·

Claude Code Fork Session Into a New Worktree

Prepared and checked using AI. Sources are linked in the article.

claude-code git-worktrees tutorial ai-coding

To fork a Claude Code session into a new worktree, combine --resume, --fork-session, and --worktree. The second session inherits the saved conversation, gets a new session ID, and edits a separate checkout. --fork-session creates the new conversation identity; the worktree provides the separate files.

Name the original conversation

Start with Claude Code installed and authenticated, inside a Git repository. For example, use design-source for the original conversation and design-alternative for the new worktree and branch label.

In the original Claude Code session, enter:

/rename design-source

You can resume a conversation by its assigned name or session ID. A specific identifier avoids the ambiguity of --continue, which selects the most recent session in the current directory.

Wait until the original reaches the point you want to share, then launch the fork in another terminal. Treat that point as a handoff: write down the alternative task and the files it should change.

Launch the fork from the original checkout

Run this from the checkout whose current commit should be the starting point:

claude --resume design-source --fork-session \
  --worktree design-alternative \
  --settings '{"worktree":{"baseRef":"head"}}'

The inline --settings value applies to this session. worktree.baseRef: "head" starts the new worktree from your current local HEAD, including unpushed commits. Without this override, the default "fresh" base uses the repository’s default branch on the remote, with a local HEAD fallback when that remote base is unavailable.

By default, this creates .claude/worktrees/design-alternative/ on branch worktree-design-alternative. Choose an unused worktree name: an existing name reopens its worktree.

If interactive startup requests workspace trust, run claude once in the launch directory and accept the trust dialog before retrying. Initialize dependencies and required local configuration in the new checkout.

Give the fork an explicit instruction, for example:

Explore the alternative implementation we discussed. Before editing,
inspect this checkout and reconcile it with the conversation history.
Keep your changes in this worktree.

Create the worktree yourself for an explicit base

For direct control over the path and starting commit, create the worktree with Git first. Using ../design-alternative as an example sibling path, run these commands from the original checkout in a second terminal:

git worktree add -b design-alternative ../design-alternative HEAD
cd ../design-alternative
claude --resume design-source --fork-session

git worktree add -b creates a new branch at the supplied commit and checks it out in a separate directory. Replace HEAD with the desired commit or branch reference when appropriate. Use a new branch name and an unused destination path.

With --fork-session, Claude starts in the launch directory and leaves the source session’s worktree untouched.

Conversation history does not reproduce file state

A checkout from HEAD contains committed files. Uncommitted edits in the original checkout do not become part of that commit. If the fork needs those edits, commit the intended starting state before creating its worktree, or deliberately transfer the changes it needs. See why agent worktrees miss uncommitted changes.

This matters when the inherited conversation describes an edit that the fork’s checkout does not contain. Ask the fork to inspect the actual files before implementing its alternative.

A separate CLI process also starts without the original process’s “allow for this session” permission grants. Expect to approve permissions again as needed.

Keep the two sessions distinguishable

Rename the fork after startup so future resumes target the intended conversation. Avoid resuming the original session simultaneously in two terminals without --fork-session: both terminals would write into the same transcript.

Use git worktree list to inspect checkout paths, revisions, and branches. For returning to saved work, see resume a coding agent session in the right worktree.

Where Parallel Code fits

Parallel Code is our free, open-source desktop app for macOS and Linux. It runs several AI coding agents in parallel, each isolated in its own Git worktree, with a diff-first review surface. It fits the workflow of developing alternatives in separate checkouts and reviewing their changes.