opencode-optical-compaction
v0.1.0
Published
Replay OpenCode V2 summary checkpoints as locally rendered images.
Maintainers
Readme
Optical Compaction for OpenCode V2
OpenCode streams and saves its usual compaction summary. When a vision-capable model continues the session, this plugin replaces the outgoing text checkpoint with locally rendered PNG pages. The pages contain both the finished summary and the recent conversation OpenCode retained with it.
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["[email protected]"]
}Requires OpenCode V2 2.3.x (tested against 2.3.0). No credentials, proxy, or external rendering service are required. Remove the plugin entry to return to stock behavior. Existing checkpoints can immediately be replayed as text again.
What changes
- The first normal request after a completed summary compaction gets PNGs and a short caption instead of the checkpoint text. Later requests replay the same bytes for that checkpoint. Manual, automatic, and installed background summaries use the same handoff. Cache keys, hints, and other messages are unchanged. Text and images are inherently different inputs: the checkpoint portion of a previously cached text request cannot be reused as an image.
- New turns and attachments remain intact. Older messages and attachments are represented exactly as OpenCode serialized them for the checkpoint; this does not restore details OpenCode already shortened or omitted.
- Summary generation, native compaction, the visible transcript, system instructions, and tool calls are not modified. Models configured for native compaction (including OpenAI Responses) and models not advertising PNG/vision receive the normal request. OpenAI models configured for summary compaction are eligible.
- The renderer uses a bundled font dependency and processes content locally. Pages are only cached in memory and sent to the session's chosen model in the normal request. A failed lookup or render, unsupported characters, or an oversized checkpoint leaves the original text intact instead of truncating it.
This is an experiment in visual compression, not a byte-exact or guaranteed cost saving mode. A model can misread code, IDs, and punctuation. Image token cost and OCR quality vary by model; the plugin does not predict either. For exact values, refer back to the original transcript or re-send them as new text.
The stock OpenCode V2 2.3.0 transcript still shows the text summary. Its plugin API has no display-only image slot on the compaction row. The plugin does not create a synthetic message to simulate one because that would add transcript content back to model context.
Development
bun install --frozen-lockfile
bun run check
npm pack --dry-runInspired by AgentOCR (ACL 2026 paper) and image-token-compression. This plugin does not use optical self-compression training and does not rewrite unrelated regions of the prompt. Optical summary compaction for OpenCode V2
