Session UI goes stale/broken when its git worktree is deleted by PR merge (auto-delete-branch)

Resolved 💬 3 comments Opened May 30, 2026 by richburdon Closed Jun 3, 2026

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

  1. Start a session whose project root is the main checkout.
  2. Use EnterWorktree to create + switch into a worktree (.claude/worktrees/<name>); the harness UI begins tracking that directory.
  3. Commit work, push, open a PR.
  4. 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.
  5. 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.
  • Bash cd into the worktree path fails with no such file or directory; cwd silently falls back to the main checkout.
  • Ground truth (via gh pr view) shows the PR is MERGED and git worktree list no 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.

View original on GitHub ↗

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