branch-cleanup

branch-cleanup is a command for Claude Code from kumaran-is/claude-code-onboarding. It costs 54 tokens per session (784 once invoked), scanned A, original, MIT.

A Git branch maintenance command that finds merged, stale, and orphaned branches and removes eligible ones while protecting important branches.

In plain words
What is it for?
Use it after a sprint or before a release to preview or clean local branches, remote references, or both.
Why use it?
It reduces branch clutter and lowers the chance of deleting main development or release branches by mistake.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it after a sprint or before a release to preview or clean local branches, remote references, or both.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/kumaran-is/claude-code-onboarding/branch-cleanup
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/kumaran-is/claude-code-onboarding

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for branch-cleanup

README.md
[![agentmods](https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/branch-cleanup.svg)](https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/branch-cleanup)
Your own site
<a href="https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/branch-cleanup"><img src="https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/branch-cleanup.svg" alt="Measured on agentmods" height="20"></a>
Per session 54 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 784 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00054 $0.00784
Opus 5 $0.00027 $0.00392
Sonnet 5 $0.00011 $0.00157
Haiku 4.5 $0.00005 $0.00078

Measured 4d ago against content hash 2d56be989be8, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

branch-cleanup scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/branch-cleanup.md · 93 lines

How it starts

The opening of the file, as written. The whole thing — 93 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Branch Cleanup

Audit and clean up local and remote branches safely. Always categorises before deleting.

Step 1 — Gather Repository State

echo "=== Current branch ==="
git branch --show-current

echo "=== All local branches (by last commit) ==="
git for-each-ref --sort=-committerdate refs/heads/ \
  --format='%(refname:short)  %(committerdate:relative)  %(authorname)'

echo "=== Merged into develop/main ==="
git branch --merged develop 2>/dev/null || git branch --merged main 2>/dev/null

echo "=== Remote tracking branches ==="
git branch -r

Step 2 — Determine Mode

Check $ARGUMENTS for a mode flag:

Flag Behaviour
(none) Interactive — confirm before each deletion
--dry-run Show what would be deleted; make no changes
--force Delete all merged branches without per-branch confirmation
--remote-only Prune stale remote-tracking refs only; skip local branches
--local-only Delete merged local branches only; skip remote prune

Step 3 — Protected Branches (NEVER delete)

Skip these regardless of mode or flags:

  • main, master, develop, staging, production
  • Any branch matching release/* or hotfix/*
  • The currently checked-out branch
  • Any branch with unpushed commits (git log origin/<branch>..<branch> returns commits)

Step 4 — Categorise Branches

Classify every non-protected branch into one of:

  1. Safe to delete — merged into develop/main, no unpushed commits
  2. Stale — last commit > 30 days ago, not merged → list for human review, do NOT auto-delete
  3. Orphaned remote — remote-tracking ref with no active PR → prune with git remote prune origin

Step 5 — Execute Cleanup

# Always prune stale remote-tracking refs first (safe, no branch deleted)
git remote prune origin

# Get merged branches excluding protected patterns
git branch --merged develop 2>/dev/null | \
  grep -vE '^\*|\bmain\b|\bmaster\b|\bdevelop\b|\bstaging\b|\bproduction\b|release/|hotfix/'

Read the full file on GitHub · 93 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 93 lines · 54 tokens per session scan A 2d56be989be8

Subscribe to this mod's changes

branch-cleanup is a command published in the GitHub repository kumaran-is/claude-code-onboarding (35 stars, last pushed 2mo ago), licensed MIT. It adds 54 tokens to every session and 784 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.