Skip to content
claude.dev BlogThariq Shihipar

Building Claude Code: designing agents around prompt caching

Lessons from building Claude Code: Prompt caching is everything

The Claude Code team shared engineering lessons on prompt caching, keeping the request prefix stable to cut latency and cost in long agent sessions. Put static content first, update state through messages, avoid switching models or adding and removing tools mid-session, and use defer_loading to load tools late. When compacting context, reuse the original session's system prompt, tool definitions and history, then append the compaction request so it hits the cache. The team also tracks cache hit rate and treats an abnormal drop as an incident.

Why it matters: The Claude Code team applies cache prefix stability to prompt ordering, tool loading and context compaction, a transferable caching method for long agent sessions.

Read the original ↗Export Markdown