home/productivity/prompt-caching-4

Prompt Caching

GPTClaudeDeepSeek··257 copies·updated 2026-07-14
prompt-caching-4.prompt
# Guide 08: Prompt Caching

> **Prompt caching is the single largest automatic discount on your Claude Code bill.** It reduces input token costs by up to 90% on repeated content -- and it happens without any configuration. Understanding how it works, what breaks it, and how to maximize hit rates can save you hundreds of dollars per month.

---

## Table of Contents

- [How Prompt Caching Works](#how-prompt-caching-works)
  - [The Prefix Matching Rule](#the-prefix-matching-rule)
  - [Cache Pricing by Model](#cache-pricing-by-model)
  - [Cache Write vs Cache Hit](#cache-write-vs-cache-hit)
- [What Gets Cached in Claude Code](#what-gets-cached-in-claude-code)
- [What Breaks the Cache](#what-breaks-the-cache)
- [Cache TTL and Economics](#cache-ttl-and-economics)
  - [Standard vs Extended TTL](#standard-vs-extended-ttl)
  - [Breakeven Math](#breakeven-math)
- [Maximizing Cache Hit Rate](#maximizing-cache-hit-rate)
- [ROI Calculations](#roi-calculations)
  - [Scenario 1: 50-Turn Session with Good Caching](#scenario-1-50-turn-session-with-good-caching)
  - [Scenario 2: 50-Turn Session with Poor Caching](#scenario-2-50-turn-session-with-poor-caching)
  - [Comparison Table: Cache Hit Rate Impact](#comparison-table-cache-hit-rate-impact)
- [Advanced Patterns](#advanced-patterns)
- [Common Mistakes](#common-mistakes)
- [Key Takeaways](#key-takeaways)

---

## How Prompt Caching Works

Claude's API uses prompt caching to avoid reprocessing content it has already seen. The mechanism is straightforward: when the **prefix** of a prompt matches a previous request, the matching portion is served from cache at a steep discount instead of being reprocessed at full price.

This is not a semantic cache. It is an exact prefix match. The cache checks whether the beginning of the current request is byte-for-byte identical to a recent request. If the first 50,000 tokens of your current turn match the first 50,000 tokens of the previous turn, those 50,000 tokens are cache hits. The moment a single token diverges, everything after that point is a cache miss.

### The Prefix Matching Rule

when to use it

Community prompt sourced from the open-source GitHub repo Sagargupta16/claude-cost-optimizer (MIT). A "Prompt Caching" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.

tags

productivitycommunitydeveloper

source

Sagargupta16/claude-cost-optimizer · MIT