Skip to content
PluginImportedContains scriptsShare-alike license

git-cleanup

Safely analyzes and cleans up local git branches and worktrees by categorizing them as merged, squash-merged, superseded, or active work.

Imported description, not reviewed yet

This item came from its original repository and was only scanned automatically; no editor has written an Arabic description for it yet. Read its content yourself before you rely on it. This page is not indexed by search engines until it is reviewed.

Download

Read this before you download

Talqeen never runs anything from this item. But what you download runs on your machine if you run it or let Claude Code run it, so read the files first.

  • The item has script files.

Files: 32 · Size: 177 KB

Download the ZIP

The file carries the license of the original source.

Install

Plugins are installed from a plugin marketplace in Claude Code, not by copying files. Download the package to read its content and its license.

Instructions

git-cleanup

A Claude Code slash command for safely cleaning up accumulated git worktrees and local branches.

What It Does

Analyzes your local git repository and sorts branches and worktrees into:

  • Delete candidates: merged into the default branch (-d), or squash-merged or superseded with a named PR or commit as evidence (-D)
  • Needs review: work that could not be located in the default branch, including [gone] remotes and any candidate a skeptic managed to refute
  • Keep: unpushed commits, untracked local work, or level with a live remote
  • Unanalyzed: branches no verdict came back for, listed explicitly so a partial run never reads as a complete one

The command is gated: it requires explicit user confirmation before any deletion.

How It Works

Analysis runs as a dynamic workflow — a JavaScript orchestration script that coordinates subagents:

  1. Survey — one agent inventories branches, worktrees, tracking state, and recent merge history.
  2. Triage — the script decides, in plain JavaScript, everything git can already prove: merged branches, branches with unpushed commits, branches level with a live remote. No agent is spawned for a question git branch --merged already answers.
  3. Investigate — batched agents hunt for merge evidence on the branches that remain ambiguous, mostly [gone] remotes and groups of similarly-named branches. Related branches go to one agent so supersession is visible.
  4. Refute — every delete candidate goes to a skeptic whose job is to find a commit that is not in the default branch. A refuted candidate is downgraded to "needs review", never deleted.

Typical runs are small: a repo with a dozen branches spawns about three agents, because the triage in step 2 decides most of them without spawning anything. Eleven is the ceiling, not the norm — one survey, at most five investigators, at most five skeptics — and past five batches the batches grow rather than the agent count, so the number stops rising even as the repository gets messier. Tokens still scale with the number of ambiguous branches; it is the coordination cost that is capped, not the reading.

The workflow is strictly read-only. Both confirmation gates and every git branch -d/-D and git worktree remove run in the main session, because subagents have no way to ask the user anything.

When to Use

Invoke with /git-cleanup when you have accumulated many local branches and worktrees that need cleanup.

Important: the command sets disable-model-invocation: true, so Claude cannot invoke it on its own — it runs only when you type it. That flag is what closes autonomous invocation; the description in the frontmatter is matchable text and would otherwise let a cleanup-shaped request trigger a plugin whose job is git branch -D.

Safety Features

  • Two confirmation gates (analysis review, then deletion confirmation), both in the main session
  • Safe delete (git branch -d) for branches git itself reports as merged; force delete (git branch -D) only for squash-merged and superseded branches, where git compares shas and cannot see that a squash carried the work across
  • Every squash-merged or superseded candidate must survive a skeptic tasked with finding a commit the claim cannot account for — tested against whatever the claim named, the default branch for a PR or commit and the superseding branch for a supersession. Refuted, unverified, missing a verdict, and lost-to-a-failed-agent all fall back to needs-review. SAFE_TO_DELETE is the one category that skips this. It does not rest on git branch -d catching a mistake at execution time: -d accepts a branch merged into HEAD or into its own upstream, neither of which is "merged into the default branch". Instead each entry names its tip commit in its evidence, for a human to check at gate 1, and ships a verifyWith precondition — git merge-base --is-ancestor 'refs/heads/<branch>' '<default>' — which the main session runs immediately before the delete and skips the delete on failure. The precondition names the branch rather than the reported sha, so it cannot pass on a stale or transposed commit while the branch itself was never merged. The category is still pinned to -d and never -D
  • A [gone] remote is treated as a question, not an answer: the branch is investigated, and it only becomes a delete candidate once a specific PR or commit is named and that claim survives refutation
  • Blocks removal of worktrees with uncommitted changes
  • Never touches the current branch, the repository's actual default branch whatever it is called, or any long-lived integration or environment branch — main, master, trunk, develop, dev, integration, staging, production, preprod, qa, uat, next, canary, stable and release/*, hotfix/*, support/*, maint*/* among them, matched case-insensitively. Filtered by a regex in the script, not by instructions to a model: an agent can be talked out of a rule, a regex cannot
  • Protected branches are excluded from analysis but not from the report: they come back under keep as PROTECTED, carrying their unpushed-commit count. Never deletable and never mentioned are different guarantees, and only the first one is wanted — a staging branch with unpushed work on it has to stay visible

Installation

claude plugins:add trailofbits/skills/git-cleanup

Layout

PathRole
commands/git-cleanup.mdThe /git-cleanup entry point: gates, confirmations, and the deletions
workflows/analyze-branches.jsThe dynamic workflow, shipping as /git-cleanup:git-cleanup-analysis — workflows are namespaced by meta.name, not the filename. Read-only — it never deletes
references/merge-evidence.mdWhat counts as proof a branch is merged, read by the agents and the fallback path
tests/analyze-branches.test.mjsStubs every agent and asserts the triage, clustering, and failure handling
evals/End-to-end evals: does the model produce a correct gate-1 analysis on a real repository?

The suite runs in CI and under make check via the js-tests target, which fails if it discovers no *.test.mjs files. To run just this one:

node plugins/git-cleanup/tests/analyze-branches.test.mjs

Tests vs evals

The two cover different halves, and neither substitutes for the other:

  • tests/ stubs every agent and asserts the JavaScript in analyze-branches.js — triage, clustering, protected-branch filtering, failure handling. Deterministic, free, and blind to what the model actually does with the result.
  • evals/ runs the real model against a real repository and grades the gate-1 analysis: does unpushed work stay in Keep, does every delete candidate name its evidence, does anything get deleted before the user answers. See evals/README.md.
make eval-self-tests  # free; proves the graders still fire. Part of `make check`
make evals           # the real suite — costs API calls, opt-in only

Example

User: /git-cleanup

Claude: [Runs the workflow: survey, then investigates 4 ambiguous branches,
         then refutes 3 delete candidates]

        GATE 1 — analysis

        Safe to delete (merged, -d)
        | fix/typo      | merged into main                                |

        Safe to delete (squash-merged / superseded, -D)
        | feature/auth  | PR #42, no unaccounted commits                  |
        | feature/api   | PR #29, no unaccounted commits                  |

        Needs review
        | bugfix/login  | claimed PR #51, refuted: commit 9ab2c1e missing  |
        | experiment/x  | remote gone, work not found in main             |

        Keep
        | wip/parser    | 5 unpushed commits                              |

        Worktrees
        | ../proj-auth  | feature/auth | STALE (merged)                   |

        Which would you like to clean up?
        [Delete all recommended] [Pick categories] [Pick individual branches]

User: [Delete all recommended]

Claude: GATE 2 — I will execute:

        # Worktrees holding branches being deleted (must come first)
        git worktree remove '../proj-auth'

        # Merged (safe delete, each guarded by its verifyWith precondition)
        git merge-base --is-ancestor 'refs/heads/fix/typo' 'main' && git branch -d 'fix/typo'

        # Squash-merged and superseded (force delete)
        git branch -D 'feature/auth'
        git branch -D 'feature/api'

        Confirm? (yes/no)

User: "yes"

Claude: Deleted fix/typo, feature/auth, feature/api, worktree ../proj-auth.
        Kept wip/parser. bugfix/login and experiment/x still need review.

Three things in that transcript are load-bearing: every delete candidate arrives with its evidence attached so you can audit it, bugfix/login was demoted because a skeptic found a commit its merge claim could not account for, and gate 2 lists exact commands with the flag each branch actually needs rather than a list of names.

Files

  • folder.claude-plugin343 B
    • plugin.json343 B
  • foldercommands14 KB
    • git-cleanup.md14 KB
  • folderevals70 KBscript
    • foldercases22 KB
      • folder01-mixed-repo4.7 KB
        • case.json896 B
        • graders.json3.7 KB
        • prompt.md195 B
      • folder02-all-unpushed3.5 KB
        • case.json853 B
        • graders.json2.5 KB
        • prompt.md170 B
      • folder03-gone-no-evidence2.5 KB
        • case.json650 B
        • graders.json1.7 KB
        • prompt.md159 B
      • folder04-dirty-worktree3.1 KB
        • case.json830 B
        • graders.json2.2 KB
        • prompt.md178 B
      • folder05-protected-pressure2.6 KB
        • case.json822 B
        • graders.json1.7 KB
        • prompt.md183 B
      • folder06-neg-autonomous-cleanup2.5 KB
        • case.json1,016 B
        • graders.json1.3 KB
        • prompt.md172 B
      • folder07-neg-unrelated-question3.3 KB
        • case.json916 B
        • graders.json2.2 KB
        • prompt.md161 B
    • folderfixtures8.7 KBscript
      • make-repo.sh8.7 KBscript
    • folderlib6.6 KBscript
      • graders.sh6.6 KBscript
    • folderselftest13 KBscript
      • run-selftest.sh13 KBscript
    • README.md8.9 KB
    • run-evals.sh11 KBscript
  • folderreferences4.6 KB
    • merge-evidence.md4.6 KB
  • foldertests25 KBscript
    • analyze-branches.test.mjs25 KBscript
  • folderworkflows34 KBscript
    • analyze-branches.js34 KBscript
  • LICENSE20 KB
  • README.md8.9 KB

What the automatic scan found

We scanned the files automatically when they were imported. This is what the scan pointed at. It does not mean the item is harmful, and it does not mean it is safe: read it yourself.

  • Needs a lookA script file

    In file plugins/git-cleanup/evals/fixtures/make-repo.sh

  • Needs a lookDeletes files forcibly and recursively

    In file plugins/git-cleanup/evals/run-evals.sh, line 102

  • Needs a lookDeletes files forcibly and recursively

    In file plugins/git-cleanup/evals/selftest/run-selftest.sh, line 34

Comments (0)

No comments yet. Be the first.

Sign in to comment. Commenting comes at level 1 (Member).

Report

Similar items

  • PluginImported

    agent-teams

    Orchestrate multi-agent teams for parallel code review, hypothesis-driven debugging, and coordinated feature development using Claude Code's Agent Teams

    MITFiles: 29

  • PluginImported

    c4-architecture

    Comprehensive C4 architecture documentation workflow with bottom-up code analysis, component synthesis, container mapping, and context diagram generation

    MITFiles: 6

  • PluginImported

    code-refactoring

    Code cleanup, refactoring automation, and technical debt management with context restoration

    MITFiles: 6

  • PluginImported

    code-review

    Automated code review for pull requests using multiple specialized agents with confidence-based scoring

    Apache-2.0Files: 4

  • PluginImported

    code-simplifier

    Agent that simplifies and refines code for clarity, consistency, and maintainability while preserving functionality

    Apache-2.0Files: 3

  • PluginImported

    codebase-cleanup

    Technical debt reduction, dependency updates, and code refactoring automation

    MITFiles: 6