branch-cleaner
Skill130 starsChanged 11 months agoMITView on GitHub
Use when the user asks to list, audit, prune, or delete local or remote Git branches, especially stale, merged, gone-upstream, protected, worktree-bound, or open-PR branches. Identifies safe candidates and performs only explicitly authorized cleanup.
- Commits and pushes
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 6 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
When GitHub context is available, prefer the GitHub connector for open/merged PR metadata and branch protection context.
- Distinctive: line 23
Delete only approved candidates:
- Distinctive: line 28
use git branch -D only for an individually named unmerged branch explicitly approved by the user.
- Distinctive: line 33
Treat age as a review signal, never proof that a branch is safe to delete.
- Distinctive: line 34
Never delete through an unresolved glob or a generated command string.
- Distinctive: line 35
Do not remove a branch used by another worktree.
- Distinctive: line 36
Do not delete remote branches or force-delete unmerged branches without explicit approval.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Branch cleaner
Workflow
- Resolve the repository, current branch, remote, and remote default branch from Git. Ask only when they remain ambiguous.
- Fetch and prune remote-tracking refs, then collect evidence:
git status -sbgit worktree list --porcelaingit branch --merged <remote>/<default>andgit branch --no-merged <remote>/<default>git for-each-ref refs/heads --sort=committerdate --format="%(committerdate:iso8601) %(refname:short) %(upstream:short) %(upstream:track)"
- When GitHub context is available, prefer the GitHub connector for open/merged PR metadata and branch protection context. Use
ghonly as a fallback. - Exclude the current branch, the default branch, branches checked out in any worktree, protected branches or rulesets, and branches with open PRs. If open-PR or protection state cannot be verified, keep the branch report-only.
- Group candidates by evidence:
- merged into the fetched default branch;
- upstream gone;
- old but unmerged, which is report-only unless the user explicitly approves force deletion.
- Present concrete branch names, last commit dates, merge state, and local/remote scope before deleting anything.
- Delete only approved candidates:
- immediately before each deletion, fetch current evidence and recheck the branch tip SHA, worktree use, open PRs, and protection or ruleset state against the reviewed candidate;
- skip the branch if its tip or state changed, or if any safety check is unavailable;
- local merged branch:
git branch -d <branch>; - remote branch:
git push <remote> --delete <branch>only when remote deletion was explicitly requested; - use
git branch -Donly for an individually named unmerged branch explicitly approved by the user.
- Re-run the candidate commands and
git status -sbto verify the result.
Safety
- Treat age as a review signal, never proof that a branch is safe to delete.
- Never delete through an unresolved glob or a generated command string.
- Do not remove a branch used by another worktree.
- Do not delete remote branches or force-delete unmerged branches without explicit approval.
- Preserve unrelated working-tree changes.
Deliverable
Report deleted branches, skipped branches with reasons, commands run, and any candidates still needing a decision.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- bug-triageSkill
- ci-fixSkill
- commit-workSkill
- create-prSkill
- dependency-upgraderSkill
- docs-syncSkill
- focused-tddSkill
- manage-product-ideasSkill
- pr-visual-explainerSkill
- rebase-assistantSkill
- regex-builderSkill
- release-notesSkill
- review-architecture-scopeSkill
- review-backend-changeSkill
- review-frontend-changeSkill
- review-security-privacySkill
- review-test-coverageSkill
- vps-checkupSkill
- write-ui-copySkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

