Where does the bug appear (feature/product)?
Cursor CLI
Describe the Bug
The Shell tool starts each command in the folder where the previous command ended. If a command deletes that folder, every later Shell call fails, and the session does not recover on its own. The error text tells the model to restart the environment. It never says the folder is gone.
This is common. A temp-dir cleanup does it:
T=(mktemp −d) cd “T” && … && rm -rf “$T”
What we hit
Four sessions were stuck at once. One of them had been stuck for about 23 hours, with 89 failed commands. Nothing in the tool result named the missing directory. A failed command cannot change the saved folder, so the agent stays stuck until the session is restarted, or until some later call passes a working_directory that still exists.
What we changed locally
A small patch on that path. Before spawning, if the saved folder does not exist, reset it to the workspace root and add a stderr line saying the previous folder was gone. Only fail when the model explicitly asked for a folder that is missing, and then say that the folder is missing.
Tested with the three-call repro. Call 1 still succeeds. Calls 2 and 3 run. The model sees the notice. A Cursor update will overwrite the patch.
Suggested product fix
Must
• Before spawn, check that the folder still exists.
• If the saved folder is gone and the model did not name one, reset this.cwd to the workspace root (or $HOME) and put one line in the result: the previous working directory no longer exists, and the command ran in the fallback.
• If the model did name a missing folder, fail that call only, and say the path is missing. Do not leave the stale path in place for the next call.
• Pass the real spawn error through, including ENOENT and the path. Do not collapse it to “no exit status”.
• Do the same in zsh, zsh-light, PowerShell, and the generic terminal executor. They share the pattern.
Should
• Do not describe spawn bash ENOENT as if bash itself were missing when cwd is the path that does not exist.
• A failed spawn must not be the only thing that can clear this.cwd. The saved folder has to move even when the state dump never runs.
Steps to Reproduce
Steps to reproduce
One prompt, about 15 seconds. No working_directory on any call.
mkdir -p /tmp/repro && cd /tmp/repro cursor-agent -p --force --trust --model composer-2.5 --output-format stream-json
‘Make three separate Shell calls without working_directory:
1: D=(mktemp −d) cd “D” && rm -rf “$D” && echo removed
2: date -u
3: pwd’
Expected
Call 1 removes the temp dir and succeeds. Calls 2 and 3 run, in the workspace folder. If the saved folder is gone, the result says so, and the next command does not inherit it.
Actual
Call 1 succeeds. Calls 2 and 3 return about 100 ms after starting, with no exit code:
{"spawnError":{"command":"","workingDirectory":"","error":"The shell command returned no exit status, so its result is unknown — do not assume it ran or succeeded. If this repeats, the execution environment may need to be restarted."}}
Root cause, from the shipped bundle
Three separate facts. All three have to be true for the session to stick.
1. The spawn uses a folder that is already gone. In BashState.execute, the spawn folder is r?.workingDirectory ?? this.cwd. After call 1, this.cwd is taken from the dumped $PWD, which is the deleted temp dir. child_process.spawn(..., { cwd }) on a missing folder emits error (ENOENT, reported as spawn bash ENOENT, which is misleading because bash exists) and close(-2). It never emits exit. The exit code stays null, so the tool reports "no exit status".
2. The saved folder is only updated after a successful state dump. The failed spawn produces none. this.cwd keeps pointing at the missing folder.
3. Every later Shell call goes through that value. LocalShellExecutor passes getCwd(), the same stale folder, as workingDirectory. A call that does not set working_directory cannot escape.
The same workingDirectory ?? this.cwd pattern is in zsh, zsh-light, PowerShell, and the generic terminal executor. This is not bash-only.
### Operating System
Linux
### Version Information
cursor-agent 2026.09.26-dd393fe
Linux (Fedora, kernel 7.2), bash
Modes: cursor-agent acp, and cursor-agent -p
The same code path is in both.
### Does this stop you from using Cursor
Sometimes - I can sometimes use Cursor