# AI Assistant Shell Session Regression: direnv Environment Not Applied Automatically

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

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

  1. Navigate to a directory with a working .envrc file
  2. Run which bun (or any tool provided by the flake)
  3. Expected: Tool should be found automatically
  4. 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:

  1. Load the nix flake development environment
  2. Make tools like bun, postgresql, etc. available in the shell
  3. Apply all environment variables and PATH modifications

Actual Behavior

  1. :white_check_mark: direnv environment variables are present (DIRENV_DIR, DIRENV_FILE, DIRENV_WATCHES, etc.)
  2. :cross_mark: The actual environment changes (PATH modifications, tool availability) are NOT applied
  3. :cross_mark: Tools like bun are not found even though they should be available
  4. :cross_mark: Manual intervention required: eval "$(direnv export zsh)" to make environment work

Operating System

MacOS

Current Cursor Version (Menu → About Cursor → Copy)

Version: 1.6.27
VSCode Version: 1.99.3
Commit: d750e54bba5cffada6d7b3d18e5688ba5e944ad0
Date: 2025-09-17T20:21:17.042Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.6.0

Additional Information

  • OS: macOS (darwin 24.6.0)
  • Shell: zsh (/bin/zsh)
  • direnv: 2.37.1 (installed via nix)
  • Setup:
    • .envrc file contains use flake
    • flake.nix provides bun and postgresql_16
    • direnv hook is properly configured in ~/.zshrc
    • Environment has been allowed with direnv allow

Does this stop you from using Cursor

Yes - Cursor is unusable

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.

Wow - genuinely didn’t think of that :sweat_smile:

Yes, reverting back to 1.5 did indeed work. Thanks!

That’s kind of grim though… Hope it gets fixed!

Edit: Reverted back specifically to 1.6.26 (from 1.6.27) and it’s still working.

That means the regression was introduced with 1.6.27.

Thanks for the report. Can you check if you are facing this issue on the latest version? Team has shipped several improvements on this front

Hey @sanjeed5 , thanks for looking into it!

Just tried it with v1.7.17. Unfortunetely it’s still not working though.

Using the integrated terminal works as expected, but the AI Agent is still not loading the environment.

Here are the specific details and some output, let me know if you need anything else that would help debugging.

Version Details:

Version: 1.7.17
VSCode Version: 1.99.3
Commit: 34881053400013f38e2354f1479c88c9067039a0
Date: 2025-09-29T03:10:26.099Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.6.0

Integrated terminal:

$ which bun
/nix/store/gbrcl1g5ji1c3rg69nizifq5lazlpsh2-bun-1.2.20/bin/bun

AI Agent:

Thanks for sharing the details. I’ve raised it with the team!

1 Like

Hey @sanjeed5 , just upgraded to v1.7.28 and the issue seems fixed!

Thanks for addressing it! :folded_hands:

Hey @sanjeed5 ,

unfortunately, it has stopped working again the with the latest version:

Version info:

Version: 1.7.44
VSCode Version: 1.99.3
Commit: 9d178a4■■■89981b62546448bb32920a8219a5d0
Date: 2025-10-10T15:43:37.500Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.6.0

It seems that the Agent is not running ~/.profile when starting a shell session.

Version: 1.7.46
VSCode Version: 1.99.3
Commit: b9e5948c1ad20443a5cecba6b84a3c9b99d62580
Date: 2025-10-14T01:21:46.830Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 25.0.0

Yep, that’s my impression, too. It used to, though, but then there was a regression in a minor version release and it seems to be unstable since then.

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

Hey @a0s ,

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:

Version: 1.7.52
VSCode Version: 1.99.3
Commit: 9675251a06b1314d50ff34b0cbe5109b78f848c0
Date: 2025-10-17T01:41:03.967Z
Electron: 34.5.8
Chromium: 132.0.6834.210
Node.js: 20.19.1
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.6.0

@sanjeed5 I can also confirm that the behavior is broken in the latest release. Here is my system info;

Version: 2.0.64
VSCode Version: 1.99.3
Commit: 25412918da7e74b2686b25d62da1f01cfcd27680
Date: 2025-11-06T04:35:14.424Z (15 hrs ago)
Electron: 37.7.0
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Darwin arm64 25.0.0

Keep us up to date on when a fix is coming.

Yeh, same here @bbaserdem :grimacing:

Feels like it breaks and gets fixed with every other update.

As another workaround, enabling the Legacy Terminal Tool setting seems to fix this.

We are seeing the same issue on 2.0.77.

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.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.