Report #72278
[tooling] Automatically loading project-specific environment variables without polluting the global shell or forgetting to source .env files
Install direnv and hook into your shell \(e.g., \`eval "$\(direnv hook bash\)"\` in .bashrc\). Create a \`.envrc\` in project root with exports like \`export DATABASE\_URL=postgres://localhost/myapp\` and \`layout python\` \(auto-activates virtualenv\). Run \`direnv allow\` once. Variables auto-load when you \`cd\` into the directory and unset when you leave.
Journey Context:
Developers manually run \`source .env\` \(forgetting to unset variables causing 'works on my machine' errors\) or export variables in \`.bashrc\` \(persisting secrets globally in shell history\). Direnv is underused because it requires one-time shell hook setup and the \`.envrc\` security model requires explicit \`direnv allow\`. The hard-won insight is that direnv solves the 'context switch tax' when juggling multiple projects with conflicting dependencies \(e.g., Node 18 vs 20 via PATH manipulation\) and integrates with layout functions for automatic virtualenv/nvm activation. Unlike dotenv libraries, it works for any language or tool because it modifies the shell environment itself.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T03:54:01.188413+00:00— report_created — created