Rtk
OpenCode v2 plugin that rewrites shell commands through rtk to cut LLM token usage by 60-90%.
0
790
近 7 天 790
37.8
生态多维模型
2 天前
2026-10-02
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-rtk-plugin@0.1.3"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-rtk-plugin@0.1.3"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-rtk-pluginOpenCode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
An OpenCode v2 plugin that routes every shell command through
rtk, cutting LLM token usage by 60-90% on common dev commands.
OpenCode sends tool output back to the model. rtk compresses that output
(git, grep, ls, test runners, build logs, and more) into a token-efficient
form before the model ever sees it. This plugin wires the two together.
Why
- Smaller context, lower cost. Command output is the biggest hidden token sink in an agent loop.
- No prompt changes. Rewriting happens in the shell hook, transparently.
- Single source of truth. All rewrite rules live in
rtk rewrite; this plugin is a thin delegating adapter, so rules never drift.
Requirements
- OpenCode v2 (
opencode --versionreports 2.x). rtk>= 0.23.0 onPATH— see rtk-ai/rtk:brew install rtk
Install
From npm
opencode plugin add opencode-rtk-plugin
From GitHub
opencode plugin add github:nabheet/opencode-rtk-plugin
Or add it to opencode.json(c) directly:
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["opencode-rtk-plugin"]
}
Manual
Copy this directory to .opencode/plugins/opencode-rtk-plugin/ (project) or
~/.config/opencode/plugins/opencode-rtk-plugin/ (global), then list it:
{
"plugins": [{ "package": "./.opencode/plugins/opencode-rtk-plugin" }]
}
Options
{
"plugins": [
{
"package": "opencode-rtk-plugin",
"options": {
"binary": "rtk",
"timeoutMs": 5000,
"enabled": true
}
}
]
}
| Option | Default | Description |
|---|---|---|
binary |
"rtk" |
Path or name of the rtk executable. |
timeoutMs |
5000 |
Per-rewrite timeout in milliseconds. |
enabled |
true |
Set false to disable the plugin. |
How it works
The plugin registers one OpenCode v2 shell hook:
ctx.shell.hook("create.before", (event) => {
// event.command is the command about to run; mutate it to rewrite
})
For each shell command it runs rtk rewrite <command> and replaces the command
with rtk's output when it differs. If rtk is missing, times out, or errors,
the original command runs unchanged.
Compatibility
- Targets OpenCode v2 (
pluginsconfig +id/setupplugin definition). OpenCode v1 used a different plugin API and is not supported. rtkships hooks for Claude Code, Codex, Cursor, Gemini CLI, Copilot and others. OpenCode is not among them, so this plugin fills that gap.
Prereleases
Every push to a PR publishes an installable beta to the npm beta dist-tag:
opencode plugin add opencode-rtk-plugin@beta
Releases (maintainers)
All publishing happens in GitHub Actions via npm trusted publishing (OIDC provenance). Never publish from a local shell.
.github/workflows/ci.yml is the single workflow file (npm allows one trusted
publisher per package; the workflow filename must stay ci.yml):
test— lint + plugin-export smoke check onmainand PRs (Node 24).- push to
main→publishjob publishes the next patch tolatest, pushes avX.Y.Ztag, and opens a GitHub release. The version is derived from the last publishedlatest, so repeated merges never collide; an intentional minor/major bump inpackage.jsonis honored. - tag
v*-beta*→publishjob publishesbeta+ a prerelease GitHub release. - every PR push →
prereleasejob publishes<version>-beta.<run_number>tobeta(same-repo, non-draft, non-dependabot PRs; re-runs deduped). - manual dispatch → next
-beta.Xstaging publish frommain, no git change.
License
MIT — see LICENSE. rtk itself is Apache-2.0 and is not
bundled or vendored here.
同类生态推荐
Okf Context
opencode-okf-context
OpenCode plugin: progressive disclosure + auto-unload for OKF (Open Knowledge Format) knowledge bundles. Inspired by DCP's outbound-only context transformation.
Headroom
opencode-headroom-plugin
OpenCode v2 plugin that transparently compresses large tool results via Headroom at the message level — works with any provider, including AWS Bedrock.
Cost Guard
opencode-plugin-cost-guard
The opencode cost guard plugin: stop AI token waste. Live session watch, runaway context detection, auto-compaction, spend budgets & alerts, JSONL savings reports. Cuts LLM API spend by capping paid-model context and taming cache replay.