Bash tool becomes permanently stuck when cached working directory is moved or deleted

Resolved 💬 5 comments Opened Jan 29, 2026 by aaronjohnson Closed Feb 20, 2026

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

  1. Navigate to a directory via Bash commands (e.g., working in /home/user/project/subdir/)
  2. Run a command that moves or deletes that directory:

``bash
mv /home/user/project/subdir/ /home/user/project/archive/
``

  1. 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 cd to 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 && ls fails 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:

  1. Check if cwd exists
  2. If not, walk up parent directories until a valid path is found
  3. Reset cwd to that valid parent (or home directory as ultimate fallback)
  4. Log a warning but proceed with the command

View original on GitHub ↗

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