Bash tool becomes permanently broken when CWD is deleted
Bug Description
The Bash tool becomes permanently non-functional for the rest of the session when the persisted working directory is deleted. Every command silently fails with exit code 1 and produces no stdout or stderr output. There is no way to recover without restarting the session.
Steps to Reproduce
- Use the Bash tool to
cdinto a temporary directory:
``bash``
cd /tmp/some-temp-dir && echo "works"
# Output: works
- Delete that directory using the Bash tool:
``bash``
rm -rf /tmp/some-temp-dir
- Try to run any Bash command:
``bash``
echo "hello"
# Result: Exit code 1, NO output (no stdout, no stderr)
- Try to
cdback to a valid directory:
``bash``
cd /Users/me/my-project && echo "recovered"
# Result: Still exit code 1, no output
- Try explicit subshell:
``bash``
/bin/bash -c 'echo hello'
# Result: Still exit code 1, no output
Nothing works. The session's Bash tool is permanently dead.
Expected Behavior
At minimum one of:
- The Bash tool should detect when the CWD no longer exists and automatically reset to the project root directory
- The Bash tool should produce an error message explaining why commands are failing (e.g., "Working directory no longer exists")
- Commands with explicit
cdto a valid absolute path should succeed even when the current CWD is invalid
Actual Behavior
- Every Bash command fails silently with
Exit code 1 - No stdout or stderr is returned — completely silent failure
cdto valid paths does not recover- Explicit subshell (
/bin/bash -c '...') does not recover - The session's Bash tool is permanently broken until the user restarts Claude Code
- Other tools (Read, Write, Edit, Glob, Grep) continue to work fine
Real-World Scenario
This happened during a normal workflow:
- Created a temp directory to test that an npm package installs and works correctly from the registry
cd'd into it and ranpnpm init,pnpm add,npx eslintetc.- Cleaned up with
rm -rf /path/to/temp/dir - All subsequent Bash commands failed silently — couldn't commit, push, or run any shell commands for the rest of the session
The Bash tool docs state "Working directory persists between commands" — but there's no protection against the persisted directory being deleted.
Environment
- macOS Darwin 25.2.0
- Claude Code CLI
- pnpm 10.28.0
Impact
Session-killing bug. The agent loses all ability to run shell commands and cannot complete any task requiring Bash. The silent failure (no error message at all) makes it extremely difficult to diagnose. The user must restart the entire session to recover.
Suggested Fix
Before executing each command, check if the CWD exists. If not, fall back to the project root directory (or $HOME) and include a warning message in the output like:
⚠️ Previous working directory no longer exists. Reset to /path/to/project.This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗