Use RTK to Reduce Token Usage
rtk-ai/rtk is a Rust CLI proxy that compresses common command outputs before they are sent to your coding agent context.
In practical OpenCode sessions, this can reduce prompt/context token usage significantly on repetitive commands like git status, git diff, ls, grep, test runners, and build logs.
What RTK does in OpenCode
Section titled “What RTK does in OpenCode”RTK can integrate with OpenCode through an OpenCode plugin hook and rewrite Bash commands to rtk ... equivalents automatically.
Examples:
git status→rtk git statusgit diff→rtk git diffls→rtk lsrg pattern .→rtk grep pattern .
That means you keep the same command habits while sending denser, less noisy output to the model.
Install RTK
Section titled “Install RTK”Choose one method.
Homebrew (recommended on macOS)
Section titled “Homebrew (recommended on macOS)”brew install rtkScript install (Linux/macOS)
Section titled “Script install (Linux/macOS)”curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | shVerify installation
Section titled “Verify installation”rtk --versionrtk gainSet up RTK in OpenCode
Section titled “Set up RTK in OpenCode”Install the global OpenCode plugin:
rtk init -g --opencodeThis creates:
~/.config/opencode/plugins/rtk.ts
Then restart OpenCode.
Validate that OpenCode hook is active
Section titled “Validate that OpenCode hook is active”After restart, run a few normal commands in OpenCode:
git statusgit difflsIf RTK is hooked correctly, these commands are rewritten internally and produce compact summaries.
Use these checks as well:
rtk init --showrtk gain --historyImportant limitation
Section titled “Important limitation”The OpenCode plugin hook applies to Bash tool execution only. Built-in non-Bash tools (for example native file readers/searchers) are not rewritten by this hook.
If you want RTK compaction for those workflows, use shell commands or explicit RTK commands such as:
rtk read <file>rtk grep <pattern> <path>rtk find "*.ts" .
Optional tuning
Section titled “Optional tuning”RTK supports config tuning in ~/.config/rtk/config.toml (or macOS app support path), including:
- rewrite exclusions (
hooks.exclude_commands) - tee/full-output capture behavior for failures
- tracking database location
This is useful if you want RTK in most places but need raw output for specific commands.
When to use RTK in this docs stack
Section titled “When to use RTK in this docs stack”RTK is most useful when you frequently run command-heavy coding sessions and want to reduce token burn without changing your normal terminal habits.
If your sessions are mostly short or rely heavily on OpenCode built-in non-Bash tools, the impact will be smaller.
References
Section titled “References”- RTK repository: https://github.com/rtk-ai/rtk
- RTK install docs: https://github.com/rtk-ai/rtk/blob/master/INSTALL.md
- OpenCode plugin docs: https://open-code.ai/en/docs/plugins