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

  1. Start a Claude Code session
  2. Enter a worktree (via EnterWorktree or by starting in a worktree directory)
  3. From another terminal, remove the worktree (git worktree remove ... or delete the directory)
  4. Try to run any Bash command in the Claude Code session
  5. All commands fail with exit code 1 and no useful output

Environment

  • macOS (Darwin 25.3.0)
  • Claude Code v2.1.52

View original on GitHub ↗

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