direnv(1)
direnv is an environment switcher for the shell that loads and unloads environment variables based on the current directory.
Synopsis
direnv [COMMAND] [ARGS]...Description
direnv manages per-directory environment variables by reading a .envrc file in the current directory. When you cd into a directory with a .envrc, direnv automatically loads those variables; when you leave, it unloads them. This keeps your shell clean and project-specific configurations isolated.
direnv requires shell integration (bash, zsh, fish, etc.) added to your shell rc file. It uses an allow-list mechanism where each .envrc must be explicitly allowed before execution, preventing accidental code execution from untrusted directories.
Common options
| Flag | What it does |
|---|---|
allow | Whitelist a .envrc file so direnv will execute it |
deny | Remove a .envrc from the allow-list |
status | Show the current environment and .envrc status |
reload | Force reload of the current .envrc |
export | Execute .envrc and print environment changes as shell commands |
hook [SHELL] | Print shell integration code for bash, zsh, fish, etc. |
version | Print direnv version |
fetchurl URL | Download a file and print its hash (used in .envrc for remote scripts) |
Examples
Whitelist the .envrc in the current directory after reviewing it with 'direnv status'
direnv allowCreate a .envrc that prepends /custom/bin to PATH and allow it
echo 'export PATH_prepend=/custom/bin' > .envrc && direnv allowDisplay the current direnv state and which .envrc files are loaded
direnv statusOutput the environment changes as bash commands (useful for testing .envrc)
direnv export bashReview the .envrc file before allowing it (best practice for security)
cat .envrcAdd direnv integration to bash (typically placed in ~/.bashrc)
eval "$(direnv hook bash)"Remove the current .envrc from the allow-list
direnv deny