Session UI goes stale/broken when its git worktree is deleted by PR merge (auto-delete-branch)
Summary
When a Claude Code session is rooted in a git worktree created via the harness EnterWorktree tool, and that worktree's branch is later squash-merged with auto-delete-branch enabled, the worktree directory is removed out from under the live session. The harness does not detect this: the desktop UI goes stale (shows the PR's CI as green but not merged, even though it merged and the branch/worktree were deleted), and the session's working directory silently falls back to the main checkout.
Environment
- Entrypoint:
claude-desktop - Claude Desktop release:
Claude@1.9659.2 - claude-code:
2.1.156 - Agent SDK:
0.3.156 - OS: macOS 26.5 (25F71)
- Repo uses git worktrees under
.claude/worktrees/<name>
Repro
- Start a session whose project root is the main checkout.
- Use
EnterWorktreeto create + switch into a worktree (.claude/worktrees/<name>); the harness UI begins tracking that directory. - Commit work, push, open a PR.
- Merge the PR on GitHub via squash merge with "automatically delete head branch" enabled. This deletes the remote branch; the local worktree directory is removed/becomes stale.
- Observe the session.
Expected
- The harness detects that the session's worktree directory no longer exists.
- It re-roots the session gracefully (e.g., back to the main repo) and surfaces a notice.
- The UI resyncs to reflect the merged state.
Actual
- The desktop UI is stale: it shows CI green but reports the PR as not merged, and does not reflect that the worktree was removed.
Bashcdinto the worktree path fails withno such file or directory; cwd silently falls back to the main checkout.- Ground truth (via
gh pr view) shows the PR isMERGEDandgit worktree listno longer contains the worktree — i.e., the UI and the actual repo state have diverged.
Impact
The session appears "broken" to the user and requires a manual app reload to resync. This is common for any workflow that enforces worktree-per-task and uses GitHub's auto-delete-branch-on-merge.
Suggested fix
Watch the session's tracked worktree directory for deletion (or reconcile against git worktree list after external git operations), and on disappearance re-root to the repo's primary worktree + refresh the PR/CI panel.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗