Bash tool CWD brick when worktree directory is deleted

Resolved 💬 3 comments Opened Mar 11, 2026 by dgbattman Closed Mar 15, 2026

Description

When a git worktree directory is deleted (by a background agent cleaning up), the Bash tool's internal CWD becomes unresolvable. Every subsequent Bash command fails with:

Path "/path/to/deleted/worktree" does not exist

No recovery is possible — cd, subshells, absolute paths all fail because the shell itself can't resolve its CWD before executing any command.

Steps to Reproduce

  1. Session starts inside a git worktree (e.g., via EnterWorktree)
  2. A background agent deletes that worktree directory
  3. Try any Bash command — all fail

Expected Behavior

The Bash tool should detect when CWD is an invalid/deleted path and auto-reset to the project root before executing the command.

Current Impact

This happens ~3x/week in our workflow. The only recovery is starting a new conversation, losing all context.

Suggested Fix

In the Bash tool's command execution, before spawning the shell:

if (!fs.existsSync(cwd)) {
  cwd = projectRoot; // fallback to project root
}

View original on GitHub ↗

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