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.
npx skills add softspark/ai-toolkit --skill prompt-caching-patternsgit clone --depth 1 https://github.com/softspark/ai-toolkitWrote 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.
[](https://agentmods.dev/skills/softspark/ai-toolkit/prompt-caching-patterns)<a href="https://agentmods.dev/skills/softspark/ai-toolkit/prompt-caching-patterns"><img src="https://agentmods.dev/badge/skills/softspark/ai-toolkit/prompt-caching-patterns.svg" alt="Measured on agentmods" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00043 | $0.00928 |
| Opus 5 | $0.00022 | $0.00464 |
| Sonnet 5 | $0.00009 | $0.00186 |
| Haiku 4.5 | $0.00004 | $0.00093 |
Grade A, and why
prompt-caching-patterns 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 3d 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.
How it starts
The opening of the file, as written. The whole thing — 115 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Prompt Caching Patterns
Anthropic's prompt caching cuts input-token cost by ~90% on cached prefixes and reduces latency. Worth learning because one mistake (putting a dynamic value before a stable prefix) disables the whole cache.
Cache Mechanics
- TTL: default 5 minutes;
ttl: "1h"for 1-hour cache (higher base cost but longer-lived). - Minimum size: 1024 tokens per cache block for Sonnet/Opus, 2048 for Haiku.
- Max breakpoints: 4 per request.
- Order matters: everything BEFORE a
cache_controlblock is part of that cache key. Dynamic content AFTER the cached block doesn't break the cache.
Anatomy of a Cached Request
from anthropic import Anthropic
client = Anthropic()
response = client.messages.create(
model="claude-opus-4-8",
max_tokens=1024,
system=[
{
"type": "text",
"text": LONG_SYSTEM_PROMPT, # stable across requests
"cache_control": {"type": "ephemeral"}
}
],
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": LARGE_DOCUMENT_CONTEXT,
"cache_control": {"type": "ephemeral"}},
{"type": "text", "text": user_question} # dynamic
]
}
]
)
Layering Pattern (4 breakpoints)
[ system prompt ] ← breakpoint 1 (most stable)
[ tool definitions ] ← breakpoint 2
[ long reference docs ] ← breakpoint 3
[ conversation history up to turn N ] ← breakpoint 4
[ current user message ] ← not cached (dynamic)
Put the MOST stable content earliest. A change to breakpoint 2 invalidates 3 and 4.
Anti-patterns
| Pattern | Problem | Fix |
|---|---|---|
| Timestamp in system prompt | Every request is unique | Remove timestamp, or put it AFTER the cache block |
| User name inserted into cached text | Cache misses per user | Inject user name AFTER the cache block |
| Reordering tool definitions across requests | Cache invalidated | Sort tools deterministically |
| Retrying with exponential jitter that changes prompt | Cache miss on retry | Keep the exact same prefix on retries |
| Caching <1024 tokens | Silently uncached | Merge with adjacent content or drop the breakpoint |
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.
- 3d ago First seen · 115 lines · 43 tokens per session scan A 9c9caf4f3149
prompt-caching-patterns is a skill published in the GitHub repository softspark/ai-toolkit (170 stars, last pushed 2d ago), licensed Apache-2.0. It adds 43 tokens to every session and 928 once invoked, about $0.0002 per session on Opus 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-09-03.
Other skills, from other repositories
verify-implementation
A workflow that runs a project’s verification skills to produce a report on coding patterns, architecture rules, and project conventions. It is intended for work after implementation, before a pull request, or during code review.
improve-code-quality
Guided journey from a working-but-untested vibe-coded prototype to a production-ready product with tests, clean structure, a business-rules boundary, and resilience at scale. Orchestrates nine skills phase by phase - working-with-legacy-code, clean-code, refactoring-patterns, software-design-philosophy…
remove-ai-slops
Removes AI-generated code smells from branch changes or an explicit file list behind regression tests. Use when the user asks to clean up, deslop, or remove AI-slop patterns from recent changes.
semgrep-rule-variant-creator
Creates language variants of existing Semgrep rules. Use when porting a Semgrep rule to specified target languages. Takes an existing rule and target languages as input, produces independent rule+test directories for each language.
ln-21-documentation-auditor
Audits documentation and comments for trustworthy claims, coverage, and discoverability. Not for code, test, or architecture audits.
ln-41-test-strategy-planner
Plans a risk-based test portfolio and prioritized scenarios without editing tests. Not for test execution or implementation.