branch-cleanup
Skill2 starsChanged 5 months agoMITView on GitHub
Sweep orphan remote branches (no open PR), group by age and author, identify safe deletes, and propose a batch delete via gh CLI. Reduces repo noise without losing history — commits stay in reflog and main.
- Commits and pushes
6 other projects use a version of this.
Adopted by
Most recently taken up by
- jaskirat1616/grok-skillstheir own version, first seen Nov 1, 2026
- gspencergoog/skillstheir own version, first seen Oct 16, 2026
- stealth-factory/skillstheir own version, first seen Oct 13, 2026
- lwhsu/freebsd-claude-skillstheir own version, first seen Aug 5, 2026
- Jinbae10/skillstheir own version, first seen Jul 7, 2026
- fxstein/ai-todotheir own version, first seen Jan 31, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- jaskirat1616/grok-skills★ 22same name
- fxstein/ai-todo★ 17same name
- stealth-factory/skills★ 5same name
- gspencergoog/skills★ 3same name
- lwhsu/freebsd-claude-skills★ 2same name
- Jinbae10/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- control-plane/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- control-plane/CLAUDE.mdCLAUDE.md
- agentic-os-reference-syncSkill
- capture-triageSkill
- darwin-housekeepingSkill
- darwin-path-modeSkill
- decision-log-entrySkill
- eodSkill
- expert-interview-guideSkill
- feedback-intakeSkill
- harness-onboardingSkill
- ingest-contentSkill
- meeting-to-work-itemsSkill
- memory-consolidateSkill
- morning-briefSkill
- os-bootstrap-extendSkill
- os-bootstrapSkill
- pr-reviewSkill
- scheduleSkill
- spec-cross-checkSkill
- ux-critiqueSkill
- weekly-retroSkill
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 46
If a number is returned → has an open PR → do not include in the cleanup list.
- Very specific: line 81
If dry_run=true, stop after Step 5.
- Very specific: line 82
If dry_run=false, ask: *"Delete N safe branches?
- Distinctive: line 89
Never auto-delete 🟡 (unique commits) — those require explicit principal approval per branch.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Skill: branch-cleanup
When to use
The repo has accumulated remote branches without open PRs — leftovers from squash-merged PRs, abandoned work, or old sessions.
NOT for:
- Deleting a local branch — use
git branch -Ddirectly. - Deleting a branch with an open PR — close the PR first.
- Force-deleting a branch with unique unmerged commits — escalate to the principal (risk of loss).
Inputs
repo_path(optional) — defaults to cwd.age_days(optional) — last-commit age threshold, default 14.dry_run(optional) — defaults totrue. Lists without deleting.falsedeletes after confirmation.
Sequence
Step 1 — Collect remote branches
cd <repo_path>
git fetch --prune origin
git branch -r | grep -v HEAD | grep -vE 'origin/(main|master)$'Step 2 — Filter out branches with open PRs
For each remote branch, check open PR status:
gh pr list --head <branch_name> --state open --json number --jq '.[].number'If a number is returned → has an open PR → do not include in the cleanup list.
Step 3 — Collect metadata per branch
git log <branch> -1 --pretty=format:'%cs|%an|%H'
git merge-base --is-ancestor <branch_sha> origin/main
# exit 0 = merged ancestor, exit 1 = unique commitsStep 4 — Categorize
| Category | Criterion | Default action |
| 🟢 Safe delete | Merged into main + age ≥ age_days | Propose delete |
| 🟡 Stale but unique | Not merged + age ≥ 30 days | List for principal to decide |
| 🔴 Recent | Age < age_days | Skip (likely active work) |
Step 5 — Structured output
## Branch cleanup — repo <name>
🟢 Safe to delete (merged + stale ≥ {age_days}d): N
- <branch> · {age}d · {author} · merged
🟡 Unique commits, stale ≥ 30d: M
- <branch> · {age}d · {author} · {n} unique commits
🔴 Recent (skip): K
Total candidates: N+MStep 6 — Confirm + execute
If dry_run=true, stop after Step 5. Hand off the table to the principal.
If dry_run=false, ask: "Delete N safe branches? (yes/no)". On yes:
for branch in <safe_list>; do
git push origin --delete "$branch"
doneNever auto-delete 🟡 (unique commits) — those require explicit principal approval per branch.
Anti-patterns
- Deleting a branch with unique commits because "it's old" — those commits exist only on that branch; deletion loses them. Always require explicit per-branch approval.
- Bulk-delete without showing the table first — the principal needs to scan the list, not trust a count.
- Including main/master in the candidate list — defensive grep filter required.
Why it matters
git branch -r output bloats over time. A repo with 50+ stale branches makes gh pr list and IDE branch pickers noisy. Periodic cleanup keeps the working surface small without losing history (everything stays in the reflog and on main if merged).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

