claude-code-templates: Command for Claude Code

.claude/commands/worktree-cleanup.md

worktree-cleanup is a command for Claude Code from davila7/claude-code-templates. It costs 8 tokens per session (1,033 once invoked), scanned A, original, MIT.

A command for removing completed Git worktrees and their branches. A worktree is a separate working folder connected to another branch of the same repository.

In plain words
What is it for?
Use it to list cleanup candidates, remove merged worktrees, clean their branches, or preview the changes with a dry run.
Why use it?
It clears out branches and folders left behind after work has been merged, while offering checks for merge status and a preview mode.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: names the AskUserQuestion tool; mentions Claude Code.

This is davila7/claude-code-templates's own configuration. It tells Claude Code how to work on claude-code-templates itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything claude-code-templates configures →

About the project

Claude Code Templates is a command-line tool and catalogue for configuring Anthropic’s Claude Code with agents, commands, settings, hooks, integrations, skills, and project templates. Developers use it to browse and install reusable components for their coding workflows. The catalogue includes many of these Claude Code components.

davila7/claude-code-templates · 32,814 stars · on GitHub · aitmpl.com

Reuse

Borrowing it

Nothing to install: this file belongs to davila7/claude-code-templates. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/davila7/claude-code-templates/main/.claude/commands/worktree-cleanup.md
Clone the repo
git clone --depth 1 https://github.com/davila7/claude-code-templates

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 worktree-cleanup

README.md
[![agentmods](https://agentmods.dev/badge/commands/davila7/claude-code-templates/worktree-cleanup/github.svg)](https://agentmods.dev/commands/davila7/claude-code-templates/worktree-cleanup)
Your own site
<a href="https://agentmods.dev/commands/davila7/claude-code-templates/worktree-cleanup"><img src="https://agentmods.dev/badge/commands/davila7/claude-code-templates/worktree-cleanup/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 worktree-cleanup

Your own site · 80×15
<a href="https://agentmods.dev/commands/davila7/claude-code-templates/worktree-cleanup"><img src="https://agentmods.dev/badge/commands/davila7/claude-code-templates/worktree-cleanup.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 8 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,033 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.00008 $0.01033
Opus 5.5 $0.00003 $0.00413
Sonnet 5.5 $0.00002 $0.00207
Haiku 4.5 $0.00001 $0.00103

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

Security

Grade A, and why

worktree-cleanup 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.

.claude/commands/worktree-cleanup.md · 125 lines

How it starts

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

Worktree Cleanup

Remove worktrees and branches that have been merged: $ARGUMENTS

Instructions

You are in the main repository (not a worktree). Clean up finished worktrees.

Branch Patterns

This project uses the following branch prefixes for worktrees:

  • claude/* — Claude Code auto-created worktrees
  • claude-daniel/* — User-created worktrees
  • review/* — Component review worktrees

All three prefixes must be checked in every step below.

Step 1: Validate Environment

  1. Verify this is the main working tree (first entry in git worktree list)
  2. If inside a worktree, warn: "Run /worktree-cleanup from the main repo, not from a worktree."
  3. Fetch latest from origin: git fetch origin --prune
  4. Get the main branch name (main or master)

Step 2: Parse Arguments

Parse $ARGUMENTS for options:

  • --all — clean up ALL merged worktrees and branches
  • --branch <prefix>/<name> — clean up a specific worktree/branch
  • --dry-run — show what would be cleaned up without doing anything
  • --force-all — remove ALL worktrees regardless of merge status (asks confirmation per worktree)
  • No arguments — list worktrees and ask which to clean up

Step 3: Identify Worktrees

  1. List all worktrees: git worktree list
  2. List all matching branches:
    git branch --list 'claude/*' 'claude-daniel/*' 'review/*'
    
  3. For each matching branch, check if it's been merged into main:
    git branch --merged origin/<main-branch> | grep -E '^\s+(claude/|claude-daniel/|review/)'
    
  4. Also check remote branches:
    git branch -r --merged origin/<main-branch> | grep -E 'origin/(claude/|claude-daniel/|review/)'
    
  5. For squash-merged branches (not detected by --merged), check if the branch diff is empty against main:
    # A branch is effectively merged if its changes already exist in main
    git diff origin/main...<branch> --stat
    
    If the diff is empty or very small (only whitespace), consider it merged.

Read the full file on GitHub · 125 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 · 125 lines · 8 tokens per session scan A 78f0ba528fcc

Subscribe to this mod's changes

worktree-cleanup is a command published in the GitHub repository davila7/claude-code-templates (32,814 stars, last pushed today), licensed MIT. It adds 8 tokens to every session and 1,033 once invoked, about $0.0000 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.

Related

Other commands, from other repositories

ccc-fork

Fork the current work into isolated git worktrees to try several approaches side by side, compare them on measured results, and merge the winner. Use when choosing between implementations, attempting a risky refactor, or testing competing bug theories.

KevinZai/commander · 46 tokens

ccc-multi-repo

Coordinate one change across several repositories in a single session with --add-dir: shared branch names, linked PRs, dependency-ordered merges and per-repo verification. Use for API contract changes, shared library updates and cross-service refactors.

KevinZai/commander · 48 tokens

ccc-parallel

Run several Claude Code agents at once, each in its own git worktree and branch, then merge the results through one coordinator. Use when you have independent tasks to develop concurrently.

KevinZai/commander · 36 tokens

ccc-ao

Spawn, monitor, stop and merge parallel agents in isolated git worktrees through the Composio ao CLI. Use when you want several agents working on one project at once.

KevinZai/commander · 35 tokens

ccc-pr

Open a pull request for the current branch: commit pending work, run tests, push, and create the PR with gh. Use when a branch is ready for review.

KevinZai/commander · 34 tokens

ccc-verify

Verify the current codebase in a fixed order (build, types, lint, tests with coverage, secrets, debug logs, git status) and return a PASS/FAIL report with a ready-for-PR verdict. Use before committing, before opening a PR, or when asked to check that everything still works.

KevinZai/commander · 62 tokens