How Claude Code, OpenCode and Pi place prompt-caching breakpoints differently
arpit_bhayani · x · 2026-10-17
Arpit Bhayani breaks down how different coding harnesses exploit prefix-based prompt caching: as long as the prefix is unchanged, inference for that portion is skipped, but any early change invalidates everything after it, so prompts must be ordered from most stable to most volatile.
- Claude Code: static system prompt and tools first, then project memory, session context, and messages last.
- OpenCode: caches the first 2 system messages and the last 2 non-system messages.
- Pi: marks the system prompt, last user message, and last tool.
Some harnesses cache beyond system messages — up to the last couple of turns — reusing cached computation across use cases sharing a system prompt and across turns in a conversation. The pattern: static first, volatile last, stable key per session. Break the order once (e.g. editing the system prompt mid-session) and you pay for the entire prefix again in both cost and energy.
More from coding & agent
- AI stock-research prompt series: simulate 3 price paths for any ticker over 3-6 months — bigaiguy · 2026-10-17
- AI stock prompt series: scan X for regulatory tailwinds favoring specific companies — bigaiguy · 2026-10-17
- New prototype geoclass pools OpenAI subscriptions to bypass regional inference capacity limits — TheZachMueller · 2026-10-17
- Dumping a huge task into Codex, and it just says "yea, we're doing this son" — wavefnx · 2026-10-17
- Terminal Night 3 report: UNIX philosophy, CLI organization, and AI-era terminal design — 4310sy · 2026-10-17
- Researcher urges: Claude Code and Codex are not just for coding — jacob_posel · 2026-10-17