Worktree Cleanup banner
davila7 davila7

Worktree Cleanup

Development community intermediate

Description

Remove worktrees and branches that have been merged: $ARGUMENTS

Installation

Terminal
claude install-skill https://github.com/davila7/claude-code-templates

README


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

    undefined

Step 2: Parse Arguments

Parse `$ARGUMENTS` for options:

    undefined

Step 3: Identify Worktrees

    undefined

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:

    undefined

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:

    undefined