Last updated on

Shared Context Belongs at the Top


I was reviewing a large code change and wanted more than one opinion on it. Correctness, security, performance, and someone to argue against the change entirely. One agent juggling all of those at once tends to give each of them a shallow pass, so I gave every angle its own agent, all reading the same diff.

It felt like the right design. Then I looked at the bill: ten agents cost nine times as much as one.

Most of that money went into processing the same document ten times. When I changed nothing but the order of the prompts, the same ten agents cost 2.5 times one agent. The fix turned out to be less about multi-agent systems and more about something every agent system has: shared context, and how easily it slips out of the cache as the system grows.

How the cache decides

Prompt caching saves the processed start of a prompt. The next request can reuse it up to the first byte that differs, as long as an earlier request cached that part. Everything after that point is processed again at full price.

On Anthropic’s models, writing to the cache costs 1.25x the normal input price, and reading from it costs a tenth, or 5% on Sonnet 5.5 and Opus 5.5 (Anthropic). OpenAI and Gemini follow the same prefix idea with their own rules (OpenAI, Gemini).

A timestamp at the top causes a cache miss for everything after it.

It’s tempting to think of this as “cache the system prompt.” But the cache has no idea what a system prompt is. It sees one sequence of bytes, in order. A system prompt that starts with a timestamp shares nothing. A long document in the first user message can be the most valuable thing you cache. What matters is which part many requests have in common, and whether that part sits at the top.

How shared context drifts

Nobody sets out to break their cache. Context builders grow one reasonable addition at a time, and some of those additions land near the top. The answers stay just as good, so nothing looks wrong. Only cost and latency creep up.

Teams running agents at scale have written about exactly this:

  • A timestamp at the top of the system prompt. Manus calls it a common mistake: handy for telling the model the time, fatal for the hit rate (Manus).
  • JSON with unstable key order. Same content, different bytes. Manus keeps its context append-only and its serialization deterministic for this reason.
  • Tools in a different order each turn. Codex fixed its cache hit rate by sorting its MCP tools (Codex).
  • Tools added or removed mid-session. Tools sit at the very front, so every change invalidates everything after them (Claude Code). Manus masks tools instead of removing them.
  • Settings you can’t see in the text. On Anthropic’s API, the effort and thinking settings are part of the prompt, so changing them breaks the cached messages.
  • Automatic caching on the wrong block. It places the breakpoint on the last block, which is usually the per-request part. Set it explicitly at the end of the shared part instead.

Go look at your context builder

This is the cheap part. Write down every block your system sends, in order, and next to each one note how often it changes: almost never, once per session, or every request. Then sort it, slowest-changing first, and put the cache breakpoint right after the last shared block. Keep the code that builds the shared part in one place, so the next person who adds context knows where it belongs.

Then check the numbers. Every response tells you how many tokens it read from the cache (cache_read_input_tokens). If a request that should share reads nothing, something above it changed. Anthropic’s cache diagnostics will tell you exactly where.

Where multi-agent systems gain the most

With one agent, a misplaced block costs you once per request. With several agents reading the same material, it costs you once per agent.

Frameworks often build prompts the “natural” way: task first, material after. Claude Code subagents, for example, get their task and then fetch what they need with a tool. When I gave three subagents the same 18 KB file, each one wrote it to the cache separately, and none of them ever read another’s copy.

Three subagents each write the same shared context to the cache.

The fix is to attach the shared material in code, ahead of each agent’s task. With five agents on a 56,000-token diff, that one change took the cost from $0.73 to $0.23.

There’s one catch. A cache entry only becomes readable once the first request starts answering, so if every agent starts at the same moment, they all miss. Let one go first, or send a max_tokens: 0 request to warm the cache. Anthropic documents that option; I haven’t tested it yet.

Ten agents, one document Cost vs one agent
One agent, all ten questions $0.13 1x
Ten agents, no caching $1.19 9x
Shared first, one agent first $0.33 2.5x
Shared first, all at once $1.47 11x

Many opinions, without many bills

This is what I care about most. Once the shared material is cached, every extra agent pays mostly for its own question and its own answer. That makes the original idea affordable: several focused opinions on the same work, each reading the full material instead of a summary someone else wrote for it.

It isn’t free. Output isn’t cached, and the agents need the same model, tools, system prompt and effort setting to share an entry. I also haven’t measured whether ten focused opinions beat one broad one. But at 2.5x instead of 9x, it’s cheap enough to find out.

When agents run long conversations and mostly re-read their own history, the shared part matters less. There, the number of turns drives the bill more than the order.

How I tested

These are local, controlled runs, one per setup, using Claude Sonnet 5.5 via OpenRouter (pinned to Anthropic) on October 5, 2026, at medium effort. The single agent ran without caching. Cache reads cost $0.20 per million tokens at the time and $0.10 now, so the cached runs would be cheaper today. I compared cost only, not answer quality.

Sources