worktree-cleanup
From davila7
Clean up merged worktrees and their branches
Install
/worktree-cleanupFacts
- Repository
- davila7/claude-code-templates
- Status
- Actively maintained
- Last commit
- Declared tools
- Bash(git:*), Bash(rm:*), Bash(ls:*), Bash(pwd:*), Bash(grep:
- Source file
- .claude/commands/worktree-cleanup.md
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
feature-development
★ 229,918Workflow command scaffold for feature-development in everything-claude-code.
affaan-mupdated 14d agoMITdatabase-migration
★ 229,918Workflow command scaffold for database-migration in everything-claude-code.
affaan-mupdated 14d agoMITadd-language-rules
★ 229,918Workflow command scaffold for add-language-rules in everything-claude-code.
affaan-mupdated 14d agoMITcommit-push-pr
★ 137,934Commit, push, and open a PR
anthropicsupdated 13d agodedupe
★ 137,934Find duplicate GitHub issues
anthropicsupdated 13d agotriage-issue
★ 137,934Triage GitHub issues by analyzing and applying labels
anthropicsupdated 13d ago