/claude-code-expert:cc-worktree-managementfrom claude-code-expert
Manages Git worktrees for agent isolation and parallel task execution. Provides EnterWorktree/ExitWorktree patterns, branch-per-worktree setup, and cleanup lifecycle for Claude Code.
Ships in claude-code-expert. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Git worktrees let each agent or task operate on its own branch without interfering with the main working directory. Claude Code exposes this through EnterWorktree / ExitWorktree tools.
A worktree is a second (or third, or tenth) checked-out copy of the same repository, each on its own branch. Agents working in separate worktrees:
main (or your feature branch) undisturbedThis project itself runs in a worktree at .claude/worktrees/<branch-name>.
# Create a worktree for a task branch
git worktree add .claude/worktrees/<name> -b <branch>
# List all active worktrees
git worktree list
# Remove a worktree (branch must be merged or explicitly deleted)
git worktree remove .claude/worktrees/<name>
git worktree prune # remove stale entries
Switches the agent's working context into an isolated worktree. Subsequent tool calls (Read, Write, Bash, etc.) run inside that worktree's directory.
{
"tool": "EnterWorktree",
"params": {
"branch": "feat/my-task",
"worktreePath": ".claude/worktrees/feat-my-task"
}
}
If the branch does not exist, EnterWorktree creates it from the current HEAD. If the worktree directory already exists, the agent re-enters it.
Returns the agent to the main working directory. Always pair with EnterWorktree in the same task — leaving a worktree open wastes disk and can block git worktree remove.
{
"tool": "ExitWorktree"
}
The Agent tool's isolation: "worktree" parameter handles this automatically:
{
"tool": "Agent",
"params": {
"isolation": "worktree",
"prompt": "Implement the auth middleware changes on a clean branch."
}
}
Claude Code creates the worktree, runs the sub-agent inside it, then either:
Each parallel task gets its own branch:
main
├── .claude/worktrees/feat-auth-refactor ← branch: feat/auth-refactor
├── .claude/worktrees/fix-token-expiry ← branch: fix/token-expiry
└── .claude/worktrees/docs-update-api ← branch: docs/update-api
Name the worktree directory after the branch slug. This makes git worktree list readable and git worktree remove unambiguous.
Fan-out multiple agents across independent tasks:
Orchestrator (main worktree)
│
├── Agent A → worktree/feat-part-1 (writes auth.ts)
├── Agent B → worktree/feat-part-2 (writes middleware.ts)
└── Agent C → worktree/docs-update (writes README.md)
│
└── Orchestrator merges or PRs each branch after completion
Send all three in a single Agent tool call (parallel launch). The orchestrator collects results and decides merge order.
EnterWorktree or Agent isolation: worktree creates the worktreeExitWorktree or natural agent completiongit merge or open a PR for the branchgit worktree remove + git branch -d after mergeNever leave worktrees open indefinitely. Stale worktrees accumulate disk usage and cause git worktree prune noise.
Before git worktree remove <path>:
git -C <path> status)# Check worktree status before removal
git -C .claude/worktrees/<name> status
git worktree remove .claude/worktrees/<name>
git branch -d <branch> # safe: refuses if unmerged
git branch -D <branch> # force: use only if abandoning
Worktrees share the same .git directory. Two agents cannot check out the same branch in different worktrees — git will refuse with fatal: '<branch>' is already checked out.
Rules:
| Situation | Use worktree | Use main context |
|---|---|---|
| Long-running tasks (>10 min) | ✓ | |
| Tasks touching many files | ✓ | |
| Parallel independent tasks | ✓ | |
| Quick single-file fix | ✓ | |
| Research-only (read-only) | ✓ | |
| Task must share context with parent | ✓ |
When using the Claude Agent SDK (Python/TypeScript) rather than the CLI, the equivalent of a worktree is a forked session. Sessions are stored at:
~/.claude/projects/<url-encoded-cwd>/<session-id>.jsonl
Fork a session to branch history without touching the original:
# Python
result = await query(prompt="implement auth changes", options={"forkSession": True})
# → new session branched from current history; original session untouched
// TypeScript
const result = await query({ prompt: "implement auth changes", options: { forkSession: true } });
Worktree vs forked session:
| Git worktree | Forked session | |
|---|---|---|
| Isolates | File system state (branch) | Conversation history |
| Parallel? | Yes — each has own branch | Yes — each has own session ID |
| Resumable? | Via EnterWorktree | Via resume: sessionId |
| Cleanup | git worktree remove | Sessions expire or are deleted |
| Use in | Claude Code CLI | Agent SDK programmatic use |
For CLI-based orchestration (this plugin's default), use worktrees. Use forkSession when building applications on top of the SDK.
To resume a specific session: resume: "<session-id>" in SDK options, or --resume in /cc-orchestrate (reads .claude/active-task.md for the last wave's session ID).
The cc-orchestrate command uses isolation: "worktree" for any template that fans out to multiple implementation agents. Each agent gets its own branch. The orchestrator collects the branch names and opens PRs or merges in sequence.
See skills/cc-agent-teams/SKILL.md for full multi-agent coordination patterns.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
21 skills in this plugin
/cc-agentic-patternsSelect and wire an agentic design pattern (reflection, prompt chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer, ReAct, blackboard) into the 5-layer Claude Code stack. Use this skill whenever deciding how to structure a multi-step task, whether to spawn subagents, how to run parallel review, or when to use which pattern. Triggers on: "which pattern", "orchestrate", "parallel review", "self-review", "chain of thought", "eval-optimizer loop", "blackboard", "ReAct", "how to decompose this task"./cc-agent-teamsSelect and coordinate multi-agent teams (topology kits, role-based squads, lifecycle, worktree isolation). Use this skill whenever launching parallel agents, designing a review board, running a debug council, scheduling an orchestrator-workers team, configuring agent tool restrictions, or deciding between solo and team execution. Triggers on: "launch a team", "parallel agents", "review board", "debug council", "architect-implementer-reviewer", "swarm", "multi-agent", "subagents for X", "team topology", "agent lifecycle"./cc-auto-modeAuto mode permission handling — classifier-based approvals, PermissionDenied hook, defer permissionDecision, and autonomy profiles for hands-off Claude Code usage/cc-autonomy-modeConfigure Claude Code's autonomous operating mode — profile selection (conservative, balanced, aggressive, unattended-review), permission blocks, and the three gate agents (planner, verifier, reviewer). Use this skill whenever enabling autonomous mode, switching profiles, tightening permissions for production branches, or setting up unattended execution. Triggers on: "autonomy", "unattended mode", "auto-approve", "permission mode", "autonomy profile", "gates", "/cc-autonomy", "planner verifier reviewer", "let claude run on its own"./cc-context-budgetingManage Claude Code's context window — token arithmetic, /compact strategy, anchor preservation, progressive loading, session analytics. Use this skill whenever a session gets long, context approaches limits, after /compact, when deciding what to load into CLAUDE.md vs leave in references, or when analyzing session cost/token usage. Triggers on: "context full", "compact", "too many tokens", "budget", "session analytics", "save tokens", "context window", "/compact strategy"./cc-deep-code-intelligenceEvidence-driven deep analysis for hard coding problems — architecture decisions, root-cause investigation, high-stakes refactor planning, performance bottleneck isolation. Use this skill whenever the user asks for "the best approach", a "deep analysis", "root cause", "principal engineer review", or runs /cc-intel. Also triggers on hard debugging questions, major architectural choices, tricky performance problems, or any task where a hypothesis tree and evidence table matter more than a fast answer.npx claudepluginhub thelobbi/claude --plugin claude-code-expertOther plugins' skills for the same job