Compact large JSON tool output in OpenCode with TOON.
The plugin acts as a middle layer: it stores shorter TOON in the context window instead of full JSON, while preserving JSON compatibility when forwarded output is used by later bash commands.
It only replaces the original output when the TOON result is smaller.
Strongly tabular JSON can see roughly 40-60% token savings, with smaller wins on mixed or nested data.
avg tokens
JSON |โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| 100%
TOON |โโโโโโโโโโโโ...... | 40-60% less
Add it to your OpenCode config:
{
"plugin": ["opencode-toon-plugin"]
}The plugin sits between tool output and the agent context. The agent sees compact TOON instead of large JSON, but commands can still receive JSON when that output is forwarded later.
Only bash output is handled by default. Output is changed only when all checks pass:
โโโโโโโโโโโโโโโ
โ bash output โ
โโโโโโโโฌโโโโโโโ
โ
v
โโโโโโโโโโโโโโโโโโโ no
โ 256+ chars and โโโโโโโโโโ> keep original output
โ valid JSON? โ
โโโโโโโโโโฌโโโโโโโโโ
โ yes
v
โโโโโโโโโโโโโโโโโโโ no
โ TOON is shorter โโโโโโโโโโ> keep original output
โ than JSON? โ
โโโโโโโโโโฌโโโโโโโโโ
โ yes
v
show TOON in context
remember original JSON in memory
Before a later bash command runs, the plugin looks for TOON payloads inside quoted strings and heredocs. It restores JSON in two cases:
- Exact match: the TOON text matches output remembered in the current OpenCode process.
- Valid TOON fallback: no memory match exists, but the payload can be decoded as TOON.
Edited or invalid TOON is left unchanged.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ bash command contains TOON payload โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ
โ
v
โโโโโโโโโโโโโโโโโโโโ yes
โ remembered exact โโโโโโโโโ> restore original JSON
โ TOON output? โ
โโโโโโโโโโฌโโโโโโโโโโ
โ no
v
โโโโโโโโโโโโโโโโโโโโ yes
โ valid TOON โโโโโโโโโ> decode to JSON
โ payload? โ
โโโโโโโโโโฌโโโโโโโโโโ
โ no
v
run command unchanged
Prompt:
Run `gh api repos/octocat/Hello-World/issues` and show me the result.
| Without TOON | With TOON |
|---|---|
[
{
"id": 1,
"title": "Found a bug",
"state": "open",
"labels": [
{ "name": "bug" }
],
"assignee": "monalisa"
},
{
"id": 2,
"title": "Docs update",
"state": "open",
"labels": [
{ "name": "docs" }
],
"assignee": "hubot"
},
{
"id": 3,
"title": "Ship release",
"state": "closed",
"labels": [
{ "name": "release" }
],
"assignee": "octocat"
}
] |
[3]:
- id: 1
title: Found a bug
state: open
labels[1]{name}:
bug
assignee: monalisa
- id: 2
title: Docs update
state: open
labels[1]{name}:
docs
assignee: hubot
- id: 3
title: Ship release
state: closed
labels[1]{name}:
release
assignee: octocat
|
Override eligible tools with OPENCODE_TOON_PLUGIN_TOOLS:
OPENCODE_TOON_PLUGIN_TOOLS=bash,rtkbun install
bun run test
bun run typecheck
bun run benchMIT
