cleanup-git

A command for cleaning unused Git branches and worktrees, which are separate working directories linked to one repository. It first relies on a Git analysis command to identify what can be removed.

In plain words
What is it for?
Use it to remove branches marked as gone, delete their linked worktrees, and prune stale worktree records. It also reports removals and errors.
Why use it?
It helps clear stale branches and worktrees that clutter a repository. The cleanup is destructive, so the items to delete must be reviewed first.

Command

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/bengous/claude-code-plugins/cleanup-git
Clone the repo
git clone --depth 1 https://github.com/bengous/claude-code-plugins
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 658 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.00000 $0.00658
Opus 5 $0.00000 $0.00329
Sonnet 5 $0.00000 $0.00132
Haiku 4.5 $0.00000 $0.00066

Measured yesterday against content hash 7f88d6569c21, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cleanup-git 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 yesterday.

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.

archive/git-legacy/commands/cleanup-git.md · 96 lines

How it starts

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

Clean Up Git Repository

Perform git repository cleanup operations based on the analysis from /git-tools:analyze-git.

IMPORTANT: This command performs DESTRUCTIVE operations. Run /git-tools:analyze-git first to review what will be deleted.

Prerequisites

You MUST run /git-tools:analyze-git before using this command to understand what will be deleted.

Step 1: Clean Gone Branches with Worktrees

Run the following command to remove worktrees and delete branches marked as [gone]:

git branch -v | grep '\[gone\]' | sed 's/^[+* ]//' | awk '{print $1}' | while read branch; do
  echo "Processing branch: $branch"
  worktree=$(git worktree list | grep "\\[$branch\\]" | awk '{print $1}')
  if [ ! -z "$worktree" ] && [ "$worktree" != "$(git rev-parse --show-toplevel)" ]; then
    echo "  Removing worktree: $worktree"
    git worktree remove --force "$worktree"
  fi
  echo "  Deleting branch: $branch"
  git branch -D "$branch"
done

After completion, report:

  • Number of worktrees removed
  • Number of branches deleted
  • Any errors encountered

Step 2: Prune Stale Worktrees

Run the following command to prune worktrees marked as prunable:

git worktree prune -v

Report the output showing which worktrees were pruned.

Step 3: Clean Closed Dependabot Branches

IMPORTANT: Before deleting, verify these are truly closed/merged by checking the PR list.

For each dependabot branch with a CLOSED or MERGED PR:

  1. First, update remote references:
git fetch --prune
  1. The fetch with --prune will automatically remove stale remote references

Report:

  • Number of dependabot branches cleaned
  • Any branches that still remain (likely have OPEN PRs)

Step 4: Final Verification

After all cleanup operations:

  1. List remaining local branches:
git branch
  1. List remaining remote branches:
git branch -r
  1. List remaining worktrees:
git worktree list

Step 5: Provide Cleanup Summary

Create a summary report with:

Read the full file on GitHub · 96 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. yesterday First seen · 96 lines · 0 tokens per session scan A 7f88d6569c21

Subscribe to this mod's changes

cleanup-git is a command published in the GitHub repository bengous/claude-code-plugins (4 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 658 tokens. 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.