# Cache-stable prefix

> Put only byte-stable content before the prompt-cache marker - system prompt and tool schemas first, timestamps after - or every call pays full input price.

URL: https://bartlomiejkrupa.dev/notes/cache-stable-prefix/
Category: rule | Updated: 2026-07-20
Summary: Put only byte-stable content before the prompt-cache marker - system prompt and tool schemas first, timestamps after - or every call pays full input price.

A prompt cache is a prefix match on exact bytes. Anything that changes above the marker - timestamps, request IDs, reordered tools, dynamic tool results - invalidates every cached token after it. You still get an answer; you pay full price plus the write premium. Pair with [output tokens never cache](/notes/output-tokens-never-cache) when the temptation is to shrink the bill by compressing history in place.

## Rule

1. Freeze system prompt + tool schemas **before** the cache marker.
2. Put dynamic fields **after** it.
3. Never rewrite text that already sits inside a cached block mid-session.
4. Verify with `usage.cache_read_input_tokens` on call 2+ of an identical prefix - zero means the prefix is changing or shorter than the model minimum.

Playbook with copy-paste and the measured failure modes: [Don't break the prompt cache](/articles/dont-break-the-prompt-cache). Pair with [Trim output, not the cache](/articles/trim-output-not-the-cache) when the temptation is to compress history in place.

Sources:
- Prompt caching: https://platform.claude.com/docs/en/build-with-claude/prompt-caching
