Bash tool becomes permanently broken when CWD is deleted

Resolved 💬 4 comments Opened Feb 8, 2026 by tupe12334 Closed Feb 12, 2026

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

  1. Use the Bash tool to cd into a temporary directory:

``bash
cd /tmp/some-temp-dir && echo "works"
# Output: works
``

  1. Delete that directory using the Bash tool:

``bash
rm -rf /tmp/some-temp-dir
``

  1. Try to run any Bash command:

``bash
echo "hello"
# Result: Exit code 1, NO output (no stdout, no stderr)
``

  1. Try to cd back to a valid directory:

``bash
cd /Users/me/my-project && echo "recovered"
# Result: Still exit code 1, no output
``

  1. 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 cd to 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
  • cd to 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:

  1. Created a temp directory to test that an npm package installs and works correctly from the registry
  2. cd'd into it and ran pnpm init, pnpm add, npx eslint etc.
  3. Cleaned up with rm -rf /path/to/temp/dir
  4. 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.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗