CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Back to Blog

Mastering Claude Prompt Caching — A Practical Guide to Slashing API Costs

Claude APIPrompt CachingCost OptimizationIndie DevAPI Tips

When building apps on the Claude API, token usage is the biggest driver of cost. If you're sending long system prompts or conversation history on every request, costs can creep up faster than expected.

That's where Prompt Caching comes in. This Anthropic feature lets you cache repeated context on their servers, reducing the cost of those tokens by up to 90% on subsequent requests.

I've been developing wallpaper and wellness apps independently for years, and after integrating Prompt Caching into my API calls, the reduction in my monthly bills was immediately noticeable. Here's everything you need to know to start using it effectively.


What Is Prompt Caching?

Prompt Caching allows Claude to store portions of your prompt on Anthropic's infrastructure so they don't need to be re-processed on every call.

Without caching, every API request charges you for all input tokens — system prompt, conversation history, and user message combined. With Prompt Caching, tokens that have been cached before are billed at a dramatically lower cache read rate.

Here's how the pricing compares for Claude Sonnet models:

  • Standard input tokens: ~$3 per million
  • Cache write tokens: ~25% more expensive than standard (first write only)
  • Cache read tokens: ~90% cheaper than standard input

To put that in perspective: if you send a 1,000-token system prompt 100 times a day, that's 100,000 tokens worth of charges without caching. With Prompt Caching, all but the first request hit the cache — dropping your effective cost to roughly 10,000 tokens equivalent.


When Does Caching Make the Biggest Difference?

Prompt Caching shines in several common patterns:

Chatbots with detailed system prompts: Customer support bots, internal knowledge assistants, or any app where you define extensive rules and context in the system prompt will see major savings once that prompt is cached.

Code analysis tools: When you repeatedly reference the same codebase or large code files across multiple questions, caching the code context can significantly reduce per-query costs.

Multi-step RAG pipelines: If you're fetching external documents and inserting them into your prompt, caching those documents across multiple queries reuses the cache rather than reprocessing the same content.

Long-running conversations: As conversation history grows, input token counts increase with each turn. Caching earlier turns in the conversation history helps keep per-request costs manageable.


How to Implement It

Enabling Prompt Caching is remarkably straightforward — just add a cache_control parameter to the content block you want cached.

import anthropic
 
client = anthropic.Anthropic()
 
response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": """You are a helpful and precise customer support assistant.
            Follow these guidelines:
            1. Always maintain a professional, friendly tone
            2. Be honest when you don't know something
            3. ...(detailed instructions)...""",
            "cache_control": {"type": "ephemeral"}  # This is all it takes
        }
    ],
    messages=[
        {"role": "user", "content": "What is your return policy?"}
    ]
)

Adding cache_control: { type: "ephemeral" } tells Claude to cache that block for up to 5 minutes. Any API call within that window using the same prompt prefix will be charged at the much cheaper cache read rate.


Designing Around Cache Boundaries

To get the most out of Prompt Caching, it helps to think about which parts of your prompt change and which stay constant.

Caching works as a prefix — everything from the beginning of your prompt up to the cache_control marker gets cached. A well-structured prompt looks like this:

[CACHED] System instructions (never changes)
[CACHED] Shared context (documents, code, FAQs)
[NOT CACHED] Recent conversation history
[NOT CACHED] Current user message

Keep stable content at the top and mark it for caching. Dynamic content like the latest user message or the last few conversation turns goes at the bottom and is processed fresh each time.


TypeScript / Node.js Example

Here's a clean implementation in TypeScript:

import Anthropic from "@anthropic-ai/sdk";
 
const client = new Anthropic();
 
const systemPrompt = `
You are a technical documentation assistant specializing in clear, concise explanations.
...(detailed instructions)...
`;
 
async function askWithCaching(userMessage: string): Promise<string> {
  const response = await client.messages.create({
    model: "claude-sonnet-4-6",
    max_tokens: 2048,
    system: [
      {
        type: "text",
        text: systemPrompt,
        cache_control: { type: "ephemeral" },
      },
    ],
    messages: [{ role: "user", content: userMessage }],
  });
 
  // Inspect cache usage in the response
  const usage = response.usage;
  console.log("Cache write tokens:", usage.cache_creation_input_tokens);
  console.log("Cache read tokens:", usage.cache_read_input_tokens);
  console.log("Standard input tokens:", usage.input_tokens);
 
  return response.content[0].type === "text" ? response.content[0].text : "";
}

The response.usage object includes cache_creation_input_tokens and cache_read_input_tokens, so you can verify that caching is actually working and monitor your savings in real time.


My Experience Using It in Production

I've integrated Claude API into support features for several of my apps — wallpaper apps, relaxation tools, and more. In one case, I embedded the full FAQ and help documentation directly into the system prompt, which made the assistant much more accurate but pushed the system prompt to around 2,500 tokens.

Before Prompt Caching, every conversation turn charged the full 2,500 tokens for that system prompt. After enabling caching, nearly all calls after the first came back as cache reads — and my cost per session dropped sharply.

The implementation took less than an hour, and the ROI was immediate. If you're using the Claude API with any kind of repeated context, this is one of the easiest optimizations you can make.


Things to Watch Out For

A few caveats worth knowing:

Cache TTL is 5 minutes: The cache expires after 5 minutes of inactivity. For batch jobs or infrequent requests, the cache may expire between calls, triggering a write charge again. Prompt Caching is most effective for high-frequency, real-time interactions.

Minimum token threshold: There's a minimum number of tokens required to create a cache entry (1,024 tokens for Claude Sonnet models). Short system prompts won't qualify — this feature is best suited for longer, richer context.

Older models may need a beta header: Some older Claude model versions require the anthropic-beta: prompt-caching-2024-07-31 header to enable caching. If you're using the latest Anthropic SDK, this is typically handled automatically.


Wrapping Up

Prompt Caching is one of the most practical optimizations available in the Claude API. The implementation overhead is minimal — just a single field in your request — but the impact on costs can be substantial, especially for apps where the same context is sent repeatedly.

If you're building on the Claude API and haven't explored Prompt Caching yet, it's worth adding to your next project or sprint. The savings speak for themselves.

For full details and the latest specifications, check out Anthropic's official documentation on Prompt Caching.