Shell extension that automatically loads and unloads environment variables based on current directory
direnv is a shell extension that automatically manages environment variables based on the current working directory. It checks for .envrc files in the current and parent directories before each shell prompt, loading exported variables into the current shell session when entering a directory and unloading them when exiting.
The tool supports all major shells including bash, zsh, fish, tcsh, elvish, powershell, murex, and nushell. It works by executing .envrc files in a bash subprocess and capturing only the environment variable changes, which allows it to work across different shell types while maintaining security through an authorization mechanism that requires explicit approval before loading new configuration files.
direnv includes a standard library of utility functions like PATH_add for common environment manipulation tasks, and supports custom extensions through ~/.config/direnv/direnvrc. The single static executable is designed to be fast enough to run on every prompt without noticeable performance impact. It's commonly used for loading 12factor app configurations, creating isolated development environments per project, and managing deployment secrets without cluttering global shell configuration files.