direnv

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 your current directory. It monitors for .envrc files in the current and parent directories, loading their exported variables when you enter a directory and unloading them when you leave.

The tool works by checking for .envrc files before each shell prompt and executing them in a bash sub-shell to capture environment changes. It supports all major shells including bash, zsh, fish, tcsh, elvish, powershell, murex, and nushell. direnv requires explicit authorization of .envrc files through direnv allow as a security measure to prevent automatic execution of untrusted code.

direnv includes a standard library of utility functions accessible within .envrc files, such as PATH_add for path manipulation and dotenv for loading .env files. Users can extend functionality by creating custom functions in ~/.config/direnv/direnvrc. The tool is compiled as a single static executable for performance and supports creating isolated development environments, loading 12factor app configurations, and managing deployment secrets on a per-project basis.

Alternatives & related tools

add a badge to your README

Maintain direnv? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/direnv.svg)](https://www.trmn.sh/tools/direnv?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/direnv?utm_source=badge"><img src="https://www.trmn.sh/badge/direnv.svg" alt="Featured on trmn" height="20"></a>