direnv hooks into your shell and looks for a .envrc file in the current directory and its parents. When you cd into a project, it loads the variables defined there; when you leave, it unloads them. This means each project can have its own API keys, PATH entries, and configuration without polluting your global shell or remembering to source files manually.
A simple .envrc might look like this:
export DATABASE_URL="postgres://localhost/myapp"
export PATH="$PWD/bin:$PATH"
use node 20For security, direnv requires you to explicitly run direnv allow before any new or changed .envrc is executed, so you never run untrusted code by surprise. It integrates with tools like nix, asdf, and language version managers through "stdlib" functions. direnv is a favorite among teams that want reproducible per-project environments and developers tired of juggling secrets across many repositories. It's lightweight, language-agnostic, and works in bash, zsh, fish, and tcsh.