Long Claude Code sessions have a familiar failure mode: you reach a fork in the road, pick a direction, and twenty prompts later realize the other path was better. Starting over means rebuilding context from scratch. Anthropic's answer is /branch, a session command that copies the full conversation at the current point and switches you into the copy, leaving the original untouched. If the experiment fails, you resume the path you were on. If it succeeds, you keep the branch.
How Branching Works
From inside any active session, run /branch with an optional name:
- In-session:
/branch my-refactor-approachcreates a new session with the complete history copied up to that moment, then switches you into it. - From the CLI:
claude --continue --fork-sessionorclaude --resume <session-id> --fork-sessionforks before you even open the terminal UI. - Returning: use
/resume, the session picker, or pass the original session ID to pick up where you left off on either path.
After branching, the two sessions are fully independent. Messages, tool results, and file edits in one branch do not appear in the other. Anthropic prints both session IDs on confirmation so you can navigate between them deliberately.
/branch vs /fork
The command was originally called /fork and /fork still works as an alias in many builds. As of Claude Code v2.1.161, the semantics split:
/branchswitches you into a copy of the conversation so you can explore personally./fork <directive>spawns a background subagent that inherits the full conversation and works on a side task while you continue in the primary session.
That distinction matters. Branching is for A/B testing your own prompting strategy or implementation approach against the same loaded context. The subagent /fork is for delegation. Same word, different job.
What Gets Copied (and What Does Not)
Branches inherit the conversation transcript, project context, and file state as Claude Code understood it at the branch point. A few caveats worth knowing before you rely on it in production:
- Permissions do not carry over. Approvals you granted with "allow for this session" in the parent do not apply in the branch. You re-approve as needed.
- Plan files are isolated. Anthropic fixed an earlier bug where forked sessions shared the same plan file and edits in one branch overwrote the other. Branching is now reliable for parallel experiments.
- Resume without forking interleaves messages. If you open the same session in two terminals without
--fork-session, both streams merge into one transcript. Branch explicitly when you want separation.
Named branches group under their root session in the /resume picker. Press → to expand a tree when you have several forks from one debugging session.
Practical Workflows
The feature is small on paper and changes daily agent use in three common cases:
- Prompt A/B testing. Fork before a major refactor instruction. Run a conservative prompt in the branch and an aggressive one in the original. Compare diffs without re-explaining the codebase.
- Architecture decisions. When Claude proposes two viable patterns, branch and ask it to implement each fully. Pick the cleaner result instead of debating hypothetically.
- Safe exploration after a working state. You finally got tests green. Branch before asking for the next feature so you can always
/resumeback to the passing baseline.
Combined with Dynamic Workflows and nested subagents, a single developer can run a primary session, delegate parallel sub-tasks, and keep experimental branches isolated without starting three separate projects from zero context.
Why It Matters for Web Developers
Agent sessions are expensive in tokens and time. Re-establishing context after a wrong turn is the hidden tax on every long migration or multi-file feature. /branch treats conversation state the way git treats commits: branch to experiment, keep main clean, merge the winner manually by continuing in the branch you prefer.
There is no merge command yet. Branching is copy-and-diverge, not automatic reconciliation. For most web dev workflows that is enough. Try it on your next stuck session: branch before the risky prompt, run both paths for ten minutes, and compare which diff you would actually ship.