git-worktree-clean

git-worktree-clean is a command for Claude Code from FlorianBruniaux/claude-code-plugins. It costs 19 tokens per session (1,800 once invoked), scanned A, original, MIT.

A command for finding stale Git worktrees, which are additional working directories linked to one repository, and cleaning them up.

In plain words
What is it for?
Use it to preview cleanup, remove merged worktrees, review unmerged ones, and see disk usage and database-branch reminders.
Why use it?
It helps reclaim disk space while distinguishing merged branches from unmerged work that may still matter.

Command for Claude Code

Written for Claude Code: argument-hint in frontmatter.

Part of the devops-pipeline plugin — 11 skills, 8 commands shipped together

Good fit Use it to preview cleanup, remove merged worktrees, review unmerged ones, and see disk usage and database-branch reminders.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/florianbruniaux/claude-code-plugins/git-worktree-clean
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/FlorianBruniaux/claude-code-plugins

Made for: Claude Code.

Or install devops-pipeline, the plugin that ships this one along with the rest of its 11 skills, 8 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 git-worktree-clean

README.md
[![agentmods](https://agentmods.dev/badge/commands/florianbruniaux/claude-code-plugins/git-worktree-clean/github.svg)](https://agentmods.dev/commands/florianbruniaux/claude-code-plugins/git-worktree-clean)
Your own site
<a href="https://agentmods.dev/commands/florianbruniaux/claude-code-plugins/git-worktree-clean"><img src="https://agentmods.dev/badge/commands/florianbruniaux/claude-code-plugins/git-worktree-clean/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for git-worktree-clean

Your own site · 80×15
<a href="https://agentmods.dev/commands/florianbruniaux/claude-code-plugins/git-worktree-clean"><img src="https://agentmods.dev/badge/commands/florianbruniaux/claude-code-plugins/git-worktree-clean.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 19 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,800 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.00019 $0.01800
Opus 5.5 $0.00008 $0.00720
Sonnet 5.5 $0.00004 $0.00360
Haiku 4.5 $0.00002 $0.00180

Measured 1mo ago against content hash 6f071354c52a, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

git-worktree-clean 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 1mo 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.

plugins/devops-pipeline/commands/git-worktree-clean.md · 241 lines

How it starts

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

Git Worktree Clean

Batch cleanup of stale git worktrees. Safely removes merged branches, reports disk usage, and handles unmerged branches interactively.

Core principle: Auto-clean merged worktrees, interactive review for unmerged, always report what was reclaimed.

Part of: Worktree Lifecycle Suite | /git-worktree | /git-worktree-status | /git-worktree-remove

Process

  1. List All Worktrees: git worktree list
  2. Classify Each: merged vs unmerged vs protected
  3. Calculate Disk Usage: Per-worktree size
  4. Auto Mode: Remove all merged worktrees (safe)
  5. Interactive Mode: Review unmerged worktrees one by one
  6. Database Cleanup Reminder: List DB branches to clean
  7. Report: Summary of actions taken and space reclaimed

Flags

Flag Effect
--dry-run Preview what would be cleaned, no changes
--all Include unmerged worktrees (interactive confirmation each)
--force Remove all worktrees without confirmation (dangerous)

Worktree Discovery

# Get main branch name
MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
MAIN_BRANCH=${MAIN_BRANCH:-main}

# Protected branches (never auto-clean)
PROTECTED="main master develop staging production"

# List all worktrees (skip main working tree)
git worktree list --porcelain | while read line; do
  # Parse worktree path and branch
  # Skip the main worktree (first entry)
done

Classification

for WORKTREE in $WORKTREES; do
  BRANCH=$(git -C "$WORKTREE" rev-parse --abbrev-ref HEAD)

  # Skip protected
  if echo "$PROTECTED" | grep -qw "$BRANCH"; then
    echo "PROTECTED: $BRANCH (skipped)"
    continue
  fi

  # Check merge status
  if git merge-base --is-ancestor "$BRANCH" "$MAIN_BRANCH" 2>/dev/null; then
    echo "MERGED: $BRANCH → safe to remove"
    MERGED_LIST="$MERGED_LIST $WORKTREE"
  else
    echo "UNMERGED: $BRANCH → requires review"
    UNMERGED_LIST="$UNMERGED_LIST $WORKTREE"
  fi
done

Read the full file on GitHub · 241 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. 1mo ago First seen · 241 lines · 19 tokens per session scan A 6f071354c52a

Subscribe to this mod's changes

git-worktree-clean is a command published in the GitHub repository FlorianBruniaux/claude-code-plugins (42 stars, last pushed 1mo ago), licensed MIT. It adds 19 tokens to every session and 1,800 once invoked, about $0.0001 per session on Opus 5.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-30.