skip to content

In Claude Code, how do `/branch` and `--fork-session` let you try a second approach without losing the first, and what does each carry over?

level: middleimportance: should knowfreq 14%

answer

  1. copy the conversation, not the code
  2. new session ID, original untouched
  3. same process versus a new one
  4. session-only approvals
  5. two terminals without forking

basics

~20 s

/branch copies the conversation so far into a new session and switches the running process into it; --fork-session does the same at launch with -c or -r. The original stays intact. Only /branch keeps Allow for this session grants, and neither copies your files.

solid answer

~40 s

`/branch [name]` copies the transcript up to now into a new session with its own ID and switches the running process to write to the copy; the confirmation prints both IDs, and the original stays on disk and in the picker, reachable with `/resume`. Because it is the same process, "Allow for this session" grants, background subagents and Bash commands, and a Remote Control connection all carry into the branch. `claude --continue --fork-session` or `claude --resume <id> --fork-session` forks at launch into a new process, so session-only grants are gone and you re-approve. Both copy the conversation only: edits from either branch land in the same working directory. Resuming one session in two terminals without forking interleaves both into one transcript.

code

bash · 5 lines
bash
# yesterday's session stays untouched; the experiment gets its own ID and name
claude --resume flaky-test --fork-session --name flaky-test-fixture-rewrite

# later, back to the original line of work
claude --resume flaky-test

go deeper

for a junior

Remember that /branch makes a copy of the conversation and switches you into it, and the original is kept for /resume.

for a middle

Explain the process difference: /branch stays in the running process and keeps session grants and background work; --fork-session starts a new process with a new session ID and must be combined with -c or -r.

for a senior

Call out the traps: branching copies the conversation but not the files, and two terminals on one unforked session interleave into a single transcript.

for a principal

Weigh conversation branching against isolated worktrees: branching is cheap for exploring reasoning, but parallel code changes need separate checkouts or they collide.

## What branching is for Halfway through a debugging session you often reach a fork in the road: retry the flaky test with a longer timeout, or rewrite the fixture. **Branching** lets you explore one direction while keeping the conversation as it stood, so you can come back and try the other. Claude Code offers two ways to do it, and the difference between them is **which process** ends up writing the copy. ## `/branch` inside a running session `/branch try-longer-timeout` (the name is optional) creates a copy of the conversation at this point and **switches you into it**. Without a name, the branch is named after the conversation's first prompt. Mechanically, Claude Code copies the transcript and points the running process at the copy, so: - the confirmation prints **two session IDs**, the new branch you are in and the original - the original is **unchanged on disk** and stays in the session picker; return with `/resume <original-name>` or its ID - the branch has its own session ID and appears as its own row; the picker groups related entries under one row you expand with the right arrow key ## `--fork-session` at launch `--fork-session` is a modifier for resuming: combine it with `--continue` or `--resume`. ```bash claude --continue --fork-session claude --resume flaky-test --fork-session ``` The resumed conversation gets a **new session ID** instead of reusing the original, so the original transcript is left alone. This is the route when you want to start a second line of work from a saved session in another terminal, or when you want to keep yesterday's session pristine while experimenting from it. ## What each one carries over | State | `/branch` | `--fork-session` | | :- | :- | :- | | Conversation history | Copied up to the point you branched | Copied from the saved transcript | | Session ID | New ID; the original keeps its own | New ID; the original keeps its own | | "Allow for this session" grants | Kept: same process | Lost: new process, so you re-approve | | Rules saved with "don't ask again" | Still apply | Still apply, read from settings files at launch | Because `/branch` keeps the same process, two more things follow it into the branch: - in-flight background subagents and background Bash commands keep running, and their output appears in the branch you switched into, not in the original - a Remote Control connection stays connected, so a phone or browser watching the session follows you into the branch The grant row is the one that bites. "Allow for this session" approvals live in the running process; rules you saved with "don't ask again" live in settings files that every launch reads. So a fork that suddenly asks again for something you approved an hour ago is expected behaviour, not a bug. ## What branching does not copy Both routes copy the **conversation**, not your **files**. If Claude edits `src/api.ts` in the branch, the original conversation's working directory has that edit too, because there is only one working directory. Two practical consequences: 1. Commit or stash before branching if you want a clean way back to the code as it was. 2. To run two approaches against separate copies of the code at the same time, use separate git worktrees, which Claude Code supports as its own parallel-work feature. Branching is also different from **rewinding**. Rewinding to a checkpoint moves the current session back to an earlier point and can restore code; branching never edits the original, it creates a second session. And it differs from copying a conversation into a background session that keeps working while you stay here, which is another command with its own rules. ## Two terminals, one session If you resume the **same** session in two terminals without forking, Claude Code does not stop you and does not copy anything: messages from both terminals **interleave into one transcript**. The next resume then replays a conversation in which two lines of work are mixed together. The fix is to decide up front: - one terminal per session, or - `--fork-session` in the second terminal, so each line of work owns its own session ID.

  • You open the same session ID in two terminals without forking. What happens, and what should you have done?
    Nothing blocks it: messages from both terminals interleave into one transcript, so the next resume shows two lines of work mixed together. Start the second terminal with `--fork-session` (or use `/branch` in the first) so each line of work gets its own session ID.
  • Why does a session forked with `--fork-session` ask again for commands the original already allowed?
    "Allow for this session" grants belong to the running process, and `--fork-session` starts a new one, so they are gone. Rules saved with "Yes, and don't ask again" live in settings files that every launch re-reads, so those still apply. `/branch` keeps session grants because it stays in the same process.
  • After `/branch`, how do you get back to the original conversation?
    The `/branch` confirmation prints the original's session ID alongside the new one. Run `/resume <original-name>` or pass that ID to `/resume`; the original is unchanged on disk and still listed in the session picker, where related entries are grouped under one row.

  • /branch snapshots the working tree, so each branch has its own files
  • Resuming one session in two terminals gives each terminal its own copy
  • /branch overwrites the original conversation from the branch point onward
  • --fork-session keeps every Allow for this session grant
  • Branching and rewinding to a checkpoint are the same operation