claude-code - 💡(How to fix) Fix Session UI goes stale/broken when its git worktree is deleted by PR merge (auto-delete-branch)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

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.

Root Cause

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.

RAW_BUFFERClick to expand / collapse

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: [email protected]
  • 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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Session UI goes stale/broken when its git worktree is deleted by PR merge (auto-delete-branch)