agentleFS
narenaryannarenaryan/agent-skills/skills/engineering/prompt-cache-boundaries/SKILL.md

prompt-cache-boundaries

Skill0 starsChanged 39 days agoMITView on GitHub

Use when Claude API agents repeatedly rewrite shared context, first requests miss the prompt cache, or high cache-hit rates coexist with rising per-task cost.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Verify the chosen model/platform's minimum cacheable length, isolation scope, TTL, and breakpoint limits.

    line 23
  2. Distinctive:

    Run offline counterexamples from repository root:

    line 40

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Audit Prompt Cache Boundaries

A stable template need not produce a stable provider-bound prefix. A matching prefix is not an observed cache hit; a hit is not evidence of lower task cost or preserved task quality.

Separate the evidence

QuestionEvidence
What changed?Final request structure, ordered tools, system blocks, history, model, and prompt-affecting settings
What was reused?Actual response usage.cache_read_input_tokens, not a local hash
Did optimization help?Comparable completed tasks: total usage, latency, failures, and independently checked outcomes

Repair the boundary

  1. Inspect authorized synthetic requests after harness/SDK transformations. Record model, platform, workspace, feature configuration, and breakpoint positions. Keep prompt bodies, credentials, and customer data out of telemetry.
  2. Claude prefixes follow tools → system → messages. Keep tool order and schema serialization deterministic. Changed tool definitions invalidate later prefixes; hashing only the system prompt misses this. Do not erase required instructions or tools merely to make requests match.
  3. Separate stable instructions from changing repository/date/context blocks, preserving their roles, content, and ordering. Mark the last stable block with "cache_control": {"type": "ephemeral"}. A marker after volatile content writes that volatile prefix; lookback cannot recover a shorter entry that was never written. Automatic caching alone does not fix that layout.
  4. Verify the chosen model/platform's minimum cacheable length, isolation scope, TTL, and breakpoint limits. Concurrent readers cannot use a new entry before its writer's response starts. A local byte comparison establishes neither token eligibility nor cache availability.

[shared policy + cwd/date]◀cache differs between jobs. [shared policy]◀cache [cwd/date] exposes a reusable boundary without deleting context. Changing an earlier tool description still breaks that prefix. Reordering/splitting content needs task-quality checks; preserved concatenated text alone is insufficient.

Diagnose without inventing certainty

For authorized Claude API calls, opt into diagnostics each turn and chain the previous response ID. This feature is not available on Bedrock or Google Cloud. Read diagnostics alongside usage:

ResultInterpretation
diagnostics: nullAmbiguous without opt-in and prior-ID context; never independently proves a hit
cache_miss_reason: nullComparison pending
previous_message_not_found / unavailableNo usable comparison
*_changedFirst divergence only; an earlier prefix may still hit

Compare write/read/uncached/output tokens and calls per completed task, not only hit percentage. Keep model/effort and task mix comparable; any intentional changes need separate quality evaluation. Vendor savings do not transfer automatically.

Run offline counterexamples from repository root:

python3 skills/engineering/prompt-cache-boundaries/fixture.py

Primary sources and validation limits.

Pitfalls

  • Treating a null diagnostic or local fingerprint as a hit, or a first-call miss as proof of a broken boundary.
  • Sharing private context beyond its authorized audience to improve reuse.
  • Claiming savings or quality parity from serialization tests; they exercise neither inference nor billing.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.