Ships with claude-code-templates. Installing the plugin gets this command.
⚡ How it fires
How this command gets triggered: by you, by Claude, or both.
Fires itselfClaude auto-loads it when your prompt matches the work.
You can call itInvoke it directly when you want it.
Slash command/worktree-cleanup
👁️ Context preview
What this command does when you run it.
Clean up merged worktrees and their branches
📊 Stats
Stars29,853
Forks3,189
LanguagePython
LicenseMIT
📦 Ships with claude-code-templates
</> Command definition
worktree-cleanup.md
---allowed-tools: Bash(git:*), Bash(rm:*), Bash(ls:*), Bash(pwd:*), Bash(grep:*)
argument-hint: --all | --branch claude/name | --dry-run
description: Clean up merged worktrees and their branches
---# 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