clean-branches

clean-branches is a command for coding agents from davepoon/buildwithclaude. It costs 7 tokens per session (1,792 once invoked), scanned A, original, MIT.

A command for removing Git branches that have already been merged or are no longer used. Git branches are separate lines of project history used to develop changes safely.

In plain words
What is it for?
Use it to inspect local and remote branches, identify stale or merged branches, and clean them up without deleting protected branches.
Why use it?
It helps reduce branch clutter while checking the current repository, protected branches, merge status, and possible backups first.

Command

Part of the all-commands plugin — 23 commands shipped together

About the project

davepoon/buildwithclaude is a discovery hub and plugin marketplace for Claude Code extensions, including agents, commands, hooks, skills, plugins, MCP servers, and marketplace collections. Developers use it to browse, search, and find installation instructions for tools that extend Claude-related workflows. Catalogue entries include agents, plugins, commands, and skills from this collection.

davepoon/buildwithclaude · 3,415 stars · on GitHub · buildwithclaude.com

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/davepoon/buildwithclaude/clean-branches
Clone the repo
git clone --depth 1 https://github.com/davepoon/buildwithclaude

Or install all-commands, the plugin that ships this one along with the rest of its 23 commands.

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/davepoon/buildwithclaude/clean-branches.svg)](https://agentmods.dev/commands/davepoon/buildwithclaude/clean-branches)
Your own site
<a href="https://agentmods.dev/commands/davepoon/buildwithclaude/clean-branches"><img src="https://agentmods.dev/badge/commands/davepoon/buildwithclaude/clean-branches.svg" alt="Measured on agentmods" height="20"></a>
Per session 7 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,792 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.1 $0.00007 $0.01792
Opus 5 $0.00003 $0.00896
Sonnet 5 $0.00001 $0.00358
Haiku 4.5 $0.00001 $0.00179

Measured today against content hash c4601ba5e030, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, 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 today.

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.

plugins/all-commands/commands/clean-branches.md · 250 lines

How it starts

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

Clean Branches Command

Clean up merged and stale git branches

Instructions

Follow this systematic approach to clean up git branches: $ARGUMENTS

  1. Repository State Analysis

    • Check current branch and uncommitted changes
    • List all local and remote branches
    • Identify the main/master branch name
    • Review recent branch activity and merge history
    # Check current status
    git status
    git branch -a
    git remote -v
    
    # Check main branch name
    git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
    
  2. Safety Precautions

    • Ensure working directory is clean
    • Switch to main/master branch
    • Pull latest changes from remote
    • Create backup of current branch state if needed
    # Ensure clean state
    git stash push -m "Backup before branch cleanup"
    git checkout main  # or master
    git pull origin main
    
  3. Identify Merged Branches

    • List branches that have been merged into main
    • Exclude protected branches (main, master, develop)
    • Check both local and remote merged branches
    • Verify merge status to avoid accidental deletion
    # List merged local branches
    git branch --merged main | grep -v "main\\|master\\|develop\\|\\*"
    
    # List merged remote branches
    git branch -r --merged main | grep -v "main\\|master\\|develop\\|HEAD"
    
  4. Identify Stale Branches

    • Find branches with no recent activity
    • Check last commit date for each branch
    • Identify branches older than specified timeframe (e.g., 30 days)
    • Consider branch naming patterns for feature/hotfix branches
    # List branches by last commit date
    git for-each-ref --format='%(committerdate) %(authorname) %(refname)' --sort=committerdate refs/heads
    
    # Find branches older than 30 days
    git for-each-ref --format='%(refname:short) %(committerdate)' refs/heads | awk '$2 < "'$(date -d '30 days ago' '+%Y-%m-%d')'"'
    
  5. Interactive Branch Review

    • Review each branch before deletion
    • Check if branch has unmerged changes
    • Verify branch purpose and status
    • Ask for confirmation before deletion

Read the full file on GitHub · 250 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. today First seen · 250 lines · 7 tokens per session scan A c4601ba5e030

Subscribe to this mod's changes

clean-branches is a command published in the GitHub repository davepoon/buildwithclaude (3,415 stars, last pushed yesterday), licensed MIT. It adds 7 tokens to every session and 1,792 once invoked, about $0.0000 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-05.