clean-branches

clean-branches is a command for Claude Code from KhaledSaeed18/dotclaude. It costs 92 tokens per session (874 once invoked), scanned A, original, MIT.

A Git branch-cleanup command that identifies local branches that are already merged or have become stale. A branch is a separate line of development in Git.

In plain words
What is it for?
Use it to review and delete fully merged, remote-deleted, or long-inactive local branches. Pass --dry-run to preview the proposed removals without deleting anything.
Why use it?
It helps remove abandoned branches without deleting protected branches or the branch currently in use.

Command for Claude Code

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.

agentmods
npx agentmods add commands/khaledsaeed18/dotclaude/clean-branches
Clone the repo
git clone --depth 1 https://github.com/KhaledSaeed18/dotclaude

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 clean-branches

README.md
[![agentmods](https://agentmods.dev/badge/commands/khaledsaeed18/dotclaude/clean-branches.svg)](https://agentmods.dev/commands/khaledsaeed18/dotclaude/clean-branches)
Your own site
<a href="https://agentmods.dev/commands/khaledsaeed18/dotclaude/clean-branches"><img src="https://agentmods.dev/badge/commands/khaledsaeed18/dotclaude/clean-branches.svg" alt="Measured on agentmods" height="20"></a>
Per session 92 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 874 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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 $0.00092 $0.00874
Opus 5 $0.00046 $0.00437
Sonnet 5 $0.00018 $0.00175
Haiku 4.5 $0.00009 $0.00087

Measured 4d ago against content hash 85e2a96aa514, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

clean-branches 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-plugin/plugins/git/commands/clean-branches.md · 92 lines

How it starts

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

Context

Options: $ARGUMENTS

Current branch and remotes:

!git branch --show-current 2>/dev/null

!git remote -v 2>/dev/null | head -4

Task

Identify merged and stale local branches and remove them, after presenting a clear list of what will be deleted and why.

Step 1: Gather branch state

# All local branches with their last commit date and whether they are merged into main/master
git branch -v --merged main 2>/dev/null || git branch -v --merged master 2>/dev/null
# Branches with no corresponding remote-tracking ref (orphaned after remote deletion)
git branch -vv | grep ": gone]"
# All local branches with last commit date, sorted oldest first
git for-each-ref --sort=committerdate refs/heads/ \
  --format="%(committerdate:short)  %(refname:short)  %(upstream:track)"

Step 2: Classify branches for deletion

Candidates for deletion are branches that meet one or more of these criteria:

  1. Fully merged: the branch tip is reachable from main or master (shown by git branch --merged).
  2. Remote gone: the tracking remote branch was deleted (shown by ": gone]" in git branch -vv).
  3. Stale and inactive: last commit is more than 90 days old and the branch has no open remote counterpart.

Protected branches - never delete:

  • main, master, develop, dev, staging, production
  • The currently checked-out branch
  • Any branch with uncommitted changes (this cannot happen for local branches, but note it as a constraint)

Build two lists:

  • Safe to delete: merged or remote-gone branches that are not protected.
  • Needs review: stale branches that are not merged and whose remote still exists (present these for manual decision, do not auto-delete).

Step 3: Confirm and act

Present the lists clearly before deleting anything:

Branches to delete (merged or remote-gone):
  feature/old-login     last commit: 2024-11-03  [merged into main]
  fix/typo-in-readme    last commit: 2025-01-14  [remote: gone]

Branches for manual review (stale, not merged):
  experiment/new-nav    last commit: 2024-09-12  [remote still exists]

Read the full file on GitHub · 92 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 · 92 lines · 92 tokens per session scan A 85e2a96aa514

Subscribe to this mod's changes

clean-branches is a command published in the GitHub repository KhaledSaeed18/dotclaude (5 stars, last pushed 2d ago), licensed MIT. It adds 92 tokens to every session and 874 once invoked, about $0.0005 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-08-31.