
prompt-caching
Prompt caching for Claude API to reduce latency by up to 85% and costs by up to 90%. Activate for cachecontrol, ephemeral caching, cache breakpoints, and performance optimization.
- Installs
- 54
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/thelobbi/claude --skill prompt-caching- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads prompt-caching automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Prompt Caching Skill
Leverage Anthropic's prompt caching to dramatically reduce latency and costs for repeated prompts.
When to Use This Skill
- RAG systems with large static documents
- Multi-turn conversations with long instructions
- Code analysis with large codebase context
- Batch processing with shared prefixes
- Document analysis and summarization
Core Concepts
Cache Control Placement
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are a helpful assistant with access to a large knowledge base...",
"cache_control": {"type": "ephemeral"} # Cache this content
}
],
messages=[{"role": "user", "content": "What is...?"}]
)
Cache Hierarchy
Cache breakpoints are checked in this order:
- Tools - Tool definitions cached first
- System - System prompts cached second
- Messages - Conversation history cached last
TTL Options
| TTL | Write Cost | Read Cost | Use Case |
|---|---|---|---|
| 5 minutes (default) | 1.25x base | 0.1x base | Interactive sessions |
| 1 hour | 2.0x base | 0.1x base | Batch processing, stable docs |
Cache Requirements
- Minimum tokens: 1024-4096 (varies by model)
- Maximum breakpoints: 4 per request
- Supported models: All current models (Fable 5, Opus 4.8, Sonnet 5, Haiku 4.5)
Implementation Patterns
Pattern 1: Single Breakpoint (Recommended)
# Best for: Document analysis, Q&A with static context
system = [
{
"type": "text",
"text": large_document_content,
"cache_control": {"type": "ephemeral"} # Single breakpoint at end
}
]
Pattern 2: Multi-Turn Conversation
# Cache grows with conversation
messages = [
{"role": "user", "content": "First question"},
{"role": "assistant", "content": "First answer"},
{
"role": "user",
"content": "Follow-up question",
"cache_control": {"type": "ephemeral"} # Cache entire conversation
}
]
Pattern 3: RAG with Multiple Breakpoints
system = [
{
"type": "text",
"text": "Tool definitions and instructions",
"cache_control": {"type": "ephemeral"} # Breakpoint 1: Tools
},
{
"type": "text",
"text": retrieved_documents,
"cache_control": {"type": "ephemeral"} # Breakpoint 2: Documents
}
]
Pattern 4: Batch Processing with 1-Hour TTL
# Warm the cache before batch
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=100,
system=[{
"type": "text",
"text": shared_context,
"cache_control": {"type": "ephemeral", "ttl": "1h"}
}],
messages=[{"role": "user", "content": "Initialize cache"}]
)
# Now run batch - all requests hit the cache
for item in batch_items:
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
system=[{
"type": "text",
"text": shared_context,
"cache_control": {"type": "ephemeral", "ttl": "1h"}
}],
messages=[{"role": "user", "content": item}]
)
Performance Monitoring
Check Cache Usage
response = client.messages.create(...)
# Monitor these fields
cache_write = response.usage.cache_creation_input_tokens # New cache written
cache_read = response.usage.cache_read_input_tokens # Cache hit!
uncached = response.usage.input_tokens # After breakpoint
print(f"Cache hit rate: {cache_read / (cache_read + cache_write + uncached) * 100:.1f}%")
Cost Calculation
def calculate_cost(usage, model="claude-sonnet-5"):
# Example rates (check current pricing)
base_input_rate = 0.003 # per 1K tokens
write_cost = (usage.cache_creation_input_tokens / 1000) * base_input_rate * 1.25
read_cost = (usage.cache_read_input_tokens / 1000) * base_input_rate * 0.1
uncached_cost = (usage.input_tokens / 1000) * base_input_rate
return write_cost + read_cost + uncached_cost
Cache Invalidation
Changes that invalidate cache:
| Change | Impact |
|---|---|
| Tool definitions | Entire cache invalidated |
| System prompt | System + messages invalidated |
| Any content before breakpoint | That breakpoint + later invalidated |
Best Practices
DO:
- Place breakpoint at END of static content
- Keep tools/instructions stable across requests
- Use 1-hour TTL for batch processing
- Monitor cache_read_input_tokens for savings
DON'T:
- Place breakpoint in middle of dynamic content
- Change tool definitions frequently
- Expect cache to work with <1024 tokens
- Ignore the 20-block lookback limit
Integration with Extended Thinking
# Cache + Extended Thinking
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=16000,
thinking={"type": "adaptive"},
system=[{
"type": "text",
"text": large_context,
"cache_control": {"type": "ephemeral"}
}],
messages=[{"role": "user", "content": "Analyze this..."}]
)
See Also
- [[llm-integration]] - Claude API basics
- [[extended-thinking]] - Deep reasoning
- [[batch-processing]] - Bulk processing
FAQ
What does the prompt-caching skill do?
Prompt caching for Claude API to reduce latency by up to 85% and costs by up to 90%. Activate for cachecontrol, ephemeral caching, cache breakpoints, and performance optimization.
How do I install prompt-caching?
Run npx skills add https://github.com/thelobbi/claude --skill prompt-caching in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/prompt-caching/ (personal) or .claude/skills/prompt-caching/ (project).
Which AI agents can use prompt-caching?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is prompt-caching safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains prompt-caching?
It is published by thelobbi in thelobbi/claude. It has 54 recorded installs.
More from thelobbi/claude
vision-multimodal
thelobbi/claude
Vision and multimodal capabilities for Claude including image analysis, PDF processing, and document understanding. Activate for image input, base64 encoding, multiple images, and visual analysis.
complex-reasoning
thelobbi/claude
Multi-step reasoning patterns and frameworks for systematic problem solving. Activate for Chain-of-Thought, Tree-of-Thought, hypothesis-driven debugging, and structured analytical approaches that leverage extended thinking.
design-system
thelobbi/claude
Apply and manage the AI-powered design system with 50+ curated styles
gcp
thelobbi/claude
Google Cloud Platform services including GKE, Cloud Run, Cloud Storage, BigQuery, and Pub/Sub. Activate for GCP infrastructure, Google Cloud deployment, and GCP integration.
keycloak
thelobbi/claude
Keycloak identity and access management including realms, clients, authentication flows, themes, and user federation. Activate for OAuth2, OIDC, SAML, SSO, identity providers, and authentication configuration.
kanban
thelobbi/claude
Kanban methodology including boards, WIP limits, flow metrics, and continuous delivery. Activate for Kanban boards, workflow visualization, and lean project management.
Popular ai & agents skills
google-agents-cli-publish
google/agents-cli
This skill should be used when the user wants to "publish an agent", "publish my ADK agent", "register an agent with Gemini", "publish to Gemini" (formerly Gemini Enterprise), or needs guidance on the agents-cli publish gemini command. Also use when the user wants to "manage agents in Agent Registry", "list/update/delete registered agents", or "register an MCP server". Covers ADK vs A2A registration modes, programmatic and interactive usage, flag reference, auto-detection from deployment metadata, Agent Registry fleet management, and troubleshooting. Part of the agents-cli skills suite. Do NOT use for deployment (use google-agents-cli-deploy).
google-agents-cli-eval
google/agents-cli
This skill should be used when the user wants to "run an evaluation", "evaluate my agent", "evaluate my ADK agent", "write an eval dataset", "analyze eval failures", "compare eval results", "optimize agent", or needs guidance on the Gemini platform eval methodology and the Quality Flywheel. Covers eval metrics, dataset schema, LLM-as-judge scoring, and common failure causes. Applies to any agents-cli project, whatever framework the agent is written in. Do NOT use for agent API code patterns (ADK: use google-agents-cli-adk-code), deployment (use google-agents-cli-deploy), or project scaffolding (use google-agents-cli-scaffold).
skill-creator
anthropics/skills
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
codex-pet
prime-skills/runcomfy-agent-skills
Codex Pet generator on RunComfy. Build a Codex-compatible Codex Pet spritesheet.webp + pet.json from a single reference image, drop it into ${CODEXHOME:-$HOME/.codex}/pets/ / and Codex picks it up as a custom Codex Pet next to the 8 built-ins. This skill produces the exact Codex Pet atlas Codex expects (1536x1872 PNG/WebP, 8 cols x 9 rows, 192x208 cells, 9 animation states — idle, running-right, running-left, waving, jumping, failed, waiting, running, review). Calls OpenAI GPT Image 2 edit ONCE via the local RunComfy CLI as runcomfy run openai/gpt-image-2/edit to produce a canonical Codex Pet pose, then assembles all 9 animation rows programmatically with ImageMagick micro-transforms — no Codex Pro, no $imagegen, no OPENAIAPIKEY required, only RUNCOMFYTOKEN. Triggers on "codex pet", "create codex pet", "make codex pet", "hatch codex pet", "/hatch image", "desktop pet codex", "codex pets", "spritesheet.webp", or any explicit ask to build a custom pet for OpenAI Codex.
full-output-enforcement
leonxlnx/taste-skill
Overrides default LLM truncation behavior. Enforces complete code generation, bans placeholder patterns, and handles token-limit splits cleanly. Apply to any task requiring exhaustive, unabridged output.
executing-plans
obra/superpowers
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available