You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up from #2309 (same root cause, third occurrence, found while fixing the other two).
`.claude/scripts/gc-worktrees.sh` correctly classifies a worktree as "stale" via GitHub PR state (`gh pr list --state all --json headRefName,state`, not git ancestry) — see the script's own `classify()` function and its documented rationale for why ancestry is unreliable under squash merges.
But the actual branch-deletion step (`--prune-branches`) still uses plain `git branch -d`:
```bash
line ~216
if git -C "$main_root" branch -d "$b" >/dev/null 2>&1; then echo " branch deleted $b"; fi
```
`-d`'s own internal check is ancestry-based, independent of the `gh`-based classification that selected the branch as safe to delete. Verified directly (see #2309): once stale remote-tracking refs are pruned, `git branch -d` refuses a branch that GitHub confirms is genuinely merged via squash, because the local branch tip is never an ancestor of the squash commit on the default branch. Since `classify()` already ran the authoritative check, this refusal is silent — the script just doesn't print "branch deleted" for that branch and moves on, so the branch quietly survives every future `--prune-branches` run indefinitely.
Suggested fix: use `git branch -D` for branches `classify()` already confirmed merged via `gh` PR state — exactly the same fix applied to `housekeep`'s Phase 4d and Phase 1e in #2309's PR, with the same justification: this isn't a blanket force-delete, it's using the authoritative GitHub signal instead of git's unreliable-under-squash-merge ancestry heuristic.
Related finding from Greptile's review of PR #2311 (the housekeep/fixer fix this issue is a follow-up to) — worth fixing together with the -d-vs--D issue above, since both live in the same classify() function / call site:
`classify()` matches a worktree's branch to "settled" purely by name against `gh pr list`'s `headRefName` history — it never checks whether the branch's current commit is the one that actually got merged. If a branch name is reused after its earlier PR merged (a later run, or a human, creating a new branch of the same name for unrelated work), `classify()` would still return "settled" for the new, never-merged commits, and --prune-branches's git branch -d/-D would delete them.
The fix applied to `housekeep`'s Phase 4a in #2311 pins the check to `headRefOid` (the exact SHA GitHub recorded as the merged PR's head), not just `headRefName` — comparing the local branch's current tip SHA against that recorded SHA before treating it as safe to delete. The same binding should apply to `gc-worktrees.sh`'s `classify()` when fixing the `-d`-vs-`-D` bug, so both bugs (wrong deletion command, and name-only matching) get closed in the same pass rather than one being reintroduced while fixing the other.
Activity
carlos-alm commentedon Aug 7, 2026
Related finding from Greptile's review of PR #2311 (the housekeep/fixer fix this issue is a follow-up to) — worth fixing together with the
-d-vs--Dissue above, since both live in the sameclassify()function / call site:`classify()` matches a worktree's branch to "settled" purely by name against `gh pr list`'s `headRefName` history — it never checks whether the branch's current commit is the one that actually got merged. If a branch name is reused after its earlier PR merged (a later run, or a human, creating a new branch of the same name for unrelated work), `classify()` would still return "settled" for the new, never-merged commits, and
--prune-branches'sgit branch -d/-Dwould delete them.The fix applied to `housekeep`'s Phase 4a in #2311 pins the check to `headRefOid` (the exact SHA GitHub recorded as the merged PR's head), not just `headRefName` — comparing the local branch's current tip SHA against that recorded SHA before treating it as safe to delete. The same binding should apply to `gc-worktrees.sh`'s `classify()` when fixing the `-d`-vs-`-D` bug, so both bugs (wrong deletion command, and name-only matching) get closed in the same pass rather than one being reintroduced while fixing the other.
fix(skills): bind branch-merge classification to commit SHA, not name…
fix(skills): housekeep branch pruning ignores squash merges; fixer ne…
fix(scripts): gc-worktrees.sh uses git branch -D for name+SHA confirm…