safe-bulk-worktree-branch-cleanuplisted
Install: claude install-skill wan-huiyan/agent-traffic-control
# Safe Bulk Worktree & Branch Cleanup
## Problem
A repo accumulates dozens of git worktrees and branches over many sessions.
The user wants them cleaned up "without losing progress." Bulk-deleting is
risky in two non-obvious ways:
1. **Ancestry tests lie about squash-merged branches.** `git branch --merged`
and `git merge-base --is-ancestor` only detect merge-commit / fast-forward
merges. A squash merge creates a *new* commit on the trunk — the original
branch tip is never an ancestor. In a squash-merge repo (PR titles ending
`(#NN)`), these tools flag *almost every* merged branch as "NOT merged."
Trusting them either blocks the cleanup or, worse, makes you think real
work would be lost.
2. **`git worktree remove` silently discards untracked files.** Removing a
worktree never deletes commits (the branch + history persist), but any
*uncommitted / untracked* files in that worktree's directory are gone.
## Context / Trigger Conditions
- User: "this repo is messy with all the worktrees", "clean up the branches",
"review the rest and help me clean up without losing progress".
- `git worktree list` shows many `.claude/worktrees/*` or `/tmp/*` entries.
- `git branch -a` shows dozens of stale `feature/*`, `claude/*`, `docs/*` branches.
- A bulk branch/worktree deletion where the user named something to keep.
## Solution
### 1. Inventory (read-only)
```bash
git worktree list # prunable = directory gone
git branch -a --sort