What is prompt caching in AI coding agents?
By Flavio
Prompt caching reuses processing for a matching prompt prefix. Learn what it saves in coding sessions, what stays in context, and how to check usage.
Prompt caching reuses model processing for an eligible, matching beginning of a prompt. This can reduce the cost and time spent reading repeated instructions and conversation history.
Read Prompt caching, compression, and compaction in coding agents for the full walkthrough and cost examples.
How prompt caching works
A coding agent makes several model requests during a task. Earlier instructions and messages can appear again as it adds tool results. A provider can reuse a saved prefix when the content, settings, and cache boundaries qualify.
The text still occupies the context window. Compaction reduces that text by replacing earlier context with a shorter representation.
Prompt caching around the coding tools
Claude Code handles prompt caching automatically. Its cost documentation describes cache statistics in /usage.
For OpenAI-backed applications, the OpenAI API guide explains matching prefixes and cache boundaries. Those API settings are separate from the controls a Codex interface exposes.
Cursor’s models and pricing page lists cached-input rates. Use the rate for the model you selected when reading usage.
Grok’s API caching guide covers provider caching. Configure API requests using that guide; check Grok Build documentation separately for its app controls.
Details checked against each vendor’s documentation in November 2026.
A real example
In a current interactive Claude Code session, run:
/usage
Read the prompt-cache statistics after a response. Compare them after another turn in the same task. A hit shows reuse for eligible input; the new answer still needs generation.
Use this when investigating a long session’s usage. Keep reusable project instructions stable and put changing task details in later messages. For API settings and the difference between reads and writes, follow the full caching guide.
Pitfalls
A matching opening alone can be insufficient. Cache lifetime, minimum length, and eligible boundaries depend on the provider and model. Changing earlier content can prevent later reuse.
Cached input still adds up across requests. Check output usage too, and compare total cost when evaluating a change. Subscription allowances and API bills have different accounting, as subscription vs API key explains.
Skill Cabinet helps manage reusable agent instructions. Deciding which instructions belong in a skill is covered by agent skills.
Related glossary entries
- Context window: The context window is everything a coding agent can see at once. How to check it, free it and keep it small in Claude Code, Codex, Cursor and Grok Build.
- Compaction: Compaction replaces older chat turns with a shorter summary so a coding agent can keep going. How Claude Code, Codex, Cursor and Grok Build each run it.
- Tokens and usage limits: A token is the unit a model reads and writes. A usage limit is how much of that work a plan includes. How Claude Code, Codex, Cursor and Grok count it.
Want me to talk about your product? You can sponsor this site.