AgentSkillsCN

worktree-cleanup

在任务完成后,移除工作树,并可选择一并删除对应的分支。适用于完成并行工作之后,或当任务分支已被合并时使用。

SKILL.md
--- frontmatter
name: worktree-cleanup
description: Remove worktrees and optionally delete branches for a completed task. Use after finishing parallel work or when a task branch has been merged.
argument-hint: <task-name> [--force] [--delete-branches] | --merged [--dry-run]
disable-model-invocation: true
allowed-tools: Bash(worktree cleanup *)

Cleanup worktrees

Remove a specific task

bash
worktree cleanup $ARGUMENTS

Common usage:

bash
# Remove worktrees and branches for a completed task
worktree cleanup <task-name> --force --delete-branches

Remove all merged tasks

bash
# Preview what would be removed
worktree cleanup --merged --dry-run

# Remove all merged tasks and their branches
worktree cleanup --merged --force --delete-branches

Options

OptionDescription
--mergedAuto-detect tasks whose branches are merged into the default branch
--delete-branchesDelete local branches along with worktrees
--dry-runShow targets without actually deleting
--forceSkip confirmation prompts and ignore uncommitted changes

Safety

  • Warns about uncommitted changes unless --force is used
  • Asks for confirmation unless --force is used
  • Removes the empty .worktrees/ directory when the last task is cleaned up