Fork a session in Claude Code, Codex and Cursor to try a new approach
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.
Side by side
| Claude Code | Codex CLI | Cursor | |
|---|---|---|---|
| Copy the chat and switch into it | /branch [name] | /fork | Editor: 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 command | Not documented |
| Fork from an earlier message | Not documented (forks at the current point) | Esc twice on an empty composer, edit the message | Editor: fork from that message (later messages are dropped) |
| Fork a saved session from the shell | claude --resume <id or name> --fork-session, claude --continue --fork-session | codex 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 resume | Editor: the original chat stays. CLI: /resume, agent ls |
When to fork instead of undo or start over
- Fork when the conversation so far is worth keeping (the agent has read the code, you've agreed on a plan) and you want to try option B without losing option A.
- Undo when the last steps were simply wrong. See undo
an AI agent's changes for
/rewind, Restore Checkpoint and Codex's Git-based revert. - Start fresh when the context is full of dead ends. Our context window article covers compact versus clear.
- Side chat when you only have a question and don't want it in the main transcript.
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:
- "Allow for this session" permission grants still apply.
- Background subagents and background Bash commands keep running, and their output shows up in the branch, not the original.
- A Remote Control connection (phone or browser) follows 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
/subtask <task>starts a forked subagent: it inherits the whole conversation, works in the background, and only its final result comes back to your chat. Use it when you want an answer back, not a second session. More in custom subagents./btw <question>asks a side question that sees the conversation but has no tools and isn't added to the history. Pressfin the answer to fork it into a background subagent with full tool access.
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
- Fork the whole chat from the tab menu, the sidebar or the command palette. Every message and subagent is copied.
- Fork from a message to copy the conversation through that message. Everything after it is dropped, including subagents attached to later messages.
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:
- Commit or stash first. A fork copies the chat, not the working tree, so give both attempts the same clean starting point.
- Name the original so you can find it again (
/renamein all three;claude -nwhen you start Claude Code). - Fork into a worktree:
/forkin Claude Code,/forkwith a new worktree orcodex fork <id> --worktreein Codex,/worktreeor/best-of-nin Cursor. If you use/branchor a plain fork in the same checkout, don't let both edit at once. - Give each side one clear instruction ("same feature, but with X"), then compare the diffs and run the tests in each checkout.
- 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
- Claude Code docs: Commands (/branch, /fork, /subtask, /btw)
- Claude Code docs: Manage sessions, Branch a session
- Claude Code docs: CLI reference (--fork-session, --resume, --name)
- Claude Code docs: Agent view (copy the session with /fork, file edit isolation)
- Claude Code docs: Subagents, Fork the current conversation
- Claude Code docs: Interactive mode (side questions with /btw)
- Codex docs (ChatGPT Learn): Developer commands (/fork, codex fork, codex exec fork, /side)
- Codex source on GitHub, v0.170.0: slash commands
- Cursor help: Side chats (and how forking differs)
- Cursor docs: Agent overview (side chats)
- Cursor docs: CLI slash commands (/fork, /resume, /rewind)
- Cursor docs: CLI parameters (--resume, --worktree)
- Cursor docs: Worktrees (/worktree, /best-of-n)