---
title: ""
canonical: "https://studiomeyer.academy/en/playbooks/prompt-caching-meistern"
language: en
publisher: "StudioMeyer Academy, https://studiomeyer.academy (llms.txt: https://studiomeyer.academy/llms.txt)"
---

[← Alle Playbooks](https://studiomeyer.academy/playbooks)

Playbook· setup

# Mastering prompt caching, from cache miss to an 80 percent hit rate in 10 steps

How to set cache\_control properly, build stable prefixes and read cache diagnostics. Concrete patterns for the Claude Code daily driver, your own scripts and MCP servers.

Cache hits are the cheapest token you will ever pay for. A cache read costs roughly 10 percent of the normal price, a cache write 25 percent more. If you keep a session open for two hours and the cache never fires, you burn ten times as much for the same system prompt. That is the most common hidden cost driver in Claude Code. In this playbook I go through how I push caching to an 80 percent hit rate in the daily driver, in my own scripts and in MCP servers. Little theory, a lot you can copy straight away.

## 1\. Understand in one sentence what caching does

You mark a spot in your prompt with `cache_control`. Anthropic stores everything up to that spot (tools, system, messages, in that order) for 5 minutes. On the next request with the same prefix you get that chunk back as a cache read instead of having it processed again. That is all there is to it.

What a lot of people miss is that the cache breakpoint expires after 5 minutes but gets extended on every hit. As long as you fire again within 5 minutes, the cache stays warm and keeps costing nothing. Long breaks can be covered with the 1 hour cache, more on that shortly.

## 2\. Measure the cache, otherwise you are optimizing blind

Every Anthropic API response returns four token counters. `input_tokens` is everything that was processed fresh. `cache_creation_input_tokens` is what got written into the cache this time. `cache_read_input_tokens` is what was pulled out of the cache. `output_tokens` is the answer.

In Claude Code, `/usage` shows this aggregated per session. What you have to keep an eye on is the ratio of cache\_read to input\_tokens. If that is above 4 to 1, you are running well. If input\_tokens is in the thousands every time and cache\_read stays tiny, you have a cache buster sitting somewhere, usually a dynamic date or a counter variable that leaked into the system prompt.

For your own scripts, log those four numbers per request. A small table in Postgres or a JSONL file is enough. Without that measurement you are optimizing on guesses.

## 3\. Start with automatic caching, not with explicit breakpoints

Anthropic recommends this at the top of the docs and so do I. Set `cache_control` exactly once on the last cacheable block (so before the user message that changes every time). Example in Python,

```python
response = client.messages.create(
    model="claude-sonnet-4-5",
    system=[
        {
            "type": "text",
            "text": SYSTEM_PROMPT,
            "cache_control": {"type": "ephemeral"}
        }
    ],
    messages=[{"role": "user", "content": user_message}]
)
```

That covers 80 percent of cases. Only once you have clear layers that change at different rates (tools rarely, system moderately, conversation often) do you move to explicit breakpoints.

## 4\. Apply the stable prefix trick, everything stable goes to the front

The cache only works if the prefix is byte for byte identical. A single changed character at the start invalidates everything behind it. So sort your prompt like this,

1. Tools first, they almost never change
2. Then the big static system prompt
3. Then project specific context (CLAUDE.md, loaded files)
4. And only then the changing user message at the end

Classic mistake, a timestamp or a session ID in the system prompt. That kills every cache. If you need something like that, put it at the end in the user message, not in the system block.

## 5\. Use four breakpoints cleverly, not all at once

You have up to four `cache_control` markers per request. The sensible split,

- Breakpoint 1 after the tools
- Breakpoint 2 after the static system prompt
- Breakpoint 3 after the loaded project context
- Breakpoint 4 after the last few conversation turns (rolling)

Every breakpoint costs a one-off cache write premium (25 percent extra). If you only have one layer that is genuinely stable, you do not need four markers. Rule of thumb, one good breakpoint beats four half-baked ones.

## 6\. CLAUDE.md is your biggest cache candidate

Claude Code loads CLAUDE.md into the context at the start of every session. If you keep constant instructions there (coding style, test rules, forbidden commands), that gets sent along with every single request. A cache hit reduces the cost dramatically.

What you have to avoid is dynamic data in CLAUDE.md. No `Today is 2026-05-26`, no status counter, no "the last session was ...". That can be solved elegantly with a sub-skill, pull the dynamic date in as a slash command or tool output instead of writing it statically into the file.

## 7\. Keep tool definitions lean, they sit in the cache prefix

MCP tool definitions land in `tools` and therefore right at the front. An 80 tool MCP server pumps 15,000 tokens into every single request, to be cached again each time. That is fine as long as you need those tools permanently.

But if you only need them rarely, disable the server in `.mcp.json` and switch it on situationally. Or use the pickMcp pattern when you are building your own agent, so each agent only gets the tools it actually needs. The playbook [tool-sprawl-vermeiden](https://studiomeyer.academy/playbooks/tool-sprawl-vermeiden) goes into that more deeply.

## 8\. The 1 hour cache for long breaks, but deliberately

On top of the 5 minute default, Anthropic offers a 1 hour cache. You set it with,

```json
{"type": "ephemeral", "ttl": "1h"}
```

It costs more to write and pays off when you have sessions where you are away for a while (meeting, lunch). My pattern, the 1h cache only for the truly stable layer (tools plus global system prompt). The 5 minute default for everything else. If I know I will be back at the laptop in 90 minutes, I save myself the whole system prompt rebuild.

If you start every session fresh and are always in the flow, leave the 1h cache out. The 25 percent premium on the write does not pay off when the cache is being kept permanently warm anyway.

## 9\. Use cache diagnostics when the hit fails to appear

Anthropic has cache diagnostics in beta. You send two consecutive requests and the API tells you at which point the prefix diverged. Worth gold when you do not understand why the cache is not firing.

You switch it on with the beta header `anthropic-beta: prompt-caching-diagnostics-2025-XX-XX` (look up the exact version number in the current docs, it changes). In the response you then get an extra field with the divergence point.

If diagnostics shows that the divergence already sits at token 50, you very likely have a dynamic header or a timestamp in the prefix. If it only diverges at token 8000, that is probably where your last tool output lives.

## 10\. My daily driver pattern, one concrete routine

This is what my Claude Code session looks like, optimized for caching.

At the start I hit `/usage` to see where I stand. CLAUDE.md is static (no date, no counters). My MCP setup has exactly the five servers I need for this session, the rest is disabled.

The first request runs, `cache_creation_input_tokens` is high (around 20,000), `cache_read` is zero. Normal, the first request writes the cache. Second request, `cache_read` jumps to 20,000, `input_tokens` is only the few hundred of new user input. That is the point where I know everything is running.

After a 90 minute break comes my cache reset. Instead of processing 20,000 tokens again I use `/resume` and a 1h breakpoint on the tools layer. The cache stays warm and getting back in costs about half.

Change of topic, I hit `/clear` and go into a fresh session. The cache gets discarded, but that saves more over the next hour than the one-off rebuild costs. A polluted cache full of irrelevant context is more expensive than a fresh one.

## What comes next

Once caching is in place, the next levers are in [claude-code-cost-controls-für-daily-driver](https://studiomeyer.academy/playbooks/claude-code-cost-controls-fuer-daily-driver) (model routing, `/compact`, spend limits) and [context-window-managen-claude-code](https://studiomeyer.academy/playbooks/context-window-managen-claude-code). If you build your own scripts, pour the cache logging pattern into a Postgres table and evaluate after two weeks which prefixes really deliver hits. That is often where the last 20 percent of optimization sits.

## Sources

- platform.claude.com/docs/en/build-with-claude/prompt-caching (official, retrieved 2026-05-26)
- platform.claude.com/docs/de/build-with-claude/prompt-caching (DE mirror, retrieved 2026-05-26)
- code.claude.com/docs/en/costs (official, for the /usage mechanics, retrieved 2026-04-27)

[← Debugging MCP when nothing wor](https://studiomeyer.academy/playbooks/mcp-debuggen-wenn-nichts-geht) [Repair memory drift, when your →](https://studiomeyer.academy/playbooks/memory-drift-reparieren)

Alle Playbooks

[01. From ChatGPT to Claude, guide in 10 steps](https://studiomeyer.academy/playbooks/von-chatgpt-zu-claude) [02. From ChatGPT to Codex, guide in 10 steps](https://studiomeyer.academy/playbooks/von-chatgpt-zu-codex) [03. Your first MCP server in 90 minutes](https://studiomeyer.academy/playbooks/erster-mcp-server-in-90-minuten) [04. Using memory portably, same memory in Claude, Codex and Cursor](https://studiomeyer.academy/playbooks/memory-portabel-nutzen) [05. DACH legal. EU AI Act and GDPR for AI operators](https://studiomeyer.academy/playbooks/dach-legal-eu-ai-act-und-dsgvo) [06. Your first sub-agent in 30 minutes](https://studiomeyer.academy/playbooks/erster-sub-agent-in-30-min) [07. Publishing an MCP server step by step](https://studiomeyer.academy/playbooks/mcp-server-publishen) [08. Hooks against hallucinations](https://studiomeyer.academy/playbooks/hooks-gegen-halluzinationen) [09. Git for AI, 30-minute quickstart](https://studiomeyer.academy/playbooks/git-fuer-ki-quickstart) [10. Scheduled agents with Claude Code routines](https://studiomeyer.academy/playbooks/scheduled-agents-mit-routines) [11. Avoiding tool sprawl, from 530 to 30 MCP tools per session](https://studiomeyer.academy/playbooks/tool-sprawl-vermeiden) [12. Claude Code update strategy, without your workflow suddenly breaking](https://studiomeyer.academy/playbooks/claude-code-update-strategie) [12. Structuring your subagent team, the six roles you need in a daily driver](https://studiomeyer.academy/playbooks/subagent-team-strukturieren) [13. Claude Code cost controls for daily drivers, staying under 30 dollars a day in 10 steps](https://studiomeyer.academy/playbooks/claude-code-cost-controls-fuer-daily-driver) [14. Your own slash commands for Claude Code, productive in 30 minutes](https://studiomeyer.academy/playbooks/eigene-slash-commands-fuer-claude-code) [15. Claude Code headless in CI/CD, a setup that runs tomorrow](https://studiomeyer.academy/playbooks/claude-code-headless-in-ci-cd) [16. Agent eval in 60 minutes, how to find out if your agent is any good](https://studiomeyer.academy/playbooks/agent-eval-in-60-minuten) [17. Plan Mode in Claude Code, the invisible seatbelt, when you need it and how to keep it on](https://studiomeyer.academy/playbooks/plan-mode-richtig-nutzen) [18. Debugging MCP when nothing works, the 10 checks that solve 90 percent of cases](https://studiomeyer.academy/playbooks/mcp-debuggen-wenn-nichts-geht) [18. Mastering prompt caching, from cache miss to an 80 percent hit rate in 10 steps](https://studiomeyer.academy/playbooks/prompt-caching-meistern) [19. Repair memory drift, when your agent's memory starts contradicting itself](https://studiomeyer.academy/playbooks/memory-drift-reparieren) [20. MCP STDIO security, what the OX Security story means for you](https://studiomeyer.academy/playbooks/mcp-stdio-sicherheit) [21. Opus 4.7 migration, what changed for API builders](https://studiomeyer.academy/playbooks/opus-4-7-migration) [22. Your first Skill in 30 minutes, when slash commands aren't enough](https://studiomeyer.academy/playbooks/erste-eigene-skill-in-30-min) [23. Managing the context window in long Claude Code sessions](https://studiomeyer.academy/playbooks/context-window-managen-claude-code) [24. Advisor Tool, Opus as advisor and Sonnet as executor in one API call](https://studiomeyer.academy/playbooks/advisor-tool-opus-als-berater-sonnet-als-executor) [25. Secure your MCP server with OAuth 2.1 in 60 minutes](https://studiomeyer.academy/playbooks/mcp-server-auth-mit-oauth-2-1) [26. Distributing plugin bundles via URL, --plugin-url in 30 minutes](https://studiomeyer.academy/playbooks/plugin-bundle-via-url-distribution) [27. Claude Code in a Team, how to keep CLAUDE.md alive without turning it into a trash bin](https://studiomeyer.academy/playbooks/claude-code-im-team-claude-md-gemeinsam-pflegen) [27. Loading third-party Claude Code plugins from ZIP and URL, safely in 20 minutes](https://studiomeyer.academy/playbooks/claude-code-plugins-aus-zip-und-url-laden) [28. Confused deputy audit for Claude Code, done in 25 minutes](https://studiomeyer.academy/playbooks/confused-deputy-audit-fuer-claude-code) [28. Your first Claude Code plugin in 60 minutes, from empty folder to installable bundle](https://studiomeyer.academy/playbooks/dein-erstes-claude-code-plugin) [29. Pull request reviews with Claude Code, 10 steps for a PR workflow nobody blocks anymore](https://studiomeyer.academy/playbooks/pull-request-reviews-mit-claude-code) [30. Claude Projects for non-coders, a productive workspace in 30 minutes](https://studiomeyer.academy/playbooks/claude-projects-fuer-nicht-coder) [31. Build a prompt library, reuse your favourite prompts without copy-paste](https://studiomeyer.academy/playbooks/prompt-bibliothek-aufbauen) [32. Output Styles for Claude Code, your own tone in 20 minutes](https://studiomeyer.academy/playbooks/output-styles-fuer-claude-code) [33. Statusline for Claude Code, context at a glance in 15 minutes](https://studiomeyer.academy/playbooks/statusline-fuer-claude-code) [34. Claude Code checkpoints and /rewind: your safety net for risky edits](https://studiomeyer.academy/playbooks/claude-code-checkpoints-und-rewind) [34. Keeping discovery files consistent so AI crawlers do not quote old nonsense bios](https://studiomeyer.academy/playbooks/discovery-files-konsistent-halten) [34. Debugging hooks when nothing fires](https://studiomeyer.academy/playbooks/hooks-debuggen-wenn-nichts-feuert) [34. Parallel Claude Code sessions with git worktrees, two branches at once without conflict](https://studiomeyer.academy/playbooks/parallele-claude-sessions-mit-worktrees) [34. Skill does not trigger, what to check in 10 steps before you type /command again](https://studiomeyer.academy/playbooks/skill-trigger-debugging) [34. Sub-agent or skill or MCP tool, which one do you pick when](https://studiomeyer.academy/playbooks/sub-agent-oder-skill-oder-mcp-tool) [35. Running parallel Claude Code sessions with git worktrees](https://studiomeyer.academy/playbooks/claude-code-mit-git-worktrees) [35. Memory backup before an update, so you do not cry over a schema migration bug](https://studiomeyer.academy/playbooks/memory-backup-vor-update) [36. AGENTS.md alongside CLAUDE.md, one repo context for several AI tools](https://studiomeyer.academy/playbooks/agents-md-neben-claude-md) [47. Generative Engine Optimization for small sites, so Perplexity and ChatGPT-Search cite you](https://studiomeyer.academy/playbooks/geo-fuer-kleine-sites) [50. Opus 4.8 migration, the first Opus update with no breaking changes](https://studiomeyer.academy/playbooks/opus-4-8-migration) [51. Background sessions with Claude agents: run long tasks without blocking your terminal](https://studiomeyer.academy/playbooks/background-sessions-mit-claude-agents) [52. Set up the Claude Code bash sandbox: isolate commands instead of blindly allowing them](https://studiomeyer.academy/playbooks/claude-code-bash-sandbox-einrichten) [53. From script to your own agent: the Claude Agent SDK in 90 minutes](https://studiomeyer.academy/playbooks/claude-agent-sdk-erster-eigener-agent) [54. Build an MCP App: interactive UI in your MCP tool instead of a wall of text](https://studiomeyer.academy/playbooks/mcp-app-interaktive-ui-bauen) [55. The expensive-model myth: when the top AI model is really worth it](https://studiomeyer.academy/playbooks/mythos-klasse-wann-lohnt-sich-das) [56. Setting up fallback models so Claude Code doesn't stall on overload](https://studiomeyer.academy/playbooks/claude-code-fallback-modelle) [57. Dynamic workflows in Claude Code, your first orchestrated multi-agent script](https://studiomeyer.academy/playbooks/dynamic-workflows-in-claude-code) [58. Security-guidance plugin for Claude Code, automatic security review while you build](https://studiomeyer.academy/playbooks/claude-code-security-guidance-plugin) [59. Claude Code acting up after a config change, how to find the cause](https://studiomeyer.academy/playbooks/claude-code-safe-mode-diagnose) [60. MCP is stateless: what the 2026-07-28 spec changes and what you need to do now](https://studiomeyer.academy/playbooks/mcp-spec-2026-07-was-aendert-sich) [61. Your first real n8n flow: automation for people who don't code](https://studiomeyer.academy/playbooks/mein-erster-n8n-flow-fuer-nicht-coder) [62. Agentic payments with x402, what builders need to know about machine-paid APIs](https://studiomeyer.academy/playbooks/agentic-payments-x402) [63. GPT-5.6 or Opus 5, which model for which task](https://studiomeyer.academy/playbooks/gpt-5-oder-opus-4-8-welches-modell) [64. Subagents that spawn subagents, Claude Code's 5-level rule](https://studiomeyer.academy/playbooks/subagents-die-subagents-spawnen) [65. Setting up Claude Code agent teams, multiple sessions working together](https://studiomeyer.academy/playbooks/claude-code-agent-teams-einrichten) [66. Tracking model availability, when a model vanishes overnight](https://studiomeyer.academy/playbooks/modell-verfuegbarkeit-tracken) [67. Data protection when working with AI tools: ten habits that keep you safe](https://studiomeyer.academy/playbooks/datenschutz-mit-ki-tools) [68. Using Auto Mode in Claude Code safely, in 10 steps without suicide commands](https://studiomeyer.academy/playbooks/claude-code-auto-mode-sicher-nutzen) [69. AI for the job hunt: 10 steps through the ATS filter](https://studiomeyer.academy/playbooks/ki-fuer-jobsuche) [70. Build an AI portfolio that lands you a job, in 10 steps](https://studiomeyer.academy/playbooks/ai-portfolio-fuer-den-job) [71. Proving your AI skills credibly in CV and interview](https://studiomeyer.academy/playbooks/ai-skills-belegen-lebenslauf-interview) [72. Effort levels in Claude Code, when low is enough and when you need max](https://studiomeyer.academy/playbooks/effort-level-in-claude-code-einstellen) [73. From Academy skill to your first paid AI gig](https://studiomeyer.academy/playbooks/erster-bezahlter-ki-auftrag) [74. Fact-checking an AI answer: 10 steps against wrong information](https://studiomeyer.academy/playbooks/ki-antwort-faktenchecken) [75. AI images for your brand, from first prompt to finished set](https://studiomeyer.academy/playbooks/ki-bilder-fuer-deine-marke) [76. AI for freelancers, writing quotes and client emails in half the time](https://studiomeyer.academy/playbooks/ki-fuer-selbststaendige-angebote-und-mails) [77. Spotting and correctly labelling AI content](https://studiomeyer.academy/playbooks/ki-inhalte-erkennen-und-kennzeichnen) [78. AI meeting notes that are actually usable](https://studiomeyer.academy/playbooks/ki-notizen-fuer-meetings) [79. Local AI on your own machine, so your data never leaves the house](https://studiomeyer.academy/playbooks/lokale-ki-auf-dem-eigenen-rechner) [80. Understanding the three MCP primitives. Tools, Resources and Prompts](https://studiomeyer.academy/playbooks/mcp-primitives-tools-resources-prompts) [81. Reliable JSON from any AI, so your automation doesn't break](https://studiomeyer.academy/playbooks/verlaessliches-json-aus-ai) [82. What AI tools really cost, and where the hidden bills hide](https://studiomeyer.academy/playbooks/was-kostet-ki-wirklich) [83. Understanding prompt injection, the three traps when your AI assistant reads foreign text](https://studiomeyer.academy/playbooks/prompt-injection-erkennen) [84. Protecting yourself from AI fraud, fake calls, phishing and bogus job offers](https://studiomeyer.academy/playbooks/dich-vor-ki-betrug-schuetzen) [85. Opus 5 migration, when thinking becomes the default](https://studiomeyer.academy/playbooks/opus-5-migration) [86. The AI policy for small teams, on a single page](https://studiomeyer.academy/playbooks/ki-richtlinie-fuer-kleine-teams) [87. Stopping agents that drift off course](https://studiomeyer.academy/playbooks/agenten-die-abdriften-stoppen) [88. Seeing what your agent actually did, tracing in 10 steps with OpenTelemetry](https://studiomeyer.academy/playbooks/agent-tracing-mit-opentelemetry) [89. Having AI summarize long documents without it inventing things](https://studiomeyer.academy/playbooks/lange-dokumente-sicher-zusammenfassen) [90. Vetting third-party MCP servers safely before you install them](https://studiomeyer.academy/playbooks/fremde-mcp-server-sicher-pruefen) [91. AI as a learning coach: teaching yourself a new field for a career change](https://studiomeyer.academy/playbooks/ki-lern-coach-berufswechsel) [92. The AI operator job: what do you actually do?](https://studiomeyer.academy/playbooks/berufsbild-ai-operator) [93. Using AI without losing your own edge](https://studiomeyer.academy/playbooks/ki-nutzen-ohne-selbst-zu-verlernen) [94. Why your screenshot shrinks, and how to control it](https://studiomeyer.academy/playbooks/bilder-und-screenshots-an-die-ki-geben) [95. Framing a deep research brief so the report is actually worth something](https://studiomeyer.academy/playbooks/deep-research-auftrag-formulieren) [96. Analysing numbers and tables with AI without ending up with nonsense](https://studiomeyer.academy/playbooks/zahlen-und-tabellen-mit-ki-auswerten) [97. Reading AI benchmarks without being taken for a ride](https://studiomeyer.academy/playbooks/ki-benchmarks-richtig-lesen) [98. AI as a sparring partner, better decisions instead of polite agreement](https://studiomeyer.academy/playbooks/ki-als-sparringspartner-fuer-entscheidungen) [99. Learning a new skill with AI, the honest way](https://studiomeyer.academy/playbooks/mit-ki-neue-faehigkeit-lernen) [100. Changing your MCP server without breaking your users](https://studiomeyer.academy/playbooks/mcp-server-aendern-ohne-nutzer-zu-brechen) [101. Your first local AI model in 30 minutes](https://studiomeyer.academy/playbooks/erstes-lokales-modell-in-30-minuten) [102. Which local model fits your hardware](https://studiomeyer.academy/playbooks/welches-lokale-modell-passt-zu-deiner-hardware) [103. Local AI and the GDPR, what it really solves and what it does not](https://studiomeyer.academy/playbooks/lokale-ki-und-die-dsgvo) [104. MCP with local models, tools without the cloud](https://studiomeyer.academy/playbooks/mcp-mit-lokalen-modellen) [105. Local or cloud, the honest arithmetic](https://studiomeyer.academy/playbooks/lokal-oder-cloud-die-ehrliche-rechnung) [106. When a stranger's repo configures your AI. The ChainDrop case](https://studiomeyer.academy/playbooks/agent-konfiguration-als-angriffsweg) [107. Transcribing conversations offline, without them leaving the building](https://studiomeyer.academy/playbooks/gespraeche-offline-transkribieren) [108. Connecting n8n to a local model](https://studiomeyer.academy/playbooks/n8n-mit-lokalem-modell-verbinden) [109. Reading documents offline when the scan must not be uploaded](https://studiomeyer.academy/playbooks/dokumente-offline-auslesen) [→ Zur Academy](https://studiomeyer.academy/levels/1)

## Sitemap

Public pages of this site as Markdown: [sitemap](https://studiomeyer.academy/sitemap.md). Curated entry point: [llms.txt](https://studiomeyer.academy/llms.txt), full text: [llms-full.txt](https://studiomeyer.academy/llms-full.txt).
