Agent skill
clean-branches
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/clean-branches
SKILL.md
Clean Git Branches
Safely remove merged and stale git branches with confirmation.
Process
0. Parse arguments
If $ARGUMENTS provided, use as branch pattern filter (e.g., feature/*).
1. Fetch latest state
git fetch --all --prune
2. Identify candidates
Find merged branches:
git branch --merged main | grep -v "^\*\|main\|master\|develop"
Find stale branches (no commits in 30+ days):
git for-each-ref --sort=-committerdate --format='%(refname:short) %(committerdate:relative)' refs/heads/ | while read branch date; do
if [[ "$date" == *"months"* ]] || [[ "$date" == *"year"* ]]; then
echo "$branch ($date)"
fi
done
3. Categorize and display
Present findings:
MERGED BRANCHES (safe to delete):
- feature/old-feature
- fix/completed-fix
STALE BRANCHES (no recent commits):
- experiment/abandoned (3 months ago)
- wip/forgotten (6 months ago)
PROTECTED (never delete):
- main, master, develop
4. Confirm before deletion
Use AskUserQuestion:
- "Delete all merged branches?"
- "Delete specific stale branches?" (list options)
- "Skip and keep all?"
5. Execute deletion
Local only (safe):
git branch -d <branch-name>
If user explicitly requests remote cleanup:
git push origin --delete <branch-name>
Safety Rules
- Never delete: main, master, develop, release/*
- Always confirm before any deletion
- Use
-d(safe delete) not-D(force) - Show what will be deleted before acting
- Remote deletion requires explicit confirmation
Output
Summary:
- Branches deleted (local)
- Branches deleted (remote, if requested)
- Branches kept
- Any errors encountered
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?