Bash tool becomes permanently stuck when cached working directory is moved or deleted
Bash tool unrecoverable when working directory is moved/deleted
Title
Bash tool becomes permanently stuck when cached working directory is moved or deleted
Labels
bug, tools
Description
Summary
The Bash tool caches the current working directory between invocations. If a command moves or deletes that directory, all subsequent Bash commands fail with a path validation error. There is no way to recover within the tool.
Steps to Reproduce
- Navigate to a directory via Bash commands (e.g., working in
/home/user/project/subdir/) - Run a command that moves or deletes that directory:
``bash``
mv /home/user/project/subdir/ /home/user/project/archive/
- Attempt any subsequent Bash command, even simple ones:
``bash``
ls -la /home/user/
cd /home/user/
true
Expected Behavior
- Bash should either:
- Detect the invalid cwd and reset to a valid path (e.g., home directory or parent)
- Run commands that include explicit
cdto valid paths - Allow commands with absolute paths to execute regardless of cwd state
Actual Behavior
- Every Bash command fails with:
````
Path "/home/user/project/subdir/" does not exist
- The error occurs before the command is executed - appears to be a pre-flight validation
- No recovery is possible within the tool
- Even
cd /valid/path && lsfails because the check happens first
Workarounds
- Use file-based tools (Read, Write, Glob, Grep) which don't depend on cwd
- Have the user manually run commands in their terminal
- Avoid commands that move/delete the current working directory
Environment
- Claude Code CLI v2.1.22
Impact
Medium-high: Any workflow involving directory reorganization (common in scaffolding, refactoring, project setup) can trigger this unrecoverable state, requiring workarounds or session restart.
Suggested Fix
Add fallback logic when cwd validation fails:
- Check if cwd exists
- If not, walk up parent directories until a valid path is found
- Reset cwd to that valid parent (or home directory as ultimate fallback)
- Log a warning but proceed with the command
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗