AI & AUTOMATION

rtk (Rust Token Killer): The Blazing-Fast CLI Proxy That Slashes LLM Token Costs by 60–90%

Key Takeaways:

rtk is a single-binary Rust CLI proxy that filters and compresses command output, routinely cutting LLM token usage by 60–90% on everyday dev workflows.

What rtk Is and Why It Matters

rtk (Rust Token Killer) is an open-source CLI proxy that sits between your AI coding agent and the shell, transforming noisy command output into compact, LLM-friendly summaries. It is designed specifically to reduce token consumption for tools like Claude Code, GitHub Copilot-style agents, Cursor, and similar AI-assisted development environments.

Instead of letting commands like git status, ls, docker ps, or pytest dump thousands of characters into your model’s context, rtk intercepts the output, filters noise, groups related items, truncates irrelevant parts, and deduplicates content before passing it on. In typical 30‑minute AI coding sessions, teams report drops from around 150,000 tokens to roughly 45,000 tokens, which is about a 70% reduction in usage and cost.

Under the hood, rtk is a single Rust binary with zero external runtime dependencies, which makes it extremely fast to start, easy to ship, and simple to deploy across macOS, Linux, and Windows. It uses rusqlite with the bundled feature so you do not need a system-wide SQLite installation, further reinforcing the “drop-in binary” experience for DevOps teams.

  Without rtk:                                    With rtk:

  Claude  --git status-->  shell  -->  git         Claude  --git status-->  RTK  -->  git
    ^                                   |            ^                      |          |
    |        ~2,000 tokens (raw)        |            |   ~200 tokens        | filter   |
    +-----------------------------------+            +------- (filtered) ---+----------+

How rtk Reduces Tokens by 60–90%

At a high level, rtk plugs into your AI coding setup as a transparent proxy: the agent thinks it is running standard shell commands, but a hook rewrites them to rtk <command> equivalents. For example, a git status issued by Claude Code can silently become rtk git status, and only the condensed output is sent back to the LLM.

The token savings are driven by a few key strategies:

  • Smart filtering of unimportant lines (e.g., boilerplate, unchanged files).
  • Grouping repeated patterns (e.g., long lists of similar items).
  • Truncation of overly long outputs while preserving high-signal sections.
  • Deduplication to avoid re-sending the same context over and over.

Benchmarks from the project show savings in the 60–90% range on common operations like ls, cat, grep, git status, git diff, test commands (npm test, cargo test, pytest, go test), and container commands like docker ps. In some aggregated measurements, total tokens for a multi-command session dropped by around 80%, making a tangible impact on both cost and latency.

rtk’s Single-Binary Rust Architecture

Because rtk is written in Rust and compiled to a single static binary, you do not need to manage a Python environment, Node runtime, or additional dynamic libraries on your CI servers or developer machines. This single-binary design aligns well with containerized workflows and minimal base images where every dependency matters.

The build uses Rust 1.70 or later (2021 edition) and bundles its own SQLite via rusqlite’s bundled feature, which avoids fragile system-level dependencies. For teams managing large fleets of dev containers or remote coding environments, this combination of performance, portability, and low operational overhead is a major advantage.

Installation Guide: macOS, Linux, and Windows

This section walks through practical installation paths, from package managers to building from source.

Option 1: Install via Package Manager (e.g., Homebrew on macOS)

If you are on macOS and use Homebrew, you can install rtk with a single command:

# macOS with Homebrew
brew install rtk

After installation, verify that the binary is on your PATH and working:

rtk --version
rtk gain

If rtk gain runs and shows token statistics instead of “command not found,” your CLI proxy binary is installed correctly.

For Rust developers or any environment with cargo available, you can install directly from the official GitHub repository:

# Install latest from upstream
cargo install --git https://github.com/rtk-ai/rtk

# Or, if available on crates.io
cargo install rtk

# Verify installation
rtk --version
rtk gain

These commands download the code, compile it, and drop the rtk binary into your standard Cargo bin directory (typically ~/.cargo/bin).

Option 3: Build from Source (Dev/CI Workflows)

If you want more control or plan to contribute, you can clone and build rtk yourself:

# Clone the repository
git clone https://github.com/rtk-ai/rtk.git
cd rtk

# Development build (fast compile, slower runtime)
cargo build
./target/debug/rtk --version

# Local installation from source
cargo install --path .
rtk --version
rtk gain

For optimized release builds, especially for production images, use the release profile:

# Optimized release binary
cargo build --release
./target/release/rtk --version

# Optional: install release binary into Cargo bin
cargo install --path . --release

Across macOS, Linux, and Windows, you mainly need the Rust toolchain plus standard build tools (Xcode CLT on macOS, build-essential on Debian/Ubuntu, or an MSVC toolchain on Windows) to compile rtk successfully.

Initial Setup with AI Coding Tools

rtk is designed to integrate with popular AI coding tools using hooks that transparently rewrite shell commands. The standard workflow is:

Global Hook Setup (Claude Code and Friends)

For Claude Code and other hook-friendly agents, you typically run:

# Initialize rtk globally (recommended)
rtk init -g

This command does several things for you:

  • Installs a hook script under your Claude settings directory (for example, ~/.claude/hooks/rtk-rewrite.sh).
  • Creates a compact RTK.md file (~10 lines) that documents the meta commands with minimal token footprint.
  • Adds an @RTK.md reference into your main CLAUDE.md, so the agent knows about rtk commands.
  • Offers to patch settings.json automatically, including creating a backup before modification.

You can inspect the status at any time:

rtk init --show

For users of other agents (e.g., Cursor or Gemini-based CLIs), there are flags like --gemini or --agent cursor that tailor the integration to each environment, while still relying on the same core hook-and-rewrite mechanism.

Once the hook is in place and your AI assistant restarts, commands like git status or docker ps issued from the AI’s terminal context will automatically be executed via rtk instead.

Practical Usage: Proxying Common Dev Commands

With installation and hooks complete, you can start using rtk directly or let your AI agent drive it.

Manual Usage in Your Own Shell

You can explicitly prefix commands with rtk to see how it behaves:

# Compact git status
rtk git status

# Condensed directory listing
rtk ls -la

# Filtered test output
rtk pytest tests/unit/

# Summarized container state
rtk docker ps

Instead of the raw, verbose outputs, rtk returns dense summaries focusing on what an LLM actually needs (e.g., list of changed files, failing tests, or running containers). For example, where git status might print dozens of lines of hints and branch info, rtk git status can compress this down to a concise list such as only tracked modified files and a short summary line.

Letting Hooks Rewrite Commands Automatically

In most AI coding setups, you never type rtk yourself; the hook does it:

  1. Claude Code (or another agent) issues git status.
  2. The hook rewrites it to rtk git status.
  3. rtk executes git status under the hood, compresses the output, and forwards the slimmed-down content to the LLM.

This pattern applies across a wide range of commands: ls, tree, cat, grep, rg, git diff, npm test, cargo test, pytest, go test, docker ps, and more. Because these are exactly the commands that AI coding agents spam repeatedly, squeezing them by 60–90% has an outsized impact on token budgets over the course of a day.

Measuring Token Savings with rtk

rtk includes observability features so you can quantify results instead of guessing.

Run rtk gain to see statistics on how many tokens you would have spent without compression versus how many were actually sent through the proxy. These reports typically show per-command savings as well as totals for a session, making it easy to justify adoption to your team or leadership.

Another helpful command is rtk discover, which analyzes your command history or logs to highlight opportunities where rtk was not used but could have saved substantial tokens. This is particularly valuable in hybrid environments where some workflows are already optimized while others still rely on raw shell output.

In concrete benchmarks published by the project and community, common workflows show:

  • ls / tree: roughly 80% fewer tokens.
  • cat / read of large files: around 70% fewer tokens.
  • git status, git diff, and git log: typically 75–80% fewer tokens.
  • Test commands and container operations often land near 80–90% savings.

Where to Learn More and Contribute

The canonical source of truth for rtk is the official GitHub repository at rtk-ai/rtk, which includes documentation, installation instructions, hooks, and examples tailored to different AI coding tools. You can explore the project, open issues, and contribute via:

  • Official GitHub repo: https://github.com/rtk-ai/rtk
  • Build and contributing docs (including source builds and profiles): linked from the same repository and its documentation site.

Because rtk is open-source and written in Rust, it is well suited for customization—whether you want to tweak compression rules for your specific stack, add new command integrations, or extend the analytics pipeline. For organizations running large fleets of AI coding agents, small contributions upstream can translate into substantial cost and performance wins across the entire developer base.

You may also like

Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted