anomalyco / anomalyco/opencode

After /compact, mark the new prefix as an explicit cache breakpoint instead of relying on implicit caching (GPT-5.6+)

Open
#44,727 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 24, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Problem

GPT-5.6+ supports explicit prompt caching: setting prompt_cache_options.mode: "explicit" plus a prompt_cache_breakpoint on a specific content block lets the client control exactly where the reusable prefix ends, instead of relying on OpenAI's default implicit mode (which auto-caches the latest message prefix and can trigger unnecessary writes whenever the suffix changes).

Right after a /compact, OpenCode produces a brand-new stable prefix (system prompt + compact summary), which is inherently a cache miss on the next request. That's expected and fine as a one-time cost. But without an explicit breakpoint at that exact boundary, there's nothing telling the API "this is the stable part, stop here" — so the boundary between the stable summary and the growing suffix isn't pinned, and the cache-write cost (billed at 1.25x normal input) risks being paid again on later turns instead of being paid once and then read cheaply (90% discount) for the rest of the session.

Related: #43689 shows OpenCode currently doesn't even send prompt_cache_key, so GPT-5.6 caching may not be engaging reliably at all right now. This issue is about a follow-up/adjacent gap: once caching is wired up, the compact boundary specifically needs an explicit breakpoint so the one-time post-compact cache write doesn't repeat on every subsequent turn.

Impact

Every compact event on a GPT-5.6+ session pays a cache-write premium on the full new prefix (often 50K-150K+ tokens depending on system prompt/tool schema/summary size). If that boundary isn't pinned explicitly, this cost can recur across turns instead of being paid once, which adds up over long sessions with multiple compactions.

Expected behavior

When compaction produces a new context, the boundary right after the stable prefix (system prompt + summary) should be sent with prompt_cache_options.mode: "explicit" and a prompt_cache_breakpoint on that block, so:

the first post-compact request pays the write cost once, as expected
every following request in that session reads that prefix from cache at the discounted rate instead of rewriting it.

Plugins

No response

OpenCode version

1.18.21

Steps to reproduce
  1. Configure OpenCode with any GPT-5.6 model (Luna, Terra, Sol) via OpenCode Desktop.
  2. Run a session long enough to trigger auto-compact, while watching the cache read/write stats.
  3. When compact fires, OpenCode sends a new system prompt + compact summary as the request body. This shows up as a cache_write for that full token count (expected once).
  4. Continue the session with a few more turns. The cache_write from step 3 is not being reused as a cache_read on subsequent requests — instead of one write followed by cheap reads, cache tokens keep re-appearing as writes.
Screenshot and/or share link

No response

Operating System

macOS 26.6.2

Terminal

Warp

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.