The AI assistant’s shell sessions are no longer automatically applying direnv environments, even though direnv appears to be loaded and configured correctly. This is a regression from previous behavior where direnv environments worked automatically. In short: The shell has no tools available that it should have, because it doesn’t seem to hook into .zshrc anymore.
Additional Notes
The issue appears to be with shell session initialization/maintenance
direnv status shows the environment is “loaded” but not “applied”
This worked correctly in previous versions of the AI assistant
Everything is working fine when using the terminal “manually”
Steps to Reproduce
Navigate to a directory with a working .envrc file
Run which bun (or any tool provided by the flake)
Expected: Tool should be found automatically
Actual: “bun not found” error
Workaround
Manually apply the direnv environment:
eval "$(direnv export zsh)"
Expected Behavior
When navigating to a directory with a .envrc file containing use flake, the AI assistant should automatically:
Load the nix flake development environment
Make tools like bun, postgresql, etc. available in the shell
Apply all environment variables and PATH modifications
Actual Behavior
direnv environment variables are present (DIRENV_DIR, DIRENV_FILE, DIRENV_WATCHES, etc.)
The actual environment changes (PATH modifications, tool availability) are NOT applied
Tools like bun are not found even though they should be available
Manual intervention required: eval "$(direnv export zsh)" to make environment work
Operating System
MacOS
Current Cursor Version (Menu → About Cursor → Copy)
Not sure if this is the same, but I had to revert to 1.5 because I couldn’t get the AI agent to use my IDE configured shell (bash, instead of zsh) or my IDE configured environment variables (required to test remote commands, paths configured in bash, etc.) Using older version got me back to expected behavior.
While the Cursor IDE team continues to break functionality with each new release (I suspect they simply don’t have a ticket about direnv—therefore no clear tests for it), the only solution will be this:
.cursor/rules/direnv_setup.mdc :
---
description: Automatically execute direnv export when opening a new terminal
globs:
alwaysApply: true
---
## Rule
Always execute `eval "$(direnv export zsh)"` after opening a new terminal.
## Description
This rule ensures that direnv environment variables are automatically loaded when opening a new terminal session. This is essential for projects that use direnv for environment management.
## Implementation
The command `eval "$(direnv export zsh)"` should be executed immediately after terminal initialization to ensure:
1. Environment variables from `.envrc` are loaded
2. Project-specific environment is activated
3. Dependencies and tools are properly configured
## Notes
- This rule is mandatory for projects using direnv
- Ensures consistent environment across all terminal sessions
- Prevents issues with missing environment variables
- Automatically loads project-specific configurations
yeah I actually thought abut something similar. But I guess the issue is not really related to direnv directly but to the fact that the shell profile does not get loaded properly.
This seems to have been fixed in the latest version again:
Enabling the Legacy Terminal Tool like suggested by @othercriteria doesn’t solve it for us. And a dedicated rule like suggested by @a0s doesn’t help either.