Good question. There isn’t currently a built-in way to share an existing terminal session with the agent.
That said, there are a few approaches that work reasonably well for Nix-based workflows.
1. Use Rules to allow longer terminal timeouts (quick win)
The agent sends terminal commands to the background when they exceed a timeout (roughly ~1 minute). With commands like nix develop -c, that delay can make the agent think the command is stuck.
You can add a project rule (for example: .cursor/rules/nix.mdc) to guide the agent:
-
When running Nix-related commands (nix develop, nix build, nix shell), allow a long maximum block time (at least ~120 seconds).
-
Do not treat slow output as a failure.
-
Always prefix commands that need the Nix environment with nix develop -c.
2. Use direnv + nix-direnv for near-instant environments
The standard solution in the Nix ecosystem is nix-direnv, which caches the nix develop environment so it loads almost instantly after the first build.
To make this work with the agent’s non-interactive shell:
-
Install direnv (e.g., brew install direnv)
-
Set up nix-direnv
-
Add a .envrc with use flake in your project root
-
Then add this to ~/.zshenv:
# ~/.zshenv
if [[ -n "$CURSOR_AGENT" ]]; then
eval "$(direnv export zsh)"
fi
Note: this uses direnv export zsh, which directly sets environment variables. The usual direnv hook zsh relies on interactive shell hooks that don’t run in the agent’s non-interactive environment.
After the first nix develop build, the cached environment loads in milliseconds.
3. TMUX session (advanced)
If you want the agent to run commands inside an already-active nix develop shell, you can:
This avoids paying the startup cost entirely, but it’s a more hands-on setup.
The core limitation is that each agent terminal command runs in a fresh shell, so there’s no persistent session to “enter” Nix once. In practice, the direnv approach tends to be the smoothest workaround — the environment is simply present for every command without the agent needing to manage it explicitly.