Home › Articles

Fork a session in Claude Code, Codex and Cursor to try a new approach

Updated 2026-11-19

In short: all three tools can copy a conversation so you can try a different approach without losing the one you have. Claude Code has /branch (switch into the copy), /fork (copy runs in the background) and claude --resume <id> --fork-session. Codex has /fork, codex fork and codex exec fork. Cursor can fork a whole chat or fork from one message in the editor, and has /fork in the CLI. A fork copies the chat, not your files, so put the second attempt in a worktree if both will edit code.

Checked against each vendor's docs (and, for Codex, the v0.170.0 source) on 19 November 2026. We did not run these commands inside live Claude Code, Codex or Cursor sessions.

Side by side

Claude CodeCodex CLICursor
Copy the chat and switch into it/branch [name]/forkEditor: fork from the tab menu, sidebar or command palette. CLI: /fork
Copy it and keep both running/fork [prompt] (new background session)Not documented as a separate commandNot documented
Fork from an earlier messageNot documented (forks at the current point)Esc twice on an empty composer, edit the messageEditor: fork from that message (later messages are dropped)
Fork a saved session from the shellclaude --resume <id or name> --fork-session, claude --continue --fork-sessioncodex fork, codex fork --last, codex exec fork <id or name> [prompt]No fork flag in the CLI parameters
Keep the files apart/fork copy is told to make its own worktree/fork may offer a new worktree; codex fork <id> --worktree/worktree (editor), agent --worktree (CLI)
Quick tangent, no fork/btw (no tools, not saved to the chat)/side or /btw/side or /btw (side chat)
Back to the original/resume/resume or codex resumeEditor: the original chat stays. CLI: /resume, agent ls

When to fork instead of undo or start over

Claude Code: /branch, /fork and --fork-session

/branch: switch into a copy

Run /branch with an optional name:

/branch try-streaming-approach

Claude Code copies the conversation up to this point and switches you into the copy. The confirmation prints two session IDs: the branch you're now in and the original. The original is unchanged on disk, so /resume <original-name> (or its ID) takes you back. Leave out the name and the branch is named after the first prompt of the conversation.

Because /branch keeps the same Claude Code process, a few things follow you into the branch:

The docs describe what /branch does to the conversation only; they don't say it copies or isolates any files. Treat the branch as working in the same checkout.

/fork: a copy that runs in the background

/fork copies the conversation into a new background session while you keep working where you are. The copy carries over the model, permission mode, effort level, and any directories or "don't ask again" grants you added. After that the two are independent.

/fork try the same refactor with a single cache layer instead

With a prompt, the copy starts on it right away. Without one, it waits in agent view: open claude agents, select its row and press Space, or run claude attach <id> with the ID from the confirmation. Unless the copy edits in place, Claude Code tells it to create its own git worktree before changing code (this needs Claude Code v2.1.221 or later). Background sessions put those worktrees under .claude/worktrees/, and skip them in some cases, for example when the folder isn't a git repository and no WorktreeCreate hook is set.

If agent view is turned off (disableAgentView or CLAUDE_CODE_DISABLE_AGENT_VIEW), /fork starts a forked subagent instead.

--fork-session: fork from the command line

claude --continue --fork-session
claude --resume auth-refactor --fork-session

--fork-session works with --resume or --continue and gives the resumed conversation a new session ID instead of reusing the original. It runs as a new process, so it starts without the original's "Allow for this session" grants and you approve again. Sessions made with /branch or --fork-session appear as their own rows in the /resume picker, grouped under the original (press → to expand).

The docs also give a reason to use it in scripts: if you resume the same session in two terminals, or in two claude -p runs at once, both write to one transcript and messages from one can go missing later. Add --fork-session to each command to keep both. (For more on claude -p in scripts, see running agents headless.)

Related: /subtask and /btw

Codex: /fork, codex fork and codex exec fork

Inside a session

Type /fork and press Enter. Codex clones the chat into a new chat with a fresh ID and leaves the original transcript untouched. If it offers a checkout choice, pick the current directory or a new worktree; choose the worktree if the fork will edit code while the original also does. In the v0.170.0 source, /fork isn't available while a task is running, so wait for the turn to end (or stop it) first.

To fork from an earlier point, press Esc twice with an empty composer. Codex lets you edit your previous message and forks the chat from there.

From the shell

# pick a saved session from the list
codex fork
# fork the most recent session in this folder (add --all for every folder)
codex fork --last
# fork a specific session into a new managed Git worktree
codex fork <SESSION_ID> --worktree

# non-interactive: copy a saved session and send it a new prompt
codex exec fork <SESSION_ID> --worktree "try an alternative approach"

codex fork takes a session UUID. codex exec fork takes a UUID or a session name; with no prompt it creates the fork without starting a turn. --worktree needs local execution and can't be combined with resume, review, --ephemeral or --ignore-user-config.

/side for a tangent

/side (alias /btw) opens a side chat whose transcript is separate from the parent; you can add the question inline, as in /side Check whether this plan has an obvious risk. While you're in it, the TUI still shows the parent chat's status. Side chats are temporary by default (with features.tui_workspace on and saved history, you can reopen them), and you can't open one inside another side chat or during review mode. Unlike /fork, the source allows /side while a task is running.

Cursor: fork a chat, or open a side chat

In the editor

Cursor's docs don't say a fork gets its own copy of your files. For a second attempt at the code, start it with /worktree so the rest of that chat runs in a separate checkout, or use /best-of-n to run one task across several models, each in its own worktree. /apply-worktree brings the result into your main checkout and /delete-worktree cleans up.

/worktree try the same fix with a retry wrapper instead of a timeout

Side chats

Type /side or /btw (optionally with a question), use the plus button at the top of the chat panel, select text and choose Ask in Side Chat, or press Shift+Cmd+S (Mac) / Shift+Ctrl+S (Windows, Linux). A side chat gets the parent's history as hidden context, keeps its own transcript and stays until you close it. @-mention it in the main chat to pull what it found back in. Side chats can't be nested and are local only for now (not Cloud Agents). Cursor's own help page is clear that a side chat is not a fork: it doesn't reproduce the parent transcript.

In the CLI

The Cursor CLI has /fork ("Fork the current chat into a new session"), plus /resume, /rename and /rewind. There's no fork flag in the CLI parameters; to come back to a chat later use agent ls, agent resume or --resume [chatId], and start an isolated run with agent --worktree [name].

A clean way to try two approaches

This is our routine, built from the commands above:

  1. Commit or stash first. A fork copies the chat, not the working tree, so give both attempts the same clean starting point.
  2. Name the original so you can find it again (/rename in all three; claude -n when you start Claude Code).
  3. Fork into a worktree: /fork in Claude Code, /fork with a new worktree or codex fork <id> --worktree in Codex, /worktree or /best-of-n in Cursor. If you use /branch or a plain fork in the same checkout, don't let both edit at once.
  4. Give each side one clear instruction ("same feature, but with X"), then compare the diffs and run the tests in each checkout.
  5. Keep the winner, delete the rest. Merge or apply the winning worktree and remove the other. The worktrees guide covers the git side.

FAQ

What is the difference between /branch and /fork in Claude Code?

/branch copies the conversation up to this point and switches you into the copy; the original stays on disk and you go back with /resume. /fork copies the conversation into a new background session and you keep working in the original, so both run at once. The /fork copy is told to make its own git worktree before it edits code. If agent view is turned off, /fork starts a forked subagent instead.

How do I fork a Claude Code session from the command line?

Add --fork-session to --continue or --resume, for example claude --continue --fork-session or claude --resume auth-refactor --fork-session. You get a new session ID and the original is left alone. The new process starts without the original's "Allow for this session" permission grants, so you approve those again.

Does forking a chat copy my files?

No tool says a conversation fork copies your files. Claude Code's /branch runs in the same process, Cursor's fork copies messages and subagents, and Codex's /fork copies the chat. To keep code apart, use a worktree: Claude Code's /fork copy is told to create one, Codex's /fork can offer a new worktree and codex fork takes --worktree, and Cursor has /worktree in the editor and --worktree in the CLI.

How do I fork a Codex session?

Type /fork in the Codex CLI to clone the current chat into a new chat with a fresh ID; if Codex offers a checkout choice, pick the current directory or a new worktree. To fork a saved session, run codex fork (picker), codex fork --last, or codex fork <SESSION_ID> --worktree. Pressing Esc twice on an empty composer edits your previous message and forks from that point.

Is a side chat the same as a fork?

No. A fork copies the conversation into a new chat you continue on its own. A side chat (/side or /btw in Codex and Cursor) is a separate thread for a quick tangent that leaves the main transcript alone. Cursor's side chat gets the parent history as hidden context and you @-mention it to bring findings back. Claude Code's /btw is a single answer with no tools, and pressing f turns it into a forked subagent.

Sources

Official docs, checked 2026-11-19.

Get the free rules sampler + new tips by email

Confirm your email and we'll send you straight to the sampler download. Then one short email every two weeks covering tool format changes (Cursor, Claude Code, Codex, Windsurf, Copilot), new rules and kit updates. No spam.

We store only your email, with our email provider Resend. See the privacy policy.

Unsubscribe anytime from any email. Rather skip email? Get the sampler on GitHub or download the zip directly.