opencode-optical-optimization
v0.2.0
Published
Render OpenCode V2 checkpoints, optional prompt references, and selected skills as PNGs.
Maintainers
Readme
Optical Optimization 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. You can also opt in specific loaded skills and reference sections of your own system and agent prompts.
{
"$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.
If you used opencode-optical-compaction, replace its config entry rather
than loading both packages.
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, and the visible transcript are unchanged. 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.
Opt in to prompt references and skills
{
"plugins": [{
"package": "[email protected]",
"options": {
"agents": ["build"],
"systemSources": ["core/instructions", "api/handbook"],
"skills": ["demo"]
}
}]
}- System and agent prompts: Wrap only optional reference data in an
<optical-reference name="catalog">block, with the opening and closing</optical-reference>tags on their own lines.agentsmatches exact agent IDs.systemSourcesmatches thecore/instructionssource (project instructions) or exactapi/<key>session instruction entries. Unmarked instructions stay in the system role. OpenCode 2.3.0 only supports text in that role, so the plugin sends marked references as a leading user image message and leaves a text pointer in the system prompt. Do not mark rules, permission instructions, or anything that depends on system priority. - Loaded skills:
skillsmatches exact IDs. The plugin renders the bodies of selected or explicitly attached skills once they are in context. With the built-in Anthropic route it also renders verifiedskilltool results in place; other routes keep tool-returned skills as text. Skill discovery, admission, permissions, tool calls, and skill file paths are unchanged. - These options default to off. Native compaction, text-only models, changed or unverified sources, and content that cannot be rendered fall back to text. Existing cache keys and hints are not rewritten. Replacing an earlier prefix with media can cause a cache miss even with the same key.
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.
Skill relay benchmark
Two fresh minion runs answered the same 18 questions on three skills (Testing
on the Toilet, Rune Authoring, Git Repository Management). One received only six
rendered PNG pages via the image read tool; the other received plain text.
Under strict scoring, the PNG relay scored 17/18 (94.4%) versus 18/18
(100%) for text. The PNG relay recovered the doubles order and mock rule,
but could not read the exact phrase order/getter traffic. This is a single readback comparison, not
a test of executing skill instructions, provider token savings, or latency.
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.
