prompt-caching

prompt-caching is a skill for Claude Code from latestaiagents/agent-skills. It costs 127 tokens per session (1,416 once invoked), scanned A, original, MIT.

A guide to prompt caching in the Claude API, which stores a reusable beginning of a request so repeated system instructions, documents, or code do not need to be processed from scratch each time.

In plain words
What is it for?
Use it when many requests share a large system prompt, tool list, document, codebase, or conversation history, and when you need to measure whether the cache is being used.
Why use it?
Repeated large inputs can add processing cost and delay, especially in multi-turn chats and agent loops. Caching can reuse an unchanged prefix, provided the earlier text remains identical.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the messages-api-features plugin — 7 skills shipped together , and of latestaiagents

Good fit Use it when many requests share a large system prompt, tool list, document, codebase, or conversation history, and when you need to measure whether the cache is being used.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/latestaiagents/agent-skills/prompt-caching
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add latestaiagents/agent-skills --skill prompt-caching
Clone the repo
git clone --depth 1 https://github.com/latestaiagents/agent-skills

Made for: Claude Code.

Or install messages-api-features, the plugin that ships this one along with the rest of its 7 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for prompt-caching

README.md
[![agentmods](https://agentmods.dev/badge/skills/latestaiagents/agent-skills/prompt-caching/github.svg)](https://agentmods.dev/skills/latestaiagents/agent-skills/prompt-caching)
Your own site
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/prompt-caching"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/prompt-caching/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for prompt-caching

Your own site · 80×15
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/prompt-caching"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/prompt-caching.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 127 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,416 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00127 $0.01416
Opus 5.5 $0.00051 $0.00566
Sonnet 5.5 $0.00025 $0.00283
Haiku 4.5 $0.00013 $0.00142

Measured 26d ago against content hash 4de6b53732d5, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

prompt-caching scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 26d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/messages-api-features/prompt-caching/SKILL.md · 126 lines

How it starts

The opening of the file, as written. The whole thing — 126 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Prompt Caching

Caching is a prefix match. If the bytes before a breakpoint are identical to a recent request, the API reads them from cache at a fraction of the normal input price. Any change earlier in the prefix invalidates everything after it.

When to Use

  • Large system prompts or tool lists reused across requests
  • Many questions against the same document or codebase
  • Multi-turn conversations and agent loops whose history grows
  • Any workload where usage.cache_read_input_tokens is zero but should not be

Workflow

Step 1: Start with automatic caching

Put cache_control at the top level of the request. The API places the breakpoint on the last cacheable block and moves it forward as the conversation grows.

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();
const MODEL = process.env.ANTHROPIC_MODEL!; // a current model ID

const response = await client.messages.create({
  model: MODEL,
  max_tokens: 4096,
  cache_control: { type: "ephemeral" },
  system: LARGE_STABLE_SYSTEM_PROMPT,
  messages,
});

Step 2: Use explicit breakpoints when layers change at different rates

You can place up to 4 breakpoints per request, on individual blocks.

const response = await client.messages.create({
  model: MODEL,
  max_tokens: 4096,
  tools: TOOLS, // deterministic order
  system: [
    { type: "text", text: INSTRUCTIONS },
    { type: "text", text: KNOWLEDGE_BASE, cache_control: { type: "ephemeral", ttl: "1h" } },
  ],
  messages, // conversation can use automatic caching or a moving breakpoint
});

The render order is tools, then system, then messages. Put the most stable content first and anything volatile (timestamps, request IDs, the current question) after the last breakpoint.

Step 3: Choose a TTL

TTL Syntax Write cost (per docs) Use for
5 minutes (default) { type: "ephemeral" } 1.25x base input Active conversations, agent loops
1 hour { type: "ephemeral", ttl: "1h" } 2x base input Shared prefixes reused less often than every 5 minutes

Read the full file on GitHub · 126 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 26d ago First seen · 126 lines · 127 tokens per session scan A 4de6b53732d5

Subscribe to this mod's changes

prompt-caching is a skill published in the GitHub repository latestaiagents/agent-skills (6 stars, last pushed 26d ago), licensed MIT. It adds 127 tokens to every session and 1,416 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-04.

Related

prompt-caching compared with skills from other repositories

prompt-caching next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
prompt-cachinglatestaiagents/agent-skillsSkill626d agoMITA127Claude Code
agent-collective-intelligence-coordinatorruvnet/rufloSkill83ktodayMITA29Claude Code
agent-memory-coordinatorruvnet/rufloSkill83ktodayMITA19Claude Code
nexent-daily-testModelEngine-Group/nexentSkill6.3kyesterdayMITA78Claude Code, Codex
mem0-integrationa5c-ai/babysitterSkill1.9k28d agoMITA27Claude Code
langchain-memorya5c-ai/babysitterSkill1.9k28d agoMITA21Claude Code
knowledge-graph-managementa5c-ai/babysitterSkill1.9k28d agoMITA22Claude Code