Explains Claude API prompt caching: automatic vs explicit breakpoints, TTLs, minimum cacheable lengths, invalidation, and measuring hit rate. Useful for reducing API costs with repeated context.
Ships in messages-api-features. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
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.
usage.cache_read_input_tokens is zero but should not bePut 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,
});
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.
| 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 |
Cache reads are billed at a fraction of base input (0.1x on most models; the pricing page lists lower multipliers for some newer models). The 1-hour TTL needs no beta header. Whether 1h pays off depends on your request spacing: compute it with your own traffic, not a rule of thumb.
Prefixes shorter than the model's minimum cacheable length are processed without caching and without an error. The minimum differs by model (the docs list values from 512 to 4,096 tokens). Look up your model in the prompt caching page.
| Change | Invalidates |
|---|---|
| Tool definitions (including order) | Everything |
| Toggling web search or citations, or the speed setting | System and messages |
tool_choice, adding or removing images | Messages |
Thinking parameters or top-level output_config.effort | Model-specific; often messages |
| Any byte change in an earlier block | Everything after it |
| Different model | Separate cache |
Caches are isolated per workspace on the Claude API (per organization on some cloud platforms) and never shared across them. The system looks back a limited number of blocks (20 per docs) from a breakpoint for a prior entry, so very long multi-turn histories should keep a breakpoint near the end.
const u = response.usage;
const totalInput = u.input_tokens + (u.cache_creation_input_tokens ?? 0) + (u.cache_read_input_tokens ?? 0);
const hitRate = (u.cache_read_input_tokens ?? 0) / totalInput;
console.log({ hitRate, created: u.cache_creation_input_tokens, byTtl: u.cache_creation });
Total input is the sum of input_tokens, cache_creation_input_tokens, and cache_read_input_tokens; input_tokens alone is only the part after the last breakpoint. Track hit rate per route as a metric.
cache_creation_input_tokens > 0 on every request: the prefix changes. Diff two consecutive request bodies byte by byte (look for timestamps, unsorted JSON, varying tool sets)cache_control was sentusageWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
7 skills in this plugin
/code-executionUse the Claude API code execution tool so the model runs Bash and Python in an Anthropic-hosted sandbox during a response — for calculation, data analysis, file generation, and checking its own work. Covers tool versions, file upload, retrieving generated files, container reuse, limits, and data-retention constraints.
Use this skill when building features where Claude must actually run code (not just write it), when choosing a code execution tool version, or when debugging missing output files or expired containers.
Activate when: Claude code execution, code_execution tool, Python sandbox, run code tool, data analysis agent, code interpreter, container_upload, container reuse, OUTPUT_DIR.
/computer-useBuild desktop and browser automation agents with the Claude API computer use toolset — screenshots, clicks, typing, scrolling — run by your own harness inside an isolated VM or container. Covers choosing the toolset version, the agent loop, batch actions, sandboxing, prompt-injection risk, and when an API integration is the better choice.
Use this skill when building agents that operate GUIs (legacy apps, browsers without APIs), migrating from an older computer use tool version, or reviewing the safety of a computer use deployment.
Activate when: Claude computer use, computer_toolset, computer_20251124, computer_20250124, desktop agent, screen control, click and type agent, GUI automation.
/long-contextWork with large Claude context windows deliberately — check the window for your model, count tokens before sending, structure long inputs for recall, cache the stable part, and manage growing conversations with compaction, context editing, or memory instead of stuffing everything in.
Use this skill when feeding large codebases, document sets, or long agent histories to Claude, when weighing long context against retrieval, or when a conversation is approaching the context limit.
Activate when: long context, context window, 1M context, context limit, prompt is too long, context rot, compaction, context editing, long context vs RAG, token counting.
/memory-toolGive Claude agents persistent memory across conversations with the Claude API memory tool — a client-side file store under /memories that Claude reads and writes through commands your application executes. Covers setup, the six commands, SDK helpers, path-traversal protection, and pairing memory with compaction or context editing.
Use this skill when an agent must remember preferences, project state, or decisions between sessions, when implementing a memory handler, or when reviewing a memory implementation for security.
Activate when: Claude memory tool, memory_20250818, agent memory, persistent memory, /memories directory, cross-session state, long-term memory agent, BetaLocalFilesystemMemoryTool.
/thinking-and-effortConfigure Claude's thinking and the effort parameter correctly — adaptive vs legacy budget-based thinking, the display setting, effort levels, thinking with tool use, cost control with max_tokens, and how thinking settings interact with prompt caching. Model behavior differs, so the skill shows how to check per-model rules instead of assuming them.
Use this skill when enabling or tuning reasoning, migrating code that uses budget_tokens, debugging 400 errors on thinking parameters, empty thinking blocks, or truncated answers, or trading quality against latency and cost.
Activate when: extended thinking, adaptive thinking, budget_tokens, effort parameter, output_config effort, thinking blocks, thinking display, interleaved thinking, reasoning tokens, thinking_tokens.
/web-search-and-fetchGive Claude live web access with the Claude API web search and web fetch server tools — choosing tool versions, domain filtering, max_uses, citations, dynamic filtering, handling errors that arrive inside a 200 response, multi-turn requirements, cost, and data-exfiltration safeguards.
Use this skill when an application needs current information, cited answers, or the contents of a specific URL or PDF, or when debugging web tool errors, missing citations, or unexpected cost.
Activate when: Claude web search, web_search tool, web fetch, web_fetch tool, browse the web API, citations, allowed_domains, blocked_domains, max_uses, dynamic filtering, pause_turn.
/messages-api-features:prompt-cachingfrom messages-api-features
npx claudepluginhub latestaiagents/agent-skills --plugin messages-api-features2 plugins in one repository ship this exact skill · first indexed Nov 5, 2026