Skip to content

Anthropic

Claude Code implements automatic prompt caching, reducing input token costs to 10%

Written by an AI model from the linked sources and checked against them by a second model. How we work

All about: Claude Code versions and changes →
Image: code.claude.com

Anthropic detailed how prompt caching functions in Claude Code. Without caching, the API would reprocess the entire history on every step: system prompts, project context, past messages, and tool outputs. The cache reuses processed prefixes and only computes changes.

Matching relies on exact prefix alignment. Claude Code sorts content into layers: system prompts and tools, then project context (CLAUDE.md, memory), and finally the dialogue. Changes in an early layer invalidate everything that follows.

Cache invalidation occurs upon changing models, effort levels, enabling fast mode, adding an MCP server to the prefix, or upgrading Claude Code. The default TTL is five minutes, with a one-hour option for subscribers. You can enable the longer TTL via the ENABLE_PROMPT_CACHING_1H=1 environment variable.

No comments yet. Be the first.

Join the conversation

Sign in to leave a comment. It appears after moderation.