跳到正文
cccskills
免费在 GitHub 公开

prompt-caching

Cache the parts of the prompt that don't change so a long-running loop stops paying full price on every turn. Use when the system prompt, tool defs, or reference docs are stable across many turns.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md2.9 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Prompt Caching

Every turn of a Plan→Act→Verify loop resends the same system prompt, the same tool definitions, and (usually) the same reference docs. Without cache breakpoints you pay full input price on all of it, every turn. With them, cached reads cost ~10% of the write.

Where to put breakpoints

Cache from the top of the prompt down. The cache is prefix-matched — a break in the middle invalidates everything after it.

  1. System prompt — mark the end of it as a breakpoint if it's >1024 tokens (Sonnet/Opus) or >2048 (Haiku).
  2. Tool definitions — cache immediately after, if the tool set is stable across the loop.
  3. Large stable docs — repo map, style guide, spec — before any turn-specific user text.
  4. User message stem — only if the same preamble repeats every turn.

Everything past the last breakpoint is billed fresh every turn. That's fine — that's where the changing content goes.

TTL choice

  • 5-minute cache (default) — for tight loops where turns are seconds apart. Free to write.
  • 1-hour cache — for slow loops (human in the loop, background jobs). Write cost is higher; break-even is ~2 hits.

Pick 5m unless you know turns are minutes apart.

Staleness rules — cache invalidation is silent

  • Any byte change above the breakpoint invalidates the cache from that point.
  • Reordering tools or messages counts as change.
  • Trailing whitespace counts as change.
  • A different model version counts as change.

If cost isn't dropping, log the cache-hit metric. Do not assume.

When NOT to cache

  • Prompt <1024 tokens — below the minimum block size, no savings.
  • One-shot calls — no reuse, cache write is wasted.
  • Highly dynamic system prompt (per-user templating) — cache misses will exceed hits.

Red flags

  • Cost graph flat after adding breakpoints — you're invalidating on every turn. Diff two consecutive requests byte-for-byte above the breakpoint.
  • Breakpoint after user message — pointless; the user message changes every turn.
  • Four+ breakpoints — max is four; extras are ignored silently.
  • Caching a prompt that gets edited mid-session — one edit above the cut wipes all downstream savings.

The math

Cache write ≈ 1.25× normal input. Cache read ≈ 0.1× normal input. So a stable 20K-token prefix hit N times: N=1 costs more than no-cache; N=2 breaks even; N=10 costs ~15% of no-cache. Long loops win big; short chats lose.

Cache is the single biggest cost lever on a long-running agent. Set it once at the start of the loop, verify hits, forget it.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

a11y-pass

免费

Catch the accessibility failures that ship in almost every AI-built UI. Use after building any interactive component.

中文简介正在准备中。当前显示原文说明。

Archive228/loopkit7552026年7月15日 更新

Before compaction Loopkit extracts decisions into claude-decisions.json (machine-readable). Read it alongside claude-progress.txt at session start — prose is for humans, JSON is for the loop.

中文简介正在准备中。当前显示原文说明。

Archive228/loopkit7552026年7月15日 更新

Review a diff against the goal spec assuming the code is BROKEN. The reviewer that lives in the maker's head always agrees with itself — this pulls review into a hostile, separate pass. Invoke after every code change before marking work done.

中文简介正在准备中。当前显示原文说明。

Archive228/loopkit7552026年7月15日 更新

Verify that an endpoint checks ownership, not just authentication. Use on any handler that reads or mutates user data.

中文简介正在准备中。当前显示原文说明。

Archive228/loopkit7552026年7月15日 更新

Find the exact commit that introduced a bug. Use when something worked before and broke, and you don't know which change did it.

中文简介正在准备中。当前显示原文说明。

Archive228/loopkit7552026年7月15日 更新

Before picking new work, smoke-test the last "completed" feature. If it's broken, revert and re-open it before touching anything else. Kills the "looks shipped, isn't shipped" bug across sessions.

中文简介正在准备中。当前显示原文说明。

Archive228/loopkit7552026年7月15日 更新

查看 Archive228 的全部技能

报告此技能的问题