WO

worktree-cleanup

Corrects the order of operations for removing Git branches linked to active worktrees.

Install

mkdir -p .claude/skills/worktree-cleanup && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16324" && unzip -o skill.zip -d .claude/skills/worktree-cleanup && rm skill.zip

Installs to .claude/skills/worktree-cleanup

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Enforce the correct order when removing a branch that's pinned by a git worktree: `git worktree remove --force <path>` THEN `git branch -D <branch>`. Trying to delete the branch first fails with `error: cannot delete branch X used by worktree at Y`. Trigger this skill when: - User says "remove branch", "delete branch", "cleanup worktree", "prune branches". - `gh pr merge --delete-branch` errors with `worktree` in the message. - `git branch -D` errors with `used by worktree`. - After merging a PR that has an associated worktree.
533 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Beginner

Key capabilities

  • →Detect the branch to clean up from user messages or PRs
  • →List worktrees associated with a specified branch
  • →Remove a git worktree forcefully if it exists
  • →Delete a git branch after its worktree is removed
  • →Report on removed branches and pruned worktrees
  • →Clean up all merged branches that have associated worktrees

How it works

The skill detects a branch for cleanup, lists associated worktrees, and then executes 'git worktree remove --force <path>' followed by 'git branch -D <branch>'. If no worktree is found, it directly deletes the branch.

Inputs & outputs

You give it
User message indicating a branch to remove or a PR merge event
You get back
Confirmation of branch deletion and worktree removal

When to use worktree-cleanup

  • →Cleaning up stale git branches
  • →Removing git worktrees safely
  • →Batch deleting merged branches

About worktree-cleanup

Prevents branch deletion errors by enforcing the workflow: remove worktree first, then delete the branch.

>

When not to use it

  • →When the user is requesting to delete a branch without first removing its worktree
  • →When the user wants to remove a worktree without using the --force flag
  • →When attempting to delete a protected branch like main, dev, or master

Limitations

  • →Cannot delete a branch with unmerged commits without user warning
  • →Does not touch protected default branches like main, dev, or master
  • →Cannot handle multiple worktrees on one branch, requiring pruning stale entries first

How it compares

This skill automates the two-step process of removing a git worktree and then deleting its branch, preventing errors that occur when the branch is deleted first.

Compared to similar skills

worktree-cleanup side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
worktree-cleanup (this skill)04moNo flagsBeginner
resolve-conflicts8112moReviewIntermediate
openspec-onboard109moReviewBeginner
codex-cli-bridge91yReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry