Skip to content

Use RTK to Reduce Token Usage

Use the RTK Rust CLI proxy to compress common command output before it reaches your coding agent, cutting tokens on dev work.

Artikel ini belum diterjemahkan. Isi berikut berbahasa Inggris. Buka versi asli bahasa Inggris.

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

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

Examples:

  • git status → rtk git status
  • git diff → rtk git diff
  • ls → rtk ls
  • rg pattern . → rtk grep pattern .

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

Install RTK

Choose one method.

brew install rtk

Script install (Linux/macOS)

curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh

Verify installation

rtk --version
rtk gain

Set up RTK in OpenCode

Install the global OpenCode plugin:

rtk init -g --opencode

This creates:

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

Then restart OpenCode.

Validate that OpenCode hook is active

After restart, run a few normal commands in OpenCode:

git status
git diff
ls

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

Use these checks as well:

rtk init --show
rtk gain --history

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

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

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

Ketik untuk mencari…

↑↓ navigasi↵ pilihEsc tutup