pcl
Skill244 starsChanged 6 months agoApache-2.0View on GitHub
Delete stale git branches (local + remote) that have no open PR, and prune worktrees.
- Deletes or force-pushes
- Commits and pushes
In this repository9 other files it gives its agents.
- skills/junie/AGENTS.mdAGENTS.md
- skills/opencode/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- setup-spaSkill
- update-metadataSkill
- update-teamSkill
- spawnSkill
- spawnSkill
- spawnSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
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 10
Delete local and remote git branches that no longer have an open PR, and prune stale worktrees.
- Very specific: line 61
If --dry-run was passed, print [dry-run] would delete origin/BRANCH_NAME instead.
- Very specific: line 77
If --dry-run, print [dry-run] would delete local BRANCH_NAME instead.
- Distinctive: line 85
Remove any leftover worktree directories:
- Distinctive: line 93
Ensure we're on main branch:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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
Cleanup Stale Branches
Delete local and remote git branches that no longer have an open PR, and prune stale worktrees.
Arguments
--dry-run— List what would be deleted without actually deleting anything.
$ARGUMENTS
Procedure
Step 1: Checkout main branch
Switch to main and update to latest:
git checkout main
git pull --rebase origin mainCritical: This ensures we're not on a branch that's about to be deleted, and that we're working from the latest main.
Step 2: Fetch and prune remote refs
git fetch --prune originStep 3: Identify stale remote branches
List all remote branches except main and HEAD:
git branch -r --format='%(refname:short) %(committerdate:relative)' | grep -v 'origin/main\|origin/HEAD\|^origin 'Step 4: Get branches with open PRs (protected)
gh pr list --repo OpenRouterLabs/spawn --state open --json headRefName --jq '.[].headRefName'Any branch with an open PR MUST be skipped. Never delete a branch that has an open PR.
Step 5: Delete stale remote branches
For each remote branch that is NOT in the open PR list:
git push origin --delete BRANCH_NAMEIf --dry-run was passed, print [dry-run] would delete origin/BRANCH_NAME instead.
Step 6: Delete stale local branches
List local branches (excluding the current branch and main):
git branch --list | grep -v '^\*' | grep -v '^ *main$' | tr -d ' 'For each, check if it's already merged into main or has no remote:
git branch -d BRANCH_NAME 2>/dev/null || git branch -D BRANCH_NAMEIf --dry-run, print [dry-run] would delete local BRANCH_NAME instead.
Step 7: Prune worktrees
git worktree pruneRemove any leftover worktree directories:
rm -rf /tmp/spawn-worktrees 2>/dev/null || trueStep 8: Verify final state
Ensure we're on main branch:
git branch --show-currentShould output: main
Step 9: Summary
Print a summary:
- Number of remote branches deleted
- Number of local branches deleted
- Number of branches skipped (had open PRs)
- Worktree prune status
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.

