Prompt caching for coding agents: cache reads, cache writes and what breaks them
A coding agent resends the whole session on every turn, so providers cache the start of the prompt. The first time a prefix is sent it is written to the cache; after that it is read from the cache at a lower price. Caching makes agents affordable, but it does not make repeated text free: in our measured sessions most tokens were cache reads. The way to cut them is a smaller, stable prefix.
Updated 2026-11-27
How prompt caching works#
- Cache write: the first request with a new prefix stores it. Writing costs a little more than plain input.
- Cache read: later requests that start with the same prefix read it back for a fraction of the input price.
- Expiry: an unused cache entry expires after a few minutes, so a session that sits idle pays the write again.
The cache matches from the first token. If anything changes near the top, everything after it is written again.
Where a coding agent’s tokens actually go#
| Kind | Before MinniMemoryMCP | After |
|---|---|---|
| Fresh input | 490 | 256 |
| Cache writes | 134,041 | 96,034 |
| Cache reads | 4,133,084 | 2,152,150 |
| Output | 46,520 | 28,142 |
| Total | 4,314,135 | 2,276,582 |
All tokens for the whole run: 3 sessions a side, 30 tasks in Claude Code 2.1.325 on Claude Sonnet 5.5, measured 15 November 2026. Cache reads were 96% of all tokens. Shrinking the prefix shrank them most.
What breaks the cache#
- Changing text near the top: a date, a counter or a session id in the system prompt.
- Reordered tools: adding, removing or reordering MCP servers mid-session.
- Editing memory mid-session: a changed
CLAUDE.mdorAGENTS.mdis a new prefix. - Long pauses: coming back after the cache has expired.
- Switching models: each model has its own cache.
How to cut cache tokens#
- Make the prefix smaller. Every token in it is read again on every turn. Memory and instructions are the big parts.
- Keep it stable. Stable text first, changing text last.
- Start fresh for a new task. A long history is part of the prefix too.
MinniMemoryMCP shrinks the memory part of the prefix for Claude Code and Codex. MinniCode keeps its own prefix small: a warm MinniCode session wrote 5,286 tokens to the cache against 8,273 for Claude Code on the same tasks, 36% less. More on the bill in Why Claude Code sessions get expensive.