AI Coding Agents
Cache-Safe Subagent Forking: Reuse the Parent Prefix
In Claude Code, an ordinary subagent starts with its own system prompt and tool set, so its first request misses the parent’s conversation cache. A fork can reuse a warm parent entry when it inherits the same tools, system prompt, and history, uses the same model and cache scope, and appends the task after an eligible cached boundary.
As of November 30, 2026, an ordinary Claude Code subagent starts with its own system prompt and tool set, so its first request misses the parent’s conversation cache. A fork can reuse a warm parent entry when it inherits the same tools, system prompt, and history, uses the same model and cache scope, and appends the task after an eligible cached boundary.
Why a subagent’s first request misses the parent’s cache
On the Claude API, the rendered prefix starts with tools, followed by system and messages. A child can inherit most of the parent’s history and still miss the parent’s conversation entry because the tools or system prompt diverge earlier. An earlier breakpoint can still match content before the divergence. OpenAI likewise requires a match through an eligible boundary in the rendered context. Tool names, descriptions, schemas, and order can all affect that match.
The Claude Code documentation states the consequence directly: a subagent “starts its own conversation with its own system prompt and tool set, separate from the parent’s,” so “its first request doesn’t read the parent’s cache, because the two prefixes differ,” and it warms a cache of its own across its turns. Spawning that subagent is safe for the parent: the docs list spawning a subagent among the actions that keep the cache, because from the parent’s side the subagent’s call and result simply append to the conversation. The cold-start cost lands entirely on the child.
Claude Code issue #98513, filed September 30, 2026 and open as of November 30, 2026, reports a system message after the first user prompt containing the environment, deferred-tool names, agent and skill listings, and the date. The reporter saw the same ordering on subagent spawns. In separate fresh-session trials with distinct first prompts and project memory moved into the top-level system prompt, the reporter attributed roughly 16,000 remaining cache-write tokens per session to that post-prompt message.
What the issue trackers show about forking
Two open reports in the openai/codex repository describe how forks can lose the parent cache:
- Issue #59977, filed November 6, 2026 and open as of November 30, 2026. Every fork the reporter tested included 13 additional tool definitions, ten
codex_apptools and three Pages connector tools. The reporter saw the rest of the request match up to the fork point. In that setup, the provider was a custom Responses-compatible endpoint serving Claude models, and the reporter’s logging proxy translated the tool list one-for-one and could not add tools. The reporter attributed the fork’s cache rewrite to the added definitions. - Issue #24704, filed May 27, 2026 and open as of November 30, 2026. The reporter observed mostly uncached input on some
fork_context=trueruns with Codex CLI andgpt-5.5. They suspected the child’s thread-derivedprompt_cache_keychanged routing for the inherited prefix.
How to inherit the prefix and append the task
Claude Code documents that a fork inherits the parent’s system prompt, tools, and conversation history exactly. Session copies made with /fork append their isolation instruction at the end of the copied conversation. Both preserve the content required to read the original entry while it stays warm.
Generalizing that to your own agent orchestration, the recipe has three parts:
- Same tools. Preserve the rendered tool definitions and their order. Adding or reordering a tool within the rendered prefix can prevent reuse from that point onward.
- Same system content. As of November 30, 2026, the Claude API supports appending a system instruction in
messageson Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5, and Haiku 5.5. Set the appended message’sroletosystemand leave the top-levelsystemfield unchanged. On Sonnet 5, put the child task in an appended user message to preserve the system prefix. - Task as a message. Put the child’s task, isolation note, and per-spawn details at the end of the inherited history. On the Claude API, place a
cache_controlbreakpoint on the last block whose prefix stays identical across the requests that should share it. The API allows up to four explicit breakpoints.
On OpenAI models before GPT-5.6, keep prompt_cache_key stable across related requests to help route them to the same cache. The request still has to reach a machine holding a live matching entry. On GPT-5.6 and later, OpenAI handles cache routing automatically, and separate keys are available for separate cache accounting. See the prompt_cache_key guide.
Test the boundary on the first child request
Start with a controlled pair on the Claude API. Send the parent request with an explicit breakpoint and record the cache-write count. Wait until its response starts before sending the child request. Keep the same model, speed setting, and workspace, and retain the parent breakpoint in the child. Append the child task after the breakpoint. Compare the child’s read count with the parent’s write count for that prefix. If the parent wrote zero tokens, check the model’s minimum cacheable prefix length and the breakpoint before changing how the fork is built.
If reads drop only when you switch from the test child to the production fork, compare the rendered requests starting at the tools. Check schemas and list order before looking at system text and inherited messages. If those match, look at the child’s lookup boundary. A breakpoint at the end of the child’s appended context searches backward through at most 20 positions on the Claude API, including its own position. The fork may preserve every inherited block and still place the parent’s write outside that window. Retaining a marker on the parent boundary gives the child a lookup there.
For an OpenAI Responses fork on GPT-5.6 or later in explicit-only mode, keep the parent’s breakpoint at the same boundary in the child. A prior write at an implicit message ending can be reused in explicit-only mode only if the child marks that same endpoint at an eligible boundary.
How Claude Code sets a fork’s cache lifetime
Claude Code selects a TTL per request. It puts the main conversation in one bucket and subagents, forks, workflows, in-process teammates, compaction, and session titles in another. Subagents and forks default to five minutes across billing modes. Within included subscription usage, the main conversation and a small set of server-controlled helper requests default to one hour.
As of November 30, 2026, the bucket setting and environment variable accept 5m or 1h on Claude Code v2.1.242 and later. The per-subagent frontmatter field requires v2.1.248 and applies only when a higher-priority control has yet to set the TTL.
| Scope | Setting | Environment variable |
|---|---|---|
| Everything else (subagents, forks, workflows) | subagentPromptCacheTtl | CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL |
| Per-subagent setting | cacheTtl in the subagent’s experimental frontmatter. Claude Code ignores 1h there while a subscription is drawing on usage credits. |
Two related behaviors worth knowing: when Claude resumes a subagent, the resumed run’s first request can read the cache the original run warmed, and in a workflow fan-out of same-prefix agents Claude Code holds all but the first for up to five seconds by default so their first requests can read the prefix the first agent cached.
The cost of inheriting a 60,000-token prefix on Sonnet 5.5
Assume a parent conversation on claude-sonnet-5-5 has already written a 60,000-token prefix that is still warm, and a child spawns from it. Committed rates for this model are $2 per 1M input tokens, $2.5 per 1M for a five-minute cache write, and $0.1 per 1M for a cache read (the one-hour write is documented at 2x base input, so $4 per 1M derived).
| Child shape | Estimated API input cost for the 60,000-token prefix | Formula |
|---|---|---|
| Fork that inherits the prefix exactly | $0.006 | 60,000 x $0.1 / 1M (cache read) |
| Subagent with its own system prompt and tools, caching applied | $0.15 | 60,000 x $2.5 / 1M (cache write) |
| Subagent with its own system prompt and tools, no caching | $0.12 | 60,000 x $2 / 1M (uncached input) |
The estimated $0.006 read is 4% of the $0.15 five-minute write and 5% of the $0.12 uncached cost. These are API list-price estimates for the prefix alone. Later turns can read eligible warm entries, write newly marked content, or process unmarked input at the ordinary rate.
When a smaller, fresh prompt beats a cached prefix
For a self-contained task, compare a compact prompt with both a warm fork and a cold fork. At committed rates, a 4,000-token prompt costs an estimated $0.008 uncached or $0.010 as a five-minute write (4,000 × $2 or $2.50 ÷ 1,000,000), versus $0.006 to read the warm 60,000-token prefix. A fresh uncached prompt ties that warm read at 3,000 tokens ($0.006 × 1,000,000 ÷ $2). If no later request will reuse the entry, the five-minute write costs 25% more than processing the same tokens as ordinary input.
Consider a one-hour write when the same prefix will be reused after five minutes and within an hour. Check the TTL that originally wrote the parent entry. On the Claude API, a read of a five-minute entry refreshes it for five minutes even if the child requests 1h.
Measure the child’s task input separately when comparing designs. A warm fork still has to process the new task and any attachments. If the compact prompt and the fork carry different amounts of new input, add each one’s suffix cost before choosing between them.
What to do next
- Inherit the parent history for tasks that build on it. Send a small self-contained prompt for independent tasks.
- If you fork, compare the model, cache scope, prompt-affecting settings, rendered tools, system content, inherited messages, and breakpoint placement before testing the child’s first request.
- On the child’s first Claude API response, compare
usage.cache_read_input_tokenswith the size of the intended shared prefix and checkusage.cache_creation_input_tokensfor fresh writes. Claude Code’s/usagecache line covers the main conversation only. - Check the effective TTL and its precedence before changing
subagentPromptCacheTtlorexperimental.cacheTtl. - Related reading: prompt caching basics for the shared vocabulary, Claude Code cache settings for the full TTL precedence list, MCP tool order and the prompt cache for the tool-list failure mode that bites forks, and context compaction cost for the other request in the everything-else bucket. Current per-model rates are in the provider pricing index.
Sources
- How Claude Code uses prompt caching (Anthropic, accessed 2026-11-30)
- Prompt caching (Anthropic, accessed 2026-11-30)
- Prompt caching (OpenAI, accessed 2026-11-30)
- Issue #59977: Forked threads get 13 extra tools the parent does not have (openai/codex on GitHub, accessed 2026-11-30)
- Issue #24704: Forked subagents lose prompt-cache lineage for inherited parent context (openai/codex on GitHub, accessed 2026-11-30)
- Issue #98513: Session-invariant context is sent after the first user prompt (anthropics/claude-code on GitHub, accessed 2026-11-30)
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Cache-Safe Subagent Forking: Reuse the Parent Prefix. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/cache-safe-subagent-forking/