[FEATURE REQUEST] `direnv` support
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 13 comments · opened Jun 15, 2025 · closed Jan 8, 2026
I often use claude in a directory with a direnv setup, and let claude modify the configuration. However claude is not able to see the updated PATH and other environment variables when direnv is reloaded. It will even try to run direnv reload, and then wonder why the changes it made did not work.
Adding direnv support to claude would be great!
13 Comments
I stumbled across this same problem. I've used aider which just inherits the shell that it was executed from and it works perfectly.
However I was able to make claude code eventually work. The trick is that claude seems to use your login shell, which on my system was set to zsh. Once I added the proper direnv hook it started to work as expected.
I've got a pretty complicated setup using nix + direnv together and that fixed it. Hopefully this helps anyone until proper shell inheritance is added.
I'm using nix as well- what did your fix look like? Why did it have to end up being complicated?
Claude seems to run every command in a new shell, so environment variables don't carry over between commands. I tested this with
!export FOO=barand then!echo $FOO. I'm on a mac with zsh.My workaround was to put this in ~/.zshenv (I still have the regular hook in ~/.zshrc), it seems to work OK but it's gross and I'd like a better way:
another problem is when direnv is used in a subfolder (for example in a monorepo): Bash(cd subfolder && command-managed-by-direnv) => command-managed-by-direnv will not be found (this might be similar to #2632)
For those using bash, I needed to put the script in .bashrc
Does
$SHELLenv var match the type of shell you're running?Setting SHELL helped for claude & fish+direnv+flake setup.
I wish I wrote down claude-code version. Setting
$SHELLdoes not work anymore.Adding specifically direnv reloading support is poor design - this could be fixed more generally by allowing a hook to modify shell commands before they are executed (eg. to add environment reloading commands, but there are also quite a few other use cases - I'd also like to eg. filter stdout/stderr).
For this particular problem, another workaround is just to quit
claudeand do aclaude --resume(assuming you have direnv shell integration set up).This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
symlinked in /etc/profile.d/claude-direnv.sh
works well enough for me now
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
!Image
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.