claudegoodies
Command

worktree-cleanup

From davila7

Clean up merged worktrees and their branches

Install

/worktree-cleanup

Facts

Status
Actively maintained
Last commit
Declared tools
Bash(git:*), Bash(rm:*), Bash(ls:*), Bash(pwd:*), Bash(grep:

Source preview

The instructions Claude Code reads when this command runs.

# 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:
   ```bash
   git branch --list 'claude/*' 'claude-daniel/*' 'review/*'
   ```
3. For each matching branch, 
View full source on GitHub →

Other slash commands