Clean up merged worktrees and their branches
npx claude-code-templates@latest --skill β’β’β’β’β’β’β’β’β’β’β’β’β’β’β’β’β’β’β’β’Unlock this skill to run and inspect the interactive installation sequence.
Remove worktrees and branches that have been merged: $ARGUMENTS
You are in the main repository (not a worktree). Clean up finished worktrees.
This project uses the following branch prefixes for worktrees:
claude/* β Claude Code auto-created worktreesclaude-daniel/* β User-created worktreesreview/* β Component review worktreesAll three prefixes must be checked in every step below.
git worktree list)/worktree-cleanup from the main repo, not from a worktree."git fetch origin --pruneParse $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)git worktree listgit branch --list 'claude/*' 'claude-daniel/*' 'review/*'
git branch --merged origin/<main-branch> | grep -E '^\s+(claude/|claude-daniel/|review/)'
git branch -r --merged origin/<main-branch> | grep -E 'origin/(claude/|claude-daniel/|review/)'
--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.
Show a table of all worktrees/branches:
| # | Worktree | Branch | Merged? | Dirty? | Action | |---|---------|--------|---------|--------|--------| | 1 | eager-mendeleev | claude/eager-mendeleev | Yes | Clean | Will remove | | 2 | agent-a7e312d0 | review/code-reviewer-2026-04-01 | No | Clean | Skipped |
If --dry-run was specified, show the table and stop.
Otherwise, use AskUserQuestion to confirm cleanup (unless --all was specified with only merged branches).
For each worktree/branch to clean up:
git worktree remove <path>
If that fails (dirty worktree), warn and skip β never force-remove.
git branch -d <branch>
Use -d (not -D) for merged branches. For --force-all unmerged branches, use -D only after explicit user confirmation.
git push origin --delete <branch>
If the remote branch doesn't exist, ignore the error silently.
After all removals:
git worktree prune
Show what was cleaned up:
Cleanup Complete ββββββββββββββββββββββββββββββββββ Removed: <N> worktree(s) Deleted: <N> local branch(es) Deleted: <N> remote branch(es) Skipped: <N> unmerged branch(es) ββββββββββββββββββββββββββββββββββ
If any unmerged branches were skipped, list them and suggest:
git worktree remove <path> and git branch -D <branch> manually if the work is truly abandoned# Step 1: Initialize skill agent setup
npx skills add Worktree Cleanup --install-production
python -m pip install -r requirements.txt
codex plugin install Worktree Cleanup@latest
export API_KEY=secret_token_key_here
Unlock this skill to reveal complete step-by-step setup guides, terminal commands, configuration recipes, repository links, and interactive installation video walkthroughs.
Get instant access to complete setup guides, repository source code, and integration assets.
Generate a complete test file for a specified source file or component. Use when the user explicitly asks to write, create, or generate tests for a specific file.
Multi-framework structured analysis: surfaces hidden assumptions, generates competing solutions, stress-tests each with adversarial reasoning, and delivers confidence-calibrated recommendations
Generate comprehensive architecture documentation with diagrams, ADRs, and interactive visualization