Skip to content
Client Panel

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.

RTK can integrate with OpenCode through an OpenCode plugin hook and rewrite Bash commands to rtk ... equivalents automatically.

Examples:

  • git statusrtk git status
  • git diffrtk git diff
  • lsrtk ls
  • rg pattern .rtk grep pattern .

That means you keep the same command habits while sending denser, less noisy output to the model.

Choose one method.

Terminal window
brew install rtk
Terminal window
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
Terminal window
rtk --version
rtk gain

Install the global OpenCode plugin:

Terminal window
rtk init -g --opencode

This creates:

  • ~/.config/opencode/plugins/rtk.ts

Then restart OpenCode.

After restart, run a few normal commands in OpenCode:

Terminal window
git status
git diff
ls

If RTK is hooked correctly, these commands are rewritten internally and produce compact summaries.

Use these checks as well:

Terminal window
rtk init --show
rtk gain --history

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" .

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.

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.