prompt-caching-patterns

prompt-caching-patterns is a skill for Claude Code from softspark/ai-toolkit. It costs 43 tokens per session (928 once invoked), scanned A, original, Apache-2.0.

A guided process for restructuring code while preserving its existing behaviour.

In plain words
What is it for?
Use it to extract functions or components, rename or move code, simplify logic, or remove unnecessary abstractions.
Why use it?
It makes cleanup safer by requiring a plan, tests before and after changes, small commits, and approval before execution.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the ai-toolkit plugin — 113 skills, 44 agents, 14 hooks shipped together

Good fit Use it to extract functions or components, rename or move code, simplify logic, or remove unnecessary abstractions.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/softspark/ai-toolkit/prompt-caching-patterns
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 softspark/ai-toolkit --skill prompt-caching-patterns
Clone the repo
git clone --depth 1 https://github.com/softspark/ai-toolkit

Made for: Claude Code.

Or install ai-toolkit, the plugin that ships this one along with the rest of its 113 skills, 44 agents, 14 hooks.

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-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/softspark/ai-toolkit/prompt-caching-patterns.svg)](https://agentmods.dev/skills/softspark/ai-toolkit/prompt-caching-patterns)
Your own site
<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>
Per session 43 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 928 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.00043 $0.00928
Opus 5 $0.00022 $0.00464
Sonnet 5 $0.00009 $0.00186
Haiku 4.5 $0.00004 $0.00093

Measured 3d ago against content hash 9c9caf4f3149, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

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.

app/skills/prompt-caching-patterns/SKILL.md · 115 lines

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_control block 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

Read the full file on GitHub · 115 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. 3d ago First seen · 115 lines · 43 tokens per session scan A 9c9caf4f3149

Subscribe to this mod's changes

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.

Related

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.

sangrokjung/claude-forge · 37 tokens

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…

wondelai/skills · 227 tokens

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.

code-yeongyu/oh-my-openagent · 45 tokens

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.

waybarrios/opencode-power-pack · 50 tokens

ln-21-documentation-auditor

Audits documentation and comments for trustworthy claims, coverage, and discoverability. Not for code, test, or architecture audits.

levnikolaevich/claude-code-skills · 34 tokens

ln-41-test-strategy-planner

Plans a risk-based test portfolio and prioritized scenarios without editing tests. Not for test execution or implementation.

levnikolaevich/claude-code-skills · 29 tokens