Recover gracefully when worktree CWD is deleted mid-session
Resolved 💬 3 comments Opened Feb 24, 2026 by bencohendev Closed Feb 28, 2026
Problem
When using Claude Code's worktree feature (EnterWorktree), if the worktree directory is cleaned up while the session is still active (e.g., from another terminal), the session becomes completely unusable. Every Bash command fails because the shell's CWD no longer exists, and even cd to a valid directory fails.
The only recovery is to start a new conversation.
Expected behavior
Claude Code should detect that the working directory no longer exists and automatically recover — e.g., by falling back to the parent repository root or the user's home directory — rather than leaving the session in a permanently broken state.
Steps to reproduce
- Start a Claude Code session
- Enter a worktree (via
EnterWorktreeor by starting in a worktree directory) - From another terminal, remove the worktree (
git worktree remove ...or delete the directory) - Try to run any Bash command in the Claude Code session
- All commands fail with exit code 1 and no useful output
Environment
- macOS (Darwin 25.3.0)
- Claude Code v2.1.52
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗