| name | delegate |
| description | Delegate isolated coding tasks to git worktrees via Agent(isolation: worktree). Auto-applies when the user asks you to fix/build/refactor something that warrants an isolated branch. |
| allowed-tools | Task |
git-worktree-manager (gw) — Task delegation
When the user describes a task that warrants isolation (a fix, a feature, a
refactor — anything where you'd want a clean branch), spawn it as a subagent
in an isolated worktree using Claude Code's native Agent tool with
isolation: "worktree".
gw registers WorktreeCreate / WorktreeRemove hooks at the project level
(via gw setup-claude), so any Agent(isolation: "worktree") call in this repo
is routed through gw new. That means:
.cwshare files (e.g., .env) are copied into the new worktree automatically.
- The
post_new hook configured in .cwconfig.json / global config
(e.g., npm install, cargo build) runs before the subagent starts.
- The worktree appears in
gw list and is managed via gw rm.
If the user reports that subagent worktrees don't have the expected shared files,
or that post_new isn't firing, they probably need to run gw setup-claude once
in this repo's root.
Claude Code only. The Agent(isolation: "worktree") → gw new routing
relies on Claude Code's WorktreeCreate / WorktreeRemove hook events. Other
AI tools (e.g. Codex) have no equivalent hook, so this skill's delegation path
does not apply to them — see "Delegating from a non-Claude-Code tool" below.
When to delegate vs. work in-session
Delegate when:
- The task is well-scoped (clear inputs, clear acceptance criteria).
- It can run independently — the subagent has everything it needs in the initial
prompt.
- The user is OK with a separate branch / worktree being created.
Work in-session (don't delegate) when:
- The task requires back-and-forth with the user.
- It touches the current worktree's state and shouldn't be branched off.
- The user explicitly asked you to make the change here.
If unsure, ask.
Pre-flight: choosing the base
Agent(isolation: "worktree") defaults to branching off the current worktree's
HEAD. If you're in a non-default worktree, ask once:
"You're currently inside <branch>. Should this new task stack on <branch>,
or branch from main?"
(Surface this only when the cwd branch != default base. The cost of asking once
is small; the cost of a wrong base is a manual rebase later.)
Duplicate-task detection (light pass)
Before spawning, a cheap probe:
gw list
If an existing worktree's branch name strongly matches the task (same prefix +
distinctive noun), surface it and ask:
- Continue anyway (spawn fresh)?
- Resume in the existing worktree (
gw resume <branch>)?
- Cancel?
Don't surface borderline matches — false-positive friction is worse than the
occasional duplicate.
Branch naming
When invoking the Agent, give the subagent a clear, comprehensive task prompt.
Claude Code's worktree hook will derive a branch name from the task, or you can
suggest one in the prompt.
Conventions if you suggest a branch name:
- Lowercase, hyphen-separated, max ~50 chars.
- Conventional prefixes:
fix-, feat-, refactor-, docs-, test-, chore-.
- Strip filler words (the, a, an, for, in, on, etc.).
- Examples:
- "Fix the JWT token expiration check in auth" →
fix-jwt-token-expiration
- "Add user avatar upload feature" →
feat-avatar-upload
- "Refactor the database connection pool" →
refactor-db-connection-pool
What you don't do
- Don't call
gw new directly. The Agent(isolation: "worktree") path goes
through gw's WorktreeCreate hook automatically.
- Don't write
--prompt-file shell wrappers. The Agent's prompt IS the task
description; nothing else is needed.
- Don't assume you can send follow-up messages to a spawned subagent. Make the
initial prompt comprehensive — include all requirements, constraints, and
acceptance criteria upfront. If the user's request is vague, ask clarifying
questions before spawning.
Delegating from a non-Claude-Code tool (e.g. Codex)
This skill's Agent(isolation: "worktree") path is Claude-Code-specific. If the
user is driving gw from Codex (or any tool without WorktreeCreate hooks),
there is no in-session subagent delegation — gw still gives that tool the
launch + resume + <TOOL>_* env-forward primitive, but worktree creation is
manual:
- Spawn isolated work: from a shell (a second terminal, or outside the
current session), run
gw new <branch> to create the worktree and launch the
configured AI tool inside it. Forward tool args after --, e.g.
gw new feat-x -- <codex-args>.
- Resume later:
gw resume <branch> re-opens the tool in that worktree
(injecting codex resume --last for Codex).
.cwshare copying and the post_new hook fire on gw new regardless of
which AI tool is configured — those are not Claude-specific.
There is no setup-codex and no Codex hook registration; the
WorktreeCreate / WorktreeRemove / PreToolUse(Bash) hooks installed by
gw setup-claude only ever fire under Claude Code.
Cleanup
After a delegated task ships (PR merged or abandoned), the worktree can be
removed with gw rm <branch>. The manage skill covers cleanup safety
(busy-detection, etc.) — defer to that skill for destructive operations.