worktree
Use when starting feature work that needs isolation from the current workspace, or when running multiple Claude sessions in parallel on different branches — creates and manages git worktrees. For fetching latest main into every existing worktree and branch across your sibling repos, use /claudna:sync-branches instead.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- worktree
- description
- Use when starting feature work that needs isolation from the current workspace, or when running multiple Claude sessions in parallel on different branches — creates and manages git worktrees. For fetching latest main into every existing worktree and branch across your sibling repos, use /claudna:sync-branches instead.
- user-invocable
- true
02 资源文件 3
- 参考文档bootstrap-commands.md974 B
- 参考文档common-pitfalls.md1.6 KB
- 参考文档subagent-prompt-template.md1.6 KB
03 SKILL.md 正文
Git Worktree Manager
Codex: Read
../_shared/codex-tools.mdbefore following this skill. Apply its tool, root and dispatch mappings throughout.
Create worktrees and orchestrate parallel subagents for concurrent feature work.
Instructions
Step 1: Determine repo layout
Run git rev-parse --show-toplevel to get the repo root. Shell variables do NOT persist between Bash calls — hardcode absolute paths everywhere.
Convention: worktrees live at <repo-root>-worktrees/<branch>/ (sibling to repo, never inside it).
Note: Inside a worktree, --show-toplevel returns the worktree root. Use git worktree list for the main repo path.
Step 2: Show current state
Always run git worktree list first.
Step 3: Create worktrees
Use git worktree add with absolute paths. mkdir -p the parent first. Use -b <branch> for new branches; omit -b for existing ones.
Critical: cd does not persist between Bash calls from the orchestrator. Always use absolute paths.
Step 3b: Permission boundaries
On Codex: follow ../_shared/codex-tools.md for actual checkout permissions and ownership. The orchestrator may edit/test/commit in its authorized owned checkout. Use real exposed subagent and wait controls; Claude-only run_in_background and subagent_type labels below are not Codex controls. Reuse suitable app-managed worktrees and clean them up only through their owner controls. Do not remove them to enable branch deletion; omit branch deletion when needed. Existing merge authority persists. The legacy permission assumptions below apply to Claude Code.
Worktrees are sibling directories — outside the orchestrating session's project scope. Every Bash/Read/Edit command targeting a worktree triggers a permission prompt.
To minimize friction:
- Delegate all work to subagents — they operate in their own permission scope and handle testing, committing, pushing, and PR creation.
- Orchestrator should only: create worktrees, launch subagents, monitor via TaskOutput, and merge/cleanup.
- Never run tests, edit files, or commit from the orchestrator in a worktree.
- Tell the user upfront how many worktrees and subagents you'll create.
Step 4: Orchestrate parallel subagents
- Read plan/task documents first — include complete content in each subagent prompt (subagents have no conversation history).
- Create one worktree per task (Step 3).
- Launch Task agents in parallel — one Task tool call per agent, all in a single message.
CRITICAL — subagent_type MUST be "general-purpose" (that is Claude Code's name for it; a host that calls the general-purpose type something else is still the dispatch path — use its name). This gives all tools (Bash, Read, Edit, Write, Grep, Glob). Any other type fails silently.
Set run_in_background: true for concurrency. Build each prompt from subagent-prompt-template.md, substituting absolute paths and full task description.
No dispatch primitive at all (../_shared/orchestration-guide.md §14.1) → the parallelism this skill exists for is unavailable, so say so and change shape rather than faking it. Per §14.2 and §14.5: announce the inline path, then work one worktree at a time from the main session, following subagent-prompt-template.md yourself as the task description. Two consequences to state to the user up front, not discover later: the orchestrator is now doing exactly the work Step 3b reserves for subagents, so every Bash/Read/Edit against the sibling directory raises a permission prompt; and there is no concurrency, so the cost is the sum of the tasks. If the prompt volume is unacceptable, the honest answer is to skip worktrees and work serially on branches in place — not to keep the worktree ceremony without the isolation it was buying.
Step 5: Monitor and handle failures
Use TaskOutput with block=false for non-blocking checks. Wait for all agents to complete. (On the inline path there is nothing to monitor — each task is finished before the next starts.)
If a subagent fails: read its output, report to the user, ask whether to relaunch, fix manually, or skip. Do NOT silently retry.
Step 6: Merge and cleanup
Before merging, inspect git worktree list and the retained creation receipts. Remove only the exact worktrees this task created, after all assigned work has completed, ownership is verified and uncommitted work is preserved. Keep pre-existing, foreign and app-managed checkouts; use app owner controls for managed scratch checkouts when removal is authorized. Never select cleanup by a branch prefix or remove every listed worktree.
If a branch remains checked out in a preserved worktree, omit branch deletion instead of removing that checkout to make --delete-branch succeed. Use existing merge authorization, asking only when it is missing.
- For each authorized, clean, task-created scratch checkout, remove its recorded absolute path with
git worktree remove <path>; prune only stale metadata afterward. - Merge eligible reviewed PRs sequentially using the authorized method; use
--delete-branchonly when that branch is owned and no preserved checkout needs it. - Rebase or update remaining branches only within their assigned ownership and merge topology; verify the resulting diff before any authorized push.
- Return to the intended owned checkout. Preserve others' branches and working changes.
Reference files
bootstrap-commands.md— Venv setup, npm install, .env copy (included in subagent prompts)subagent-prompt-template.md— Full prompt template for Task tool callscommon-pitfalls.md— Pitfall/fix table for worktree operations
Shell aliases (user reference)
wt-new <branch>, wt-list, wt-rm <path>, wt-set a <path> — available in user's terminal (from ~/.zshrc), but may not work inside the Bash tool. Prefer explicit git worktree commands.
04 同仓库更多 Skills
example-review
Use when you want to review pull requests with detailed, actionable feedback on code quality, correctness, and maintainability.
bad-skill
Too short
weigh-development-paths
Use when at a development junction with multiple viable approaches — architecture choices, refactoring strategies, where to put new code, or which pattern to follow. Triggers on 'which approach', 'how should I', 'Option A vs B', or any point where the next step isn't obvious and the wrong choice creates rework.
verify-completion
Use when about to claim work is complete, fixed, or passing -- requires running verification commands and confirming output before making any success claims.
vercel
Use for Vercel operations — deploy to production or preview (or roll back), view, filter, or debug deployment logs, or check project status (deployments, domains, env vars, config). Replaces /vercel-deploy, /vercel-logs, /vercel-status.
using-claudna
Use to verify clauDNA installation is healthy — hooks, skills and capture — or orient at conversation start and choose an installed skill for a task. For discovering third-party skills from the public ecosystem, use /claudna:find-skills. Replaces /skill-health.