Harness Notes

Worktrees

Updated 2026-11-22,

On this page

How each harness creates an isolated checkout, what it starts from, and what happens to the changes afterward. Worktrees isolate files; conversation forks and subagent context are separate. Unknown answers mark gaps in the recorded evidence, not proof that a capability is absent.

Forking: conversation history and file isolation

Subagents: delegation and workspace isolation

QuestionClaude Codechecked at 2.1.310
Create or enter

Use claude --worktree <name> (-w) or ask Claude to call EnterWorktree. Git-created checkouts default to .claude/worktrees/<name> on a worktree-<name> branch; an existing name reopens a checkout.

Starting state

The default worktree.baseRef: "fresh" starts from the remote default branch, with local HEAD fallback. Set "head" to include committed feature-branch work. Uncommitted files are not part of that base.

Session isolation

The whole session can enter a worktree, and EnterWorktree can switch to an existing one. Resume re-enters a retained bound worktree after validation; --fork-session instead starts in the launch directory.

Subagent isolation

Request worktree isolation or set isolation: worktree in a custom subagent definition. Each child receives its own temporary checkout, using the same configured base selection as session worktrees.

Setup and environment files

Install dependencies in the fresh checkout. .worktreeinclude copies matching gitignored files such as .env. WorktreeCreate can replace creation; that hook must handle its own file copying and setup.

Review and integrate changes

Partly

Changes stay on the worktree branch for review and integration. Keeping a checkout preserves its files and branch; removing it can discard that work. The documented lifecycle does not promise automatic integration.

Exit and cleanup

Interactive exit checks for local work and new commits before offering keep/remove; a clean unnamed worktree can be removed automatically. -p leaves its checkout. Subagent/background cleanup retains dirty or unpushed work; hook-created worktrees follow separate removal rules.

Named sessions, submodules and inability to verify state affect cleanup. See the source for the full rules; no cleanup runtime probe was run.

2.1.311 publisher fixes an isolated subagent worktree being removed while a background subagent it spawned is still working there. This supplements the 2.1.310 documentation baseline; no cleanup runtime probe.

CLI, tools and APIs

The CLI supports --worktree; model-callable EnterWorktree and ExitWorktree enter and leave a checkout. WorktreeCreate and WorktreeRemove customize lifecycle operations, including non-Git systems.

Commands

From your shell

Commands you run in a terminal or script, outside a session.

TaskClaude Codechecked at 2.1.296
Set up
Create

claude --worktree [name]

Create or reopen a session worktree; alias -w.

Notes and sources

Claude Code, 2 sources
  • Publisher documentation reviewed against the 2.1.310 baseline; implementation unavailable and no lifecycle runtime probe.
Create or enter, 1
Starting state, 1
Session isolation, 1
Subagent isolation, 1
Setup and environment files, 1
Review and integrate changes, 1
Exit and cleanup, 2
CLI, tools and APIs, 1