Harness Notes

Forking

Updated 2026-11-22,

On this page

Branching a session into a copy you can take somewhere else, and going back to an earlier point. Subagents that start from your conversation are on the Subagents page.

Worktrees: create, set up, integrate and clean up isolated checkouts

QuestionClaude Codechecked at 2.1.300
Fork a session

Inside a session, /branch [name] copies the conversation and switches you into the copy, while /fork [prompt] copies it into a new background session (its own row in claude agents) and keeps you where you are. From the shell, add --fork-session to claude --continue or claude --resume <id|name> to continue in a copy with a new session ID.

/fork became a background copy in v2.1.212; before that (and whenever agent view is turned off) it starts a forked subagent, which is now /subtask.

/fork was the old name of /branch before v2.1.77.

A session started with flags the copy can't inherit, such as a replaced system prompt or a --tools allowlist, can't be copied with /fork.

Fork or rewind from an earlier point

Partly

In the terminal, /rewind (aliases /checkpoint, /undo) or Esc twice on an empty prompt opens a list of your earlier prompts, where Restore conversation rewinds the current session to that point rather than making a copy. The VS Code extension has Fork conversation from here on any message, and the Agent SDK's forkSession(sessionId, { upToMessageId }) copies the transcript only up to a chosen message.

/branch and --fork-session always copy the whole conversation as it stands; to branch from an earlier point in the CLI, run /branch first and then /rewind in the copy.

What the fork keeps

Every fork copies the conversation history up to the fork point. /branch stays in the same process, so model, settings, "allow for this session" grants and running background work carry over; /fork copies the model, permission mode, effort and any added directories and "don't ask again" grants into the new background session. A --fork-session launch is a fresh process: session-only grants are not carried, launch flags like --model or --permission-mode apply to the copy, and it starts in the directory you launched from.

With --fork-session, a session that ended in plan mode is not put back into plan mode.

File changes and worktrees

Forking copies the conversation, not your files: /branch and --fork-session keep working on the same checkout. /fork copies are told to make their code changes in a git worktree of their own, and you can start any session isolated with claude --worktree <name>. Separately, checkpoints let /rewind restore files that Claude's edit tools changed (Restore code, or Restore code and conversation).

Checkpoints don't cover changes made by Bash commands, most subagent edits, or symlinked and hard-linked files.

A fork made with the SDK's forkSession() doesn't include the original's file checkpoints.

Where a fork came from

Partly

/branch prints both the new and the original session IDs, and the original stays in the /resume picker, so you switch back with /resume <original-name> or its ID. /fork copies show up as their own rows in claude agents and /resume with a ⑂ fork name, and SDK forks are titled after the original with (fork). There is no tree view of parent and child sessions.

SessionStart hooks see source: "fork" when a session starts as a fork.

Fork from the SDK or API

Headless: claude -p --resume <id> --fork-session "prompt". In the Agent SDK, set forkSession: true (fork_session=True in Python) together with resume, or call forkSession(sessionId, { upToMessageId, title }) / fork_session() to copy a transcript without running it; resumeSessionAt resumes at a specific message.

For an unsaved fork, combine it with --no-session-persistence (print mode) or persistSession: false in the SDK.

Notes and sources

Claude Code, 11 sources
Fork a session, 4
Fork or rewind from an earlier point, 3
What the fork keeps, 3
File changes and worktrees, 4
Where a fork came from, 3
Fork from the SDK or API, 3