Branch: Fork a Session
/branch creates a fork of your current Claude Code conversation — a new session that starts from the same context, files, and history, but evolves independently. Think of it as git branching for your AI conversation: the original session is preserved exactly as it was, and the fork can go in a different direction.
Syntax
# Fork the current session (interactive)/branch [name]
# Examples/branch try-refactor-approach/branch explore-graphql-alternative/branch risky-migration
# Fork from CLI (resume a saved session at a fork point)claude --resume <session-id> --fork-session
# List branches from the current session/branch --list
# Switch back to original session/branch --switch mainThe name is optional but recommended — it makes it easier to identify branches when you have several active forks.
When to Use Branching
Trying a Risky Approach
You are about to ask Claude to do something irreversible or hard to undo — a large refactor, a schema migration, a wholesale rewrite of a module. You want to see the result before committing to it.
Fork first. If the approach works, keep the fork. If it doesn’t, the original session is untouched.
Exploring Alternatives in Parallel
You have two plausible architectural directions. Instead of asking Claude to try one, evaluate, then try the other sequentially (losing context each time), fork into two sessions and explore both simultaneously.
Isolating Experiments
You are deep into a debugging session and want to try a speculative fix that might make things worse. Fork, apply the fix in the fork, evaluate — without disturbing the known-good state of the original session.
How the Original Session Is Preserved
When you run /branch, Claude Code:
- Snapshots the current session state: conversation history, file context, tool results, memory
- Creates a new session initialized from that snapshot
- Continues the original session exactly where it was — no changes, no side effects
The fork and the original session share the snapshot as a read-only base. Changes made in either session after the fork are independent. Files written in the fork do not appear in the original session’s file context unless you explicitly merge or pull them.
Session Fork Flow
Example: Fork to Compare Refactor Approaches
You are refactoring a data-fetching layer. Two approaches are on the table: React Query or SWR. You want to see a real implementation of each before deciding.
# In your current session — context is loaded, you understand the codebase/branch try-react-query# Claude Code opens a new terminal tab with the forked session
# In the fork: try approach A"Refactor all data fetching in src/hooks/ to use React Query. Keep the same external API — components should not need to change."
# Back in original session: try approach B/branch try-swr"Refactor all data fetching in src/hooks/ to use SWR. Keep the same external API — components should not need to change."Both forks run simultaneously (in separate terminal tabs or tmux panes). You compare the diffs side by side and pick the approach you prefer.
Forking from CLI
If you saved a session ID and want to fork from a specific point later:
# Save the session ID when you want a fork pointclaude --print-session-id# → session-abc123
# Later, resume at that fork pointclaude --resume session-abc123 --fork-session
# The original session-abc123 is untouched# A new session branches from itThis is useful for creating reproducible experiment baselines — fork the same session multiple times to test different prompts or approaches against identical starting conditions.
Gotchas
File changes are not automatically synced. If the fork writes files and the original session also writes the same files, you have a manual merge situation. Plan your fork so each branch owns distinct files, or use the fork only for exploration (not production commits).
Branches do not communicate. Two forked sessions have no awareness of each other. They cannot share tool results, file reads, or conversation history after the fork point.
Session IDs are required for CLI forking. The --resume --fork-session pattern requires that you captured the session ID at fork time. If you did not, you cannot retroactively fork an old session.
Memory writes in forks. If Claude writes to CLAUDE.md or project memory in a fork, those writes stay in the fork’s context. They do not propagate back to the original session or to your actual CLAUDE.md file unless the fork explicitly commits and pushes.