Claude Code ships /fork command, letting developers branch AI sessions with full context inheritance starting in v2.1.161
Anthropic has shipped a /fork command to Claude Code, enabling developers to branch an AI coding session into a parallel subagent that inherits the full context of the existing conversation — a capability the company describes as the inverse of a standard subagent and directly analogous to creating a git branch mid-session. The feature became enabled by default starting in Claude Code v2.1.161.
What's new
A standard Claude Code subagent starts with a fresh, isolated context window and receives only a summary of the task. A forked subagent is different: it inherits the entire conversation — the system prompt, tools, model, and full message history — from the point where the fork was initiated.
The practical effect is that a fork can begin sophisticated work immediately without requiring the developer to re-explain the problem space. The fork's own tool calls stay out of the main conversation; only its final result is returned to the parent session. Main context window size is preserved even as the fork does potentially extensive work in parallel.
To start a fork, developers type /fork followed by a directive:
/fork draft unit tests for the parser changes so far
The fork appears in a panel below the main prompt and runs in the background while the developer continues working in the primary session. When the fork completes, its result arrives as a message in the main conversation. Running forks are visible in a panel with controls for opening the transcript, sending follow-up messages, or dismissing the process.
Fork mode also changes how Claude Code handles subagent spawns more broadly. When enabled, Claude automatically uses a fork whenever it would otherwise spawn a general-purpose subagent, and all subagent spawns — fork or named — run in the background by default.
Forked subagents require Claude Code v2.1.117 or later; the /fork command is enabled by default from v2.1.161. The environment variable CLAUDE_CODE_FORK_SUBAGENT can override the default in either direction (1 to force-enable, 0 to disable) across interactive and non-interactive sessions.
Forks can spawn other named subagents but cannot spawn further forks. When a fork is used with isolation: "worktree", its file edits are written to a separate git worktree rather than the main checkout — useful for parallel implementation attempts that should not conflict until the developer decides which to keep.
Context
Claude Code launched in late 2024 as Anthropic's terminal-based AI coding product and has grown into the company's fastest-growing product by adoption. The core product loop involves developers working with Claude in a persistent session, with the AI reading, editing, and running code in the local environment.
One friction point in that model is context management: a long session accumulates history, and delegating a side task (running tests, drafting docs, exploring an alternative approach) to a standard subagent requires composing a delegation message that captures enough context for the subagent to be useful. Forks remove that friction for tasks that genuinely need the full session history.
The feature builds on Claude Code's prompt cache integration. Because a fork's system prompt and tool definitions are identical to the parent session's, its first request reuses the parent's cached context — making forking cheaper than spawning a fresh subagent for tasks that need the same background.
Why it matters
The /fork command addresses one of the more common complaints in long AI coding sessions: losing the model's grasp of what you've already done when you want to try something different. With a fork, the developer can hand off a parallel task — "try refactoring this with a class instead of closures" — without interrupting the main session or reconstructing context.
For multi-track development workflows, the combination of background execution, a visible panel, and cross-fork isolation via git worktrees makes Claude Code behave more like a local parallel agent runtime than a single chatbot-style assistant. Developers can have multiple approaches to a problem running simultaneously, each in its own context, and compare results in the main session.
The background-by-default behavior in fork mode also changes the feel of the tool significantly: Claude can initiate a fork to handle a subtask while the developer continues working, rather than blocking on the output. This closes the gap between using Claude Code as a coding assistant and using it as a background worker.
Corroborating sources
- Docs.anthropic
https://docs.anthropic.com/en/docs/claude-code/sub-agents
“A fork is a subagent that inherits the entire conversation so far instead of starting fresh.”