AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Cache Guard

skill-0x0funky-claude-cache-guard-claude-cache-guard · by 0x0funky

Prevents prompt-cache thrash and runaway token burn in long or image-heavy agent sessions. Load BEFORE reading images/screenshots (visual QA, render checks, UI verification, diagram review) in a conversation that already has substantial history, when running long agentic loops with periodic wake-ups, or when the user asks why token usage / rate limits burn unusually fast. Teaches batched image re…

No reviews yet
0 installs
18 views
0.0% view→install

Install

$ agentstack add skill-0x0funky-claude-cache-guard-claude-cache-guard

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-0x0funky-claude-cache-guard-claude-cache-guard)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
2mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Cache Guard? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Cache Guard — stop paying 700× overhead on context rewrites

The one mechanism to understand

Prompt cache is a prefix match with three tiers: tools → system → messages. Reads from cache cost 0.1× the base input price; writes cost 1.25× — a 12.5× spread. A long conversation is cheap as long as every call re-reads the cached prefix.

Any image anywhere in the request invalidates the entire messages tier. The next call rewrites the whole conversation history at the 1.25× write price. The rewrite cost equals the current context size — in an 800k-token session, one glance at a screenshot costs ~800k cache-write tokens, even though the image itself is ~1–2k tokens. Measured in production: 91% of a session's cost was image-triggered rewrites; the images themselves were 0.13% of the tokens.

Other full-rewrite triggers: cache TTL expiry (>5 min idle, next wake rewrites everything), model switch, tool-set / MCP change mid-session, editing earlier history. Details and pricing math: references/mechanism.md.

Rules

R1 — Batch image reads into one message

Reading 1 image and reading 10 images cost the SAME rewrite. Never look at screenshots one-by-one across turns. Accumulate paths, then read them all with parallel Read calls in a single message, and draw every conclusion in that turn.

R2 — Look once, write it down, never re-read

Immediately after viewing images, append findings to a notes file (e.g. qa-notes.md): filename → verdict → required fix. From then on cite the notes. Re-reading an image "to double-check" repeats the full-context rewrite.

R3 — Delegate vision to a subagent (best option when context is large)

A subagent has its own small, isolated context. Images it reads rewrite ITS few-k tokens, not your few-hundred-k, and its intermediate noise never enters your history. Use the Task/Agent tool (general-purpose works) with:

View these images and reply in TEXT ONLY — never return image data:
-  — check: 
-  — check: 
Reference material (text only, if the check needs it): 
For each image: PASS/FAIL, one-line reason, exact fix needed if FAIL.

The subagent's eyes are the same model — verdict quality depends on how concretely you state the criteria, so pass the "what does correct look like" context as text. Main session receives a short text verdict; its cached prefix stays intact. (Subagent calls may themselves skip caching — irrelevant: their context is tiny.)

R4 — If you must read inline, read early

Rewrite cost = context size at that moment. Front-load visual checks; don't defer them to the end of a long session. If the session is already huge, prefer R3 or a fresh session over inline reads.

R5 — Keep bulk data out of context

  • Verify renders/builds by exit code, file size, or a grep'd summary — not

by dumping output into the conversation.

  • Read only the lines you need (offset/limit); never cat a large file or

paste base64.

  • Write large intermediate results to files; pass paths, not contents.

R6 — Session hygiene for long-running agents

  • Work in continuous bursts. A giant session that idles >5 min pays a full

rewrite on every wake — for periodic monitors, run each round as a fresh one-shot session (state on disk) instead of waking a huge conversation.

  • Clear/restart at work-unit boundaries in image-heavy workflows; persistent

state belongs in files, not in the transcript.

  • Never switch model or add/remove tools (incl. MCP) mid-session — either one

invalidates the whole cache.

Decision table

| Situation | Do | |---|---| | Context small (~150k) OR repeated visual checks | Delegate to subagent (R3) | | Periodic loop with screenshots (monitor, render-watch) | Fresh one-shot session per round (R6) | | Image already viewed earlier | Use notes; do NOT re-read (R2) | | Need render/build verification | Exit code / file size / grep, no dumps (R5) |

Verify it's working

usage on each API response tells the truth: healthy sessions show cache_read_input_tokenscache_creation_input_tokens (aim ≥10:1; a write:read ratio near 1:3 or worse means thrash). To audit past sessions from transcripts:

node scripts/audit-session.mjs --hours 5          # rank recent sessions by burn
node scripts/audit-session.mjs --detail     # per-call forensics for one session

Flags to look for in the output: IMG-REWRITE (image nuked the messages tier) and TTL-WAKE (idle >5 min, whole context rewritten on wake).

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.