worktree
Manage git worktrees for parallel Claude Code sessions. Use when user says "worktree", "create worktree", "parallel session", "new tree", or wants to work on multiple branches simultaneously.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Git Worktree Manager
Manage git worktrees for running parallel Claude Code sessions.
Commands
/worktree create <branch-name> [from <base-branch>]
Creates a new git worktree for parallel development.
Examples:
-
/worktree create fix-bug- Creates worktree from origin/main -
/worktree create fix-bug from main- Creates worktree from main branch -
/worktree create feature-x from develop- Creates from develop
/worktree list
Lists all active worktrees.
/worktree remove [<worktree-name>]
Removes a worktree and its local branch.
Instructions
For create command:
-
Parse arguments:
-
<branch-name>: Required, the new branch name -
<base-branch>: Optional, defaults toorigin/main
-
-
Determine paths:
REPO_BASENAME=$(basename "$PWD") WORKTREE_PATH="../${REPO_BASENAME}--${BRANCH_NAME}" ABSOLUTE_PATH=$(cd .. && pwd)/${REPO_BASENAME}--${BRANCH_NAME} -
Fetch latest:
git fetch origin -
Create worktree:
git worktree add -b <branch-name> <worktree-path> <base-branch> -
Install dependencies:
cd <worktree-path> && npm install -
Return to original directory
-
Check if running inside tmux:
if [ -n "$TMUX" ]; then # Inside tmux - open new window with claude tmux new-window -c "<absolute-path>" -n "<branch-name>" "claude; bash" fi -
CRITICAL - Output this format at the end:
If tmux was used:
Worktree created successfully! Branch: <branch-name> Base: <base-branch> Path: <absolute-path> New tmux window "<branch-name>" opened with Claude Code. Switch to it with: Ctrl+b n (next) or Ctrl+b w (window list)If NOT in tmux (fallback):
Worktree created successfully! Branch: <branch-name> Base: <base-branch> Path: <absolute-path> To start a parallel Claude Code session, copy and run: ┌────────────────────────────────────────────────────────────┐ │ cd <absolute-path> && claude │ └────────────────────────────────────────────────────────────┘
For list command:
Run and display output:
git worktree list
For remove command:
-
If no worktree name provided, show
git worktree listand ask user to specify -
Parse worktree name to extract branch:
- Worktree format:
<repo>--<branch> - Extract branch: everything after
--
- Worktree format:
-
Ask for confirmation before proceeding
-
Remove worktree:
git worktree remove <worktree-path> --force -
Delete local branch:
git branch -D <branch-name> -
Confirm: "Removed worktree and local branch. Remote branch preserved for PR."
Safety Rules
- Always
git fetchbefore creating to have latest refs - Never remove worktrees with uncommitted changes without explicit confirmation
- Never remove the main worktree (one without
--in directory name) - Preserve remote branches when removing (only delete local branch)
- If branch already exists, ask user if they want to use existing or create new name
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-03-03
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!