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

QuestionCodex CLIchecked at 0.164.0Claude Codechecked at 2.1.310Cursor Agentchecked at docs-2026-10-27OpenCodechecked at v2-docs-2026-10-27pichecked at retained-extension-auditAntigravity CLIchecked at 1.5.14
Create or enter

Start a local session with codex --worktree or codex exec --worktree. The local TUI new/fork picker offers Create new Git worktree; /worktree browses managed worktrees.

CLI/TUI source inspected at 0.164.0. Desktop Worktree mode is a separate host surface.

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.

The Agents Window creates or moves a task into a worktree. IDE Worktree Skills provide /worktree; the retained CLI documentation records -w/--worktree [name].

Agents Window, IDE skills and CLI are distinct entry points.

CLI flags retained from the existing versioned Forking contract.

In Code Mode, call opencode.worktree_create with a name; it returns a directory. worktree_list lists project worktrees. Project configuration chooses the destination and strategy.

Not documented

The retained audit describes running pi or a subagent extension with a selected working directory. Built-in managed-worktree creation has not been established here; create a checkout externally when needed.

Partly

Google documents CLI subagent worktrees under the worktrees directory in app data. Direct interactive CLI creation remains unverified.

Starting state

The inspected CLI/TUI creation paths pass no base override, so the manager creates a detached checkout of the source checkout's current HEAD. Tracked edits, staged changes and untracked files are not carried over. The default allocation root is $CODEX_HOME/worktrees.

The host-local desktop.git-worktree-root setting can override the root. A detached checkout has no new branch until you create one.

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.

Not documented

This audit does not establish a common starting revision or dirty-change carryover rule across Cursor CLI, Agents Window and IDE Worktree Skills.

Not documented

The tools reference delegates worktree strategy to project configuration; this audit does not establish the base revision or dirty-file carryover for every strategy.

Not documented

The externally created checkout determines the starting revision and carried files. No pi-specific base selection contract is recorded.

Partly

Since 1.5.5 an isolated worker’s Git worktree includes staged, unstaged and untracked changes. Explicit selection of the base ref remains unverified.

Session isolation

New sessions can run in a managed worktree. codex fork <id> --worktree and codex exec fork <id> --worktree copy a conversation into a new checkout. The CLI rejects --worktree with resume, queue, archive, unarchive and delete; fork requires an explicit session.

The inspected --worktree startup path requires local execution and refuses an explicitly untrusted source.

0.165.0 TUI resume picker adds a Repo filter alongside Cwd and All when several local worktrees exist, listing sessions from matching directories across linked worktrees. The Cwd filter and resume --last/fork --last still use only the current directory.

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.

Agents Window can start or move a task into a separate checkout. In the IDE, /worktree runs the rest of that chat in an isolated checkout.

After creating a checkout, use session_move to move the session into its directory. The move takes effect at a safe boundary, so directory-dependent work belongs in a later call.

Not documented

Launch pi in an externally prepared checkout. A session fork changes conversation history; it does not establish a separate filesystem checkout.

Partly

The /fork command reuses the existing checkout. Launching a top-level CLI conversation in a harness-created worktree remains unverified.

Subagent isolation

Partly

The inspected built-in spawn path prepares a child config using the parent turn's cwd; it does not allocate a worktree in that path. A chat in a managed worktree and a subagent with its own worktree are separate capabilities.

This describes the traced built-in path, not every custom host, remote provider or extension.

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.

Partly

By default, subagents edit the parent's checkout directly, so parallel subagents can overwrite each other. If you ask for isolation ("... each in its own environment"), each subagent gets its own branch, either in a Git worktree on the same machine or in a cloud VM with a fresh clone, and its changes stay on that branch until the parent merges them. In the CLI you can also isolate the whole session with agent --worktree [name], which creates a worktree under ~/.cursor/worktrees/<repo>/<name>.

In CLI 2026.10.12, per-subagent isolation sits behind a feature flag that is off by default, so it may not be available in every CLI session.

Retained from the Subagents audit checked 2026-10-15; not re-probed for this page.

Subagents run in the parent session's directory and edit your checkout directly; there is no automatic per-subagent worktree or sandbox, so there is nothing to merge. Worktrees exist as separate session tools (worktree_create, session_move), which an agent can use to move a whole session into a new worktree.

Retained from the Subagents audit checked 2026-10-15; not re-probed for this page.

Not documented

The retained example subagent extension uses the parent directory or an explicitly supplied per-task cwd. An external checkout can be supplied; automatic per-child worktree allocation is not established.

Google documents Git worktrees for subagents and swarm workers given an isolated repository copy. From 1.5.5 it also documents isolated copies outside Git, with size and entry limits.

Setup and environment files

Not documented

Provision dependencies and local environment files in the new checkout. The inspected manager materializes committed files; this audit has not established an automatic dependency setup or ignored-file copying mechanism for CLI worktrees.

Do not infer desktop setup behavior from the CLI manager or from shared root settings.

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.

Configure .cursor/worktrees.json with setup-worktree, setup-worktree-unix or setup-worktree-windows. Each accepts command arrays or a script path; OS-specific keys take precedence. Setup can copy environment files using ROOT_WORKTREE_PATH.

Not documented

Project worktree configuration selects the strategy. Automatic dependency installation, environment-file copying and custom strategy setup semantics have not been traced for this page.

Not documented

Provision dependencies and local environment files in the selected checkout. No managed-worktree setup contract is recorded for the audited core/example extension.

Not documented

A setup script or post-creation hook for a new worktree remains unverified.

Review and integrate changes

Partly

Review the detached checkout and preserve the result on a branch or in commits before integrating it with normal Git operations. The inspected creation path returns a checkout with no branch; it does not establish a desktop Apply or automatic merge contract.

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.

Review in the Agents Window, keep working there, or commit/open a PR from that checkout. IDE /apply-worktree brings changes into the main workspace; /best-of-n compares isolated runs without merging them automatically.

Not documented

The tools reference describes creation, movement and removal; this audit does not establish an automatic merge or apply-back contract. Review and integrate the resulting checkout according to the configured strategy.

Not documented

Use the integration workflow of the externally managed checkout. No automatic apply-back or merge contract is recorded.

Not documented

Built-in merging or applying changes back to the parent remains unverified.

Exit and cleanup

CLI settings explicitly disable automatic cleanup. The TUI worktree browser supports explicit removal through the manager: it refuses the current checkout and ignored local files, then calls git worktree remove without force. Thread history is retained.

The manager's removal checks are source evidence, not a runtime-tested guarantee about unpushed commits or desktop 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.

Partly

IDE /delete-worktree removes a checkout. Cursor 3.5+ documents periodic machine-wide cleanup controlled by cursor.worktreeCleanupIntervalHours and cursor.worktreeMaxCount (default 25). This audit has not established its protections for dirty files or unpushed commits.

The cleanup settings describe the Cursor host version, not a CLI release version.

Partly

worktree_remove removes a checkout recorded for the project. force allows discarding uncommitted changes; removal requests the edit permission on the checkout directory. Protection for unpushed commits and automatic sweeping remain unverified.

Not documented

Cleanup of externally managed checkouts belongs to that workflow. This audit does not establish pi-specific retention or removal safeguards.

Not documented

The worktree location is documented. Cleanup triggers and ownership remain unverified.

CLI, tools and APIs

Partly

CLI entry points create the checkout locally before using App Server. App Server thread/start and thread/fork accept a cwd; that field selects a directory and does not by itself establish a worktree-creation API. A client can arrange a checkout before supplying its path.

The traced CLI caller and protocol are distinct. Custom hosts and hosted worktree services remain outside this audit.

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

Partly

CLI -w/--worktree [name] is retained in the fork audit; setup configuration is documented for CLI, IDE and Agents Window. A public worktree-management SDK/API contract is not established here.

CLI flags retained from the existing versioned Forking contract.

Code Mode exposes worktree_create, worktree_list, worktree_remove and session_move. Creating a worktree and moving the session are separate operations. These V2 utilities do not establish equivalent V1 commands or an identical external protocol.

Not documented

The retained extension accepts a per-task cwd. That establishes directory selection, not a managed-worktree API across arbitrary extensions.

Not documented

No CLI automation contract for worktree lifecycle was established.

Commands

From your shell

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

TaskCodex CLIchecked at 0.162.1Claude Codechecked at 2.1.296
Set up
Create

codex [exec] --worktree

Start a new local session in a managed detached Git checkout. Explicit session forks also accept --worktree.

1 note

Source inspected at 0.164.0; no worktree lifecycle runtime probe.

claude --worktree [name]

Create or reopen a session worktree; alias -w.

Inside a session

Slash commands you type into an open session.

TaskCodex CLIchecked at 0.162.1Claude Codechecked at 2.1.296
Use
Open the manager

/worktree

Browse managed worktrees and choose actions, including explicit removal.

1 note

Source inspected at 0.164.0; no worktree lifecycle runtime probe.

—

Notes and sources

Codex CLI, 14 sources
  • Source inspection at rust-v0.164.0 (6aaac694803004a63c6f393d153c96d22521a6b9). No lifecycle runtime probe; desktop, hosted services and custom/cloud providers are outside the traced paths.
Create or enter, 4
Starting state, 4
Session isolation, 3
Subagent isolation, 2
Setup and environment files, 1
Review and integrate changes, 1
Exit and cleanup, 4
CLI, tools and APIs, 3
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
Cursor Agent, 6 sources
  • Documentation reviewed 2026-10-27; retained subagent answers keep their original source/version boundaries. No lifecycle runtime probe.
Create or enter, 4
Starting state, 1
Session isolation, 1
Subagent isolation, 3
Setup and environment files, 1
Review and integrate changes, 1
Exit and cleanup, 1
CLI, tools and APIs, 4
OpenCode, 4 sources
  • Documentation reviewed 2026-10-27; retained subagent answers keep their original source/version boundaries. No lifecycle runtime probe.
Create or enter, 1
Starting state, 1
Session isolation, 1
Subagent isolation, 3
Setup and environment files, 1
Review and integrate changes, 1
Exit and cleanup, 1
CLI, tools and APIs, 1
pi, 1 source
  • Retained pi core/example-extension audit from 2026-10-15; no exhaustive extension audit or 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, 1
CLI, tools and APIs, 1
Antigravity CLI, 3 sources
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, 1
CLI, tools and APIs, 1