Motivation
After a pull request is merged, its local feature branch and linked worktree can remain behind. Manually checking and removing them is repetitive and makes it easy to delete the wrong branch or overlook stale worktree registrations.
Scope
- Add a root pnpm script for cleanup.
- Detect local branches merged into the selected mainline (prefer origin/main, with a local fallback).
- Show candidates before changing anything and require confirmation by default.
- Protect the current and base branches.
- Remove eligible linked worktrees before deleting their local branches.
- Support dry-run, non-interactive confirmation, and explicit handling of dirty worktrees.
- Out of scope: deleting remote branches automatically.
Acceptance criteria
Verification plan
- Run pnpm cleanup:merged -- --dry-run.
- Verify the candidate list and protected branches against git worktree list and git branch --merged.
- Run the script on a disposable merged branch/worktree and verify both are removed.
- Run the repository's relevant lint/type checks.
Motivation
After a pull request is merged, its local feature branch and linked worktree can remain behind. Manually checking and removing them is repetitive and makes it easy to delete the wrong branch or overlook stale worktree registrations.
Scope
Acceptance criteria
Verification plan