Launch subagent with task context in isolated worktree with token tracking
Launches subagents in isolated git worktrees to execute independent tasks with token tracking.
/plugin marketplace add cowwoc/claude-code-dog/plugin install dog@claude-code-dogThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Launch a Claude Code subagent in an isolated git worktree to execute a specific task. The subagent operates independently with its own context window while the parent agent continues coordinating.
# Generate UUID for uniqueness
UUID=$(uuidgen | cut -c1-8)
# Construct names from task context
# Format: {major}.{minor}-{task-name}-sub-{uuid}
WORKTREE_NAME="1.2-implement-parser-sub-a1b2c3d4"
BRANCH_NAME="1.2-implement-parser-sub-a1b2c3d4"
# Create worktree directory
WORKTREE_PATH=".worktrees/${WORKTREE_NAME}"
# Create branch and worktree together
git worktree add -b "${BRANCH_NAME}" "${WORKTREE_PATH}" HEAD
Copy or reference the task's PLAN.md that the subagent will execute:
# Ensure PLAN.md exists in task directory
TASK_PLAN=".claude/dog/tasks/${MAJOR}.${MINOR}-${TASK_NAME}/PLAN.md"
# Subagent will read this directly - no copy needed
Create session file for token tracking:
# Session file location
SESSION_FILE="/home/node/.config/claude/projects/-workspace/${SESSION_ID}.jsonl"
# Record spawn event
echo '{"type":"spawn","parent_session":"'${PARENT_SESSION}'","task":"'${TASK_NAME}'","timestamp":"'$(date -Iseconds)'"}' >> "${SESSION_FILE}"
# Change to worktree and launch Claude Code
cd "${WORKTREE_PATH}"
# Launch with task context
claude --resume "${SESSION_ID}" \
--prompt "Execute PLAN.md at ${TASK_PLAN}. Report completion status and metrics."
Update parent's tracking:
subagents:
- id: a1b2c3d4
task: 1.2-implement-parser
worktree: .worktrees/1.2-implement-parser-sub-a1b2c3d4
branch: 1.2-implement-parser-sub-a1b2c3d4
session: ${SESSION_ID}
spawned_at: 2026-01-10T14:30:00Z
status: running
# Parent agent spawning subagent for parser task
TASK="1.2-implement-parser"
UUID="a1b2c3d4"
git worktree add -b "${TASK}-sub-${UUID}" ".worktrees/${TASK}-sub-${UUID}" HEAD
# Launch subagent
cd ".worktrees/${TASK}-sub-${UUID}"
claude --prompt "Execute task 1.2 PLAN.md"
# Include token budget in subagent prompt
claude --prompt "Execute task 1.2 PLAN.md. Token budget: 80,000 tokens. Report if approaching limit."
# ❌ Spawning with vague instructions
claude --prompt "Work on the parser"
# ✅ Spawning with concrete plan
claude --prompt "Execute PLAN.md at .claude/dog/tasks/1.2-implement-parser/PLAN.md"
# ❌ Spawning B that depends on A's output
spawn-subagent task-a
spawn-subagent task-b # Depends on task-a!
# ✅ Wait for dependency
spawn-subagent task-a
# ... wait for completion ...
spawn-subagent task-b
# ❌ No tracking of worktree location
git worktree add somewhere
# ✅ Track for later cleanup
WORKTREE=".worktrees/${TASK}-sub-${UUID}"
git worktree add "${WORKTREE}"
# Record in STATE.md for merge-subagent skill
Subagents should not spawn further subagents. If a task needs decomposition, report back to the parent agent.
dog:monitor-subagents - Check status of spawned subagentsdog:collect-results - Gather results when subagent completesdog:merge-subagent - Merge subagent work back to task branchdog:parallel-execute - Spawn multiple subagents concurrentlyThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.