@cat4869/token-leanOpenCode plugin that reduces repeated OMO task output, safely distills reconstructable background results, and compresses built-in tool descriptions.
0
35
近 7 天 5
28.0
生态多维模型
1 个月前
2026-07-16
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@cat4869/token-lean@0.2.0"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@cat4869/token-lean@0.2.0"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D @cat4869/token-leanopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
token-lean is an OpenCode plugin that reduces avoidable token overhead in OpenCode + Oh My OpenAgent (OMO) workflows.
It focuses on conservative, recoverable cleanup:
- deduplicates repeated OMO reminder blocks;
- cleans completed
taskandbackground_outputparent Parts; - distills large background results only when they can be reconstructed from the child session;
- compresses built-in tool descriptions without changing tool schemas.
If a transformation cannot be proven safe, the plugin keeps the original output.
Compatibility
- Validated with OpenCode
1.18.2, OMO4.18.2, and Bun1.3.14. - Expected floor: OpenCode
>=1.17.15, OMO>=4.16.3.
After upgrading OpenCode or OMO, rerun the test suite and at least one real foreground/background sentinel check.
Installation
npm install @cat4869/token-lean
Add the plugin to your OpenCode config:
{
"plugin": ["@cat4869/token-lean"]
}
For local development, use an explicit file URL:
{
"plugin": ["file:///absolute/path/to/token-lean/src/index.ts"]
}
Configuration
Create config.json beside the plugin:
{
"reminderDedup": true,
"resultCompression": true,
"backgroundResultDistillation": true,
"backgroundDistillMinChars": 10000,
"backgroundDistillMinSavings": 2000,
"runtimeProbe": false,
"toolDescriptionCompress": true
}
Safety
token-lean does not patch OpenCode's SQLite database directly. Runtime writes go through OpenCode plugin Part update APIs.
The child session remains the recovery source. Compressed parent output includes a marker such as:
[result compressed by token-lean, full session: ses_...]
Background distillation is strict: the parent output must be large enough, child messages must be available, and the flattened parent body must match child chunks exactly. Otherwise the output is left unchanged.
Verification
bun run check
bun run test
bun run pack:dry-run
Optional read-only replay against an OpenCode database:
OPENCODE_DB_PATH="$HOME/.local/share/opencode/opencode.db" bun test/historical-replay.ts
For real runtime validation, use OpenCode/OMO foreground and same-process blocking background sentinel checks. Cross-process bg_... retrieval is not treated as a plugin guarantee.
Replay results
One maintainer replay snapshot showed:
- 142 completed
background_outputparts; - 69 distilled;
- 675,117 saved chars;
- 30.15% eligible savings;
- 43.24% changed-output savings.
These numbers are not a guarantee. Savings depend on task shape, OMO formatter behavior, tokenizer, and whether later turns include the optimized Part.