Skip to content
Development
Skill

/prompt-caching-patterns

Anthropic API prompt caching: TTL, breakpoints, stacking, invalidation, hit rate. Triggers: prompt caching, cache_control, cache breakpoint, cache TTL, hit rate.

From plugin
ai-toolkit
180117 skills44 agents

Claude Code

$ npx -y skills add softspark/ai-toolkit --skill prompt-caching-patterns --agent claude-code

SKILL.md

prompt-caching-patterns.SKILL.md
name: prompt-caching-patterns
description: "Anthropic API prompt caching: TTL, breakpoints, stacking, invalidation, hit rate. Triggers: prompt caching, cache_control, cache breakpoint, cache TTL, hit rate."
effort: medium
user-invocable: false
allowed-tools: Read

Prompt Caching Patterns

Cache repeated prefixes when reuse offsets write costs. Cache eligibility and pricing depend on the model and platform; a short system prompt is not cached merely because it repeats.

Claude API cache reference (2026-11-18)

| Model | Minimum eligible prefix | Cache read / base input price | |-------|-------------------------|-------------------------------| | Claude Opus 5.5 | 512 tokens | 5% | | Claude Fable 5.2 | 512 tokens | 2.5% | | Claude Sonnet 5.5 | 512 tokens | 5% | | Claude Haiku 5.5 | 512 tokens | 10% |

For the Claude API, a five-minute write costs 1.25 times base input and a one-hour write costs 2 times base input. Recheck [current pricing](https://platform.claude.com/docs/en/about-claude/pricing) before budgeting; provider-specific billing and model availability can differ.

Prefix design

Cache order is `tools → system → messages`, regardless of the order of request keys. An explicit breakpoint includes the marked block and everything before it. Keep dynamic material after the stable prefix.

[ tool definitions              ] breakpoint 1
[ reusable system instructions  ] breakpoint 2
[ reference documents           ] breakpoint 3
[ stable conversation prefix    ] breakpoint 4
[ current variable content      ]

There are at most four breakpoints. Top-level automatic `cache_control` moves a breakpoint to the last eligible block and consumes one slot. Explicit markers give control over a static prefix.

Explicit caching example

The caller supplies the approved model, text and output limit. Marking a prefix below its model's minimum silently produces no cache entry.

def cached_answer(client, model, policy, document, question, max_tokens):
    return client.messages.create(
        model=model,
        max_tokens=max_tokens,
        system=[{
            "type": "text",
            "text": policy,
            "cache_control": {"type": "ephemeral"},
        }],
        messages=[{
            "role": "user",
            "content": [
                {"type": "text", "text": document,
                 "cache_control": {"type": "ephemeral"}},
                {"type": "text", "text": question},
            ],
        }],
    )

Use `{"type": "ephemeral", "ttl": "1h"}` for an approved one-hour write. When mixing TTLs, put longer-lived breakpoints before shorter-lived ones. Do not send paid heartbeat requests simply to keep an unused prefix warm.

Invalidation

Changing tools invalidates subsequent system and message prefixes; changing the system invalidates subsequent messages. Changing effective top-level effort can invalidate messages and, on some models, earlier blocks. Explicitly setting the model's default effort is equivalent to omitting it. A supported per-message effort update preserves the existing prefix. Check cache usage after switching models.

A static string passed as `system` alone does not enable caching: configure `cache_control` at the request or content-block level. Keep tool definitions, document serialization and stable instructions deterministic.

Measuring reuse

Include writes when calculating the fraction of input served from cache.

def cache_read_fraction(usage):
    read = usage.cache_read_input_tokens or 0
    written = usage.cache_creation_input_tokens or 0
    uncached = usage.input_tokens or 0
    total = read + written + uncached
    return read / total if total else 0.0

Record write/read counts and actual costs across cold and warm requests. Choose a target from observed reuse; a single universal hit-rate threshold is misleading. Both cache counters remaining zero can indicate an ineligible prefix.

When not to cache

Skip cache writes when no prefix will be reused before expiry or when measured cost exceeds uncached requests. Do not pad prompts with irrelevant content merely to reach a minimum. A one-hour TTL may fit intermittent reuse better than five minutes, within the approved cost policy.

Sources and related skills

Reviewed 2026-11-18.

  • [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching)
  • [Pricing](https://platform.claude.com/docs/en/about-claude/pricing)

Use `model-routing-patterns` for route evaluation and `llm-ops-engineer` for application operations.

Read more
@softspark
Ships withai-toolkit

AI coding toolkit with machine-enforced safety, 116 skills, 44 agents, lifecycle hooks, persona presets, opt-in plugin packs, and benchmark tooling.

180117 skills44 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
180
Star history of softspark/ai-toolkit on GitHub, a chart by star-history.com

Other skills on ai-toolkit.

ai-toolkit-rules

ai-toolkit-rules

Mandatory engineering, security, testing, git, performance, quality, and response rules. Claude MUST load this skill for every…

mem-search

mem-search

Searches past coding sessions for observations, decisions, context. Triggers: mem-search, recall session, past work, prior…

a11y-validate

a11y-validate

Accessibility validator: WCAG 2.1 AA, EN 301 549, EAA. Triggers: a11y, accessibility, WCAG, EAA, ARIA, contrast, keyboard, screen…

agent-creator

agent-creator

Creates new specialized agents with frontmatter, tools, delegation. Triggers: new agent, create agent, agent scaffold,…

analyze

analyze

Analyzes code quality, complexity, patterns across codebase. Triggers: quality report, hotspot scan, code analysis, architecture…

api-patterns

api-patterns

API design: naming, versioning, pagination, idempotency, OpenAPI, error contracts and safe retries. Triggers: API design, REST,…

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills3w309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc3w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react2w252k
@facebook@facebookInstall Skill

Questions about prompt-caching-patterns.

Which coding agents can use prompt-caching-patterns?
prompt-caching-patterns installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.