Worktree Cleanup
Description
Remove worktrees and branches that have been merged: $ARGUMENTS
Installation
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open the source below and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
Repository README
This is the README for davila7/claude-code-templates, shared by 7 entries
in this directory. It describes the repository, not this entry specifically.
allowed-tools: Bash(git:*), Bash(rm:*), Bash(ls:*), Bash(pwd:*), Bash(grep:*) argument-hint: --all | --branch wt/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.
Step 1: Validate Environment
- Verify this is the main working tree (first entry in
git worktree list) - If inside a worktree, warn: "Run
/worktree-cleanupfrom the main repo, not from a worktree." - Fetch latest from origin:
git fetch origin --prune - Get the main branch name (main or master)
Step 2: Parse Arguments
Parse `$ARGUMENTS` for options:
--all— clean up ALL mergedwt/*worktrees and branches--branch wt/— clean up a specific worktree/branch--dry-run— show what would be cleaned up without doing anything- No arguments — list worktrees and ask which to clean up
Step 3: Identify Worktrees
- List all worktrees:
git worktree list - List all
wt/*branches:git branch --list 'wt/*' - For each
wt/*branch, check if it's been merged into main:git branch --merged origin/ | grep 'wt/' - Also check remote branches:
git branch -r --merged origin/ | grep 'origin/wt/'
Step 4: Display Status
Show a table of all `wt/*` worktrees/branches:
| Branch | Worktree Path | Merged? | Action |
|--------|--------------|---------|--------|
| wt/login-page | ../worktrees/repo/wt-login-page | Yes | Will remove |
| wt/auth-bug | ../worktrees/repo/wt-auth-bug | No | Skipped (not merged) |
Step 5: Confirm and Execute
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 **merged** worktree/branch to clean up:
Remove the worktree:
git worktree removeIf that fails (dirty worktree), warn and skip — **never force-remove**.
Delete the local branch:
git branch -d wt/Use `-d` (not `-D`) — this is safe because it only deletes merged branches.
Delete the remote branch:
git push origin --delete wt/If the remote branch doesn't exist, ignore the error silently.
Step 6: Prune
After all removals:
git worktree prune
Step 7: Summary
Show what was cleaned up:
Cleanup Complete
──────────────────────────────────
Removed: worktree(s)
Deleted: local branch(es)
Deleted: remote branch(es)
Skipped: unmerged branch(es)
──────────────────────────────────
If any unmerged branches were skipped, list them and suggest:
- Merge the PR first, then run cleanup again
- Or use
git worktree removeandgit branch -D wt/manually if the work is truly abandoned
Related Skills
Auto Update
Pull the latest ECC repo changes and reinstall the current managed targets.
Development Ecc Guide
Navigate ECC's current agents, skills, commands, hooks, install profiles, and docs from the live repository su
Development Epic Claim
Claim an epic issue, stamp coordination state, and sync local ownership.
Development Epic Publish
Publish a validated epic update back to the issue and local cache.
Development Epic Review
Mark epic review requested, approved, or changes requested.
Development Epic Unblock
Sweep blocked epic issues and reopen anything whose dependencies are closed.
Development Related Agents
Django Build Resolver
Django/Python build, migration, and dependency error resolution specialist. Fixes pip/Poetry errors, migration
Openai Codex CLI
(55.8k ⭐) - Lightweight coding agent that runs in your terminal.
src/agents/ — 11 Agent Definitions
**Generated:** 2026-04-11