Rtk
OpenCode v2 plugin that rewrites shell commands through rtk to cut LLM token usage by 60-90%.
0
790
790 in 7 days
37.8
Multi-signal model
2 days ago
2026-10-02
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-rtk-plugin@0.1.3"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-rtk-plugin@0.1.3"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D opencode-rtk-pluginOpenCode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
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.
Similar plugins
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.