Desktop: 'Create PR' prompt offered for a worktree branch whose PR was already squash-merged (upstream deleted)
Environment
- Claude Code desktop app, Windows 11 (
platform:windows) - Session running in a git worktree (
.claude/worktrees/<slug>), branchclaude/<slug>
Repro
- In a worktree session, create a branch, push it, open a PR with
gh pr create. - Squash-merge the PR (
gh pr merge --squash), then delete the remote branch (gh api -X DELETE repos/<owner>/<repo>/git/refs/heads/<branch>— the documented pattern when--delete-branchcan't be used from a worktree). - The local branch remains checked out in the worktree, upstream shows
[gone]. - The desktop UI then surfaces a "create a PR" prompt for this session/branch, and accepting it injects the
<create-pr-command>block targeting that branch.
Expected
The UI detects that this branch already had its PR merged — gh pr list --head <branch> --state all returns it as MERGED — and shows the merged-PR status card instead of offering to create one.
Note that after a squash merge, git log origin/main..HEAD still lists the branch commits (content landed under a different SHA), so a naive "unmerged commits exist" check is misleading here; the reliable signal is the PR lookup by head ref across all states (+ comparing the local head SHA to the merged PR's headRefOid).
Actual
The user gets an unexplained PR prompt for a session that finished its work (in our case they assumed it came from a different session). Running the command works only because its template carries an "If a PR already exists for this branch" branch, which the model has to detect and handle manually. A less careful agent run could create a duplicate PR whose diff would show the inverse of whatever landed on the default branch between the branch point and the merge — confusing at best.
Suggestion
Before offering PR creation for a branch whose upstream is gone, look up existing PRs by head ref (any state). If one is MERGED and the local head equals the merged headRefOid (no new commits since), suppress the prompt and surface the merged PR instead — same rendering as the <pr-created> status card.