Skip to content

direnv

A shell extension that loads and unloads environment variables based on the directory you're in.

Stars
15.5k
Forks
967
Licence
MIT
Language
Go
Last update
11 days ago
Type
Dev tool

What it is

direnv hooks into your shell and, before each prompt, checks for a .envrc file in the current and parent directories. If the file exists and you have authorized it, direnv loads its variables and makes them available to your shell, then unloads them when you leave the folder. It keeps project-specific settings out of your ~/.profile.

  • Load per-project environment variables when you cd into a project folder
  • Prepend project bin directories to PATH with helpers like PATH_add
  • Keep local overrides out of git with source_env_if_exists .envrc.local
  • Load secrets for deployment scripts without putting them in your profile

Great for

  • Developers who juggle several projects with different environment variables
  • Teams wanting per-project development environments
  • People who need to load secrets or 12factor-style config for a project folder
  • Users of bash, zsh, tcsh or fish who want a shell-level solution

Not ideal for

  • Windows-native users, since the README lists Unix-like systems as the prerequisite
  • People who need aliases or shell functions carried into the project environment, because the README says these are not exportable
  • Non-technical users, since it requires editing shell hooks and writing .envrc files
Step-by-step guide: how to use direnvInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: A Unix-like operating system (macOS, Linux, ...) · A supported shell (bash, zsh, tcsh, fish, elvish, powershell, murex, nushell)

    Clone the repository

    git clone https://github.com/direnv/direnv.git
  2. 2

    Run it

    • Install direnv using your system package manager, as described in docs/installation.md
    • Hook direnv into your shell following docs/hook.md
    • Restart your shell
    • Create a project folder and add an .envrc file with export lines
    • Run direnv allow . in that folder to authorize the file
  3. 3

    Get the most out of it

    • Use the stdlib functions such as PATH_add instead of hand-written exports, per the man page direnv-stdlib(1)
    • Put reusable helpers in ~/.config/direnv/direnvrc or ~/.config/direnv/lib/*.sh
    • Add .direnv/ and .envrc.local to .gitignore to keep local state out of commits
    • Browse the community wiki for recipes and editor integration

Downloads

Strengths

  • The README says it is compiled into a single static executable and is fast enough to be unnoticeable at each prompt
  • Authorization step means a new .envrc does not run until you explicitly allow it
  • Supports bash, zsh, tcsh and fish, and is language-agnostic

Trade-offs

  • Aliases and functions are not exported into the loaded environment, per the FAQ
  • Loading happens in a bash sub-process, so behavior can differ from what you expect in other shells
  • Its README points to a separate wiki for recipes and editor integrations, so setup beyond basics takes extra reading

How it compares

ProjectStarsTypeLevelUpdatedBest for
direnv (this)15.5kDev toolbeginner11 days agoDevelopers who juggle several projects with different environment variables
mise35.7kCLIintermediate4 days agoDevelopers who work on several projects that need different Node.js, Python or Rust versions
zoxide40.4kDev toolbeginner4 days agoDevelopers who move between many project folders in a terminal
atuin32.2kDev toolbeginner4 days agoDevelopers who work in a terminal and often need to find past commands
autocomplete25.2kOtherintermediate1.5 years agomacOS developers who use zsh, bash or fish and want suggestions for common CLIs
nvm95.7kDev toolbeginner8 days agoDevelopers who work on several Node.js projects that need different versions

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.