AgentSkillsCN

worktree

当用户说“/worktree”“请求创建工作树”“切换工作树”“列出工作树”“检查工作树状态”,或希望在隔离环境下单独处理 GitHub Issue 时,使用此方法。

SKILL.md
--- frontmatter
name: worktree
description: Use when user says "/worktree", asks to create a worktree, switch worktrees, list worktrees, check worktree status, or work on a GitHub issue in isolation.
allowed-tools: Bash(git:*), Bash(ls:*), Bash(mkdir:*), Bash(rm:*), Bash(gh:*), Bash(code:*), Bash(.claude/scripts/worktree-status.sh), Glob, Read, AskUserQuestion
user-invocable: true
argument-hint: <add|list|status|remove|prune|#issue> [branch-name]
context: fork

Git Worktree Manager

Manage git worktrees with all worktrees stored in a sibling directory.

Directory Convention

Given a repository at /path/to/repo, worktrees are stored at:

code
/path/to/repo.worktrees/<branch-name>/

Modes

ModeTriggersDescription
Add/worktree add <branch>, /worktree <branch>, /worktree #<issue>Create worktree
Status/worktree statusShow PR/CI status table
List/worktree, /worktree listList and select worktrees
Remove/worktree remove <branch>, /worktree rm <branch>Remove worktree
Prune/worktree pruneClean stale references

Mode Detection

When this skill is invoked, arguments follow the skill name (e.g., /worktree status passes "status" as arguments).

IMPORTANT: Before doing anything else, identify the mode from the invocation arguments:

ArgumentsModeInstructions
(none) or listListRead list.md
statusStatusRead status.md
#<number> or just a numberAdd (from issue)Read add.md
add <branch> or just <branch>Add (branch)Read add.md
remove <branch> or rm <branch>RemoveRead remove.md
prunePruneRead prune.md

First action: Read the appropriate .md file for your detected mode, then follow those instructions exactly.

Important Notes

  1. Always use the sibling directory convention (repo.worktrees/)
  2. Branch names can contain slashes (e.g., feat/new-feature)
  3. Run commands separately - Don't use compound commands with && or variable assignment