clean-branches
Clean branches
Remove the local leftovers of finished work, then report what was removed,
what stayed, and why. There are two entry points: a sweep of the whole
repository when the user asks, and one branch that merge hands over right
after it verified the merge. Do not ask for confirmation along the way: safety
comes from the narrow targets below, and anything that cannot be judged stays
where it is.
Find the candidates
Fetch the remote first. The base is the branch the user names, otherwise the
remote's advertised default branch. Read git worktree list --porcelain for
registered worktrees and git branch for local branches. For folders that lost
their registration, look only inside folders of the default checkout that also
hold a registered linked worktree, such as .claude/worktrees/.
A worktree is a candidate when one of these holds: