A fork in Claude Code is a subagent that starts with your entire conversation so far: the same message history, system prompt, tools and model as your main session. You start one with /subtask followed by a task, it runs in the background, and only its final result comes back to your conversation. Since v2.1.232, fork mode is on by default in interactive sessions, so Claude can also spawn forks on its own.
Claude Code forks: subagents that inherit your conversation
Thomas Poulain · · Updated
How is a fork different from a regular subagent?
If subagents are new to you, read how subagents work in Claude Code first. This post only covers what forks add.
A regular subagent starts with an empty context window. It usually gets your CLAUDE.md files and a delegation message where Claude sums up the task, but it never sees your history or the files Claude already read. When the task depends on an hour of back-and-forth, that summary loses details and you end up explaining things twice. A fork starts where you are. Here is how the official docs compare the two:
| Fork | Regular subagent | |
|---|---|---|
| Context | Full conversation history | Fresh context with the prompt it’s given |
| System prompt and tools | Same as the main session | From the agent’s definition file |
| Model | Same as the main session | From the agent’s model field |
| Prompt cache | Shared with the main session | Separate cache |
The cache row is the one I watch. A fork’s system prompt and tool definitions match the parent’s, so its first request reuses your session’s prompt cache. Per the docs, that makes a fork cheaper than a fresh subagent for tasks that need the same context. And since only its final result comes back, your context window doesn’t fill up.
How do I start a fork with /subtask?
/subtask draft unit tests for the parser changes so far
Claude Code names the fork from the first words of the task. It shows up in a panel below your prompt and runs in the background while you keep working. When it’s done, the result lands as a message in your conversation. In that panel, Enter opens the fork’s transcript so you can send it a follow-up, and x stops it.
Mind the version numbers. /subtask needs v2.1.212 or later and works whether fork mode is on or off. From v2.1.161 through v2.1.211, the same command was called /fork. Since v2.1.212, /fork copies your whole session into a new background session, which is a different feature. The exception: if you’ve turned agent view off, /subtask isn’t available and /fork starts the fork instead.
You don’t have to type the command at all. With fork mode on, Claude can start a fork itself by requesting the fork subagent type from the Agent tool.
When should I fork, and when shouldn’t I?
I fork when the side task builds on what we just did, like writing tests for the code we just changed or documenting a decision we made in the conversation. Forks are also the right fit for trying several approaches in parallel from the same starting point.
I stick with a regular subagent when I want a fresh pair of eyes, since a fork carries the same assumptions as the main session. Same thing when the job needs a different model or a restricted tool set, like a read-only reviewer: a fork keeps the main session’s model and tools.
Can a fork work in its own git worktree?
Yes, when Claude spawns it through the Agent tool. Claude can pass isolation: "worktree", and the fork writes its edits to a separate git worktree instead of your checkout. The docs don’t describe that option for /subtask, so when a fork might touch files I’m editing at the same time, I ask Claude to start it:
Fork a subagent in an isolated worktree to try the migration to the new API
What are the limits of forks?
- A fork can’t spawn another fork.
- Since v2.1.302, fork mode is also on by default in headless mode (
claude -p) and in the Agent SDK.CLAUDE_CODE_FORK_SUBAGENT=0turns it off everywhere. - With fork mode on, the subagents Claude spawns run in the background, forks or not, apart from a few exceptions, and Claude can no longer ask for the foreground.
- Since v2.1.285, a fork keeps its parent session’s permission mode and can’t exit plan mode.
To keep fork mode on but stop Claude from spawning forks, deny Agent(fork) in your settings.json:
{
"permissions": {
"deny": ["Agent(fork)"]
}
}
Can I message another session with @?
Since v2.1.232, you can also type @ followed by the name of another Claude Code session running on your machine. Claude then sends it a message with the SendMessage tool:
Let @api-worker know the schema migration finished
The other session only receives a piece of text Claude writes, never your history or your files. It comes in handy when two sessions work on the same repo in separate worktrees.
Forks are for side tasks inside one session. To run several sessions in parallel, each in its own worktree, see module 14 of the course, tmux and agent teams. Day-to-day context and session management is in module 7, Optimization and pro workflow.