# direnv

> Shell extension that automatically loads and unloads environment variables based on current directory

Stars: 15.5k · Language: Go · License: MIT · Categories: Shell

- Repository: https://github.com/direnv/direnv
- Website: http://direnv.net
- Page: https://www.trmn.sh/tools/direnv

## Overview

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

- [shfmt](https://www.trmn.sh/tools/shfmt.md): Shell script formatter built on a Go parser for POSIX sh, Bash, Zsh and mksh. The same repo ships a syntax package, shell helpers and an interpreter. (Go, 9.2k stars)
- [up](https://www.trmn.sh/tools/up.md): Interactive terminal UI for building Linux pipelines with live preview of command results (Go, 8.9k stars)
- [gum](https://www.trmn.sh/tools/gum.md): CLI tool providing interactive components for shell scripts with input prompts, menus, spinners, and styling (Go, 24.6k stars)
- [tpm](https://www.trmn.sh/tools/tpm.md): Tmux Plugin Manager: installs, updates, and removes tmux plugins from GitHub or other git repositories, configured via ~/.tmux.conf. (Shell, 15.2k stars)
- [Pure](https://www.trmn.sh/tools/pure.md): ZSH prompt that shows git branch, dirty state, and async-checked unpushed/unpulled arrows, with exit-status coloring and command execution time. (Shell, 14.5k stars)

## Guides

- [Load a project variable with direnv](https://www.trmn.sh/guides/direnv-project-environment): Set up a direnv shell hook, inspect and allow a small .envrc, and watch a project variable disappear when you leave.
- [Manage Node, Python and Go versions per project with mise](https://www.trmn.sh/guides/mise-runtime-versions): Pin Node, Python and Go versions per project with mise: install, shell activation, mise use, mise.toml vs .tool-versions, and moving off asdf or nvm.

---

Canonical: https://www.trmn.sh/tools/direnv
