← ClaudeAtlas

cleanup-after-commitlisted

Remove the git traces an agent leaves behind: merged temporary branches on the remote and locally, stray worktree copies, leftover scratch files. Deletes only what is provably merged and never touches unmerged work. Use after a PR merge or a burst of commits, or when asked to "clean up branches", "audit branches", "tidy the repo". Not for disk space or chat threads.
tonydzi/second-brain-starter-kit · ★ 15 · AI & Automation · score 76
Install: claude install-skill tonydzi/second-brain-starter-kit
# cleanup-after-commit Branches pile up because nothing removes them, not because anyone is lazy. Fix the cause first, then sweep what is already there, and never delete work that exists nowhere else. ## 1. Fix the cause (once per repo) Turn on automatic deletion of head branches after a PR merges: ``` gh repo edit OWNER/REPO --delete-branch-on-merge ``` A mature platform setting beats a cleanup script. Check every repo you own: `gh repo list OWNER --json name,isArchived -q '.[]|select(.isArchived|not).name'` then `gh api repos/OWNER/NAME -q .delete_branch_on_merge`. Archived repos are read-only, skip them. ## 2. Audit first, delete second List non-default branches and judge each one. Delete nothing during the audit. ``` gh api repos/OWNER/REPO/branches --paginate -q '.[].name' git fetch --prune origin git for-each-ref --format='%(refname:short) %(committerdate:short)' refs/remotes/origin ``` Verdict per branch: - **SAFE-MERGED**: no commits ahead of the default branch (`git rev-list --count origin/main..origin/BR` is 0). - **SAFE-PR-MERGED**: a merged PR used this branch AND the branch tip SHA equals that PR's head SHA (`gh pr list --head BR --state merged --json headRefOid,mergedAt`). - **KEEP-UNMERGED**: anything else. Live work. Report it, never delete it. ## 3. The squash-merge trap After a squash or rebase merge the branch commits are not in the default branch as-is, so "commits ahead" stays above zero forever. Do not delete on "a merged PR exists": commits pu