DEV Community

Cover image for ๐Ÿฆ€ Stop Paying for Noise: How RTK Cuts Claude Code's Token Bill by Up to 90%
Vishnu Damwala
Vishnu Damwala

Posted on • Originally published at meshworld.in

๐Ÿฆ€ Stop Paying for Noise: How RTK Cuts Claude Code's Token Bill by Up to 90%

AI terminal agents like Claude Code, Aider, and Gemini CLI are revolutionizing developer workflows. However, running shell commands through these agents is a massive source of context window pollution.

When an agent runs a command (e.g., npm install --verbose or cargo build), the output streams hundreds of lines of progress bars, registry fetches, compile dot indicators, and ANSI escape codes into the LLM. You are charged for every single line of this noise, and it pollutes the context window, causing the LLM to lose focus.

Introducing RTK (Rust Token Killer)

RTK is a zero-dependency CLI proxy written in Rust that intercepts Bash tool commands in your AI agent's tool lifecycle, compresses the output, and feeds clean, semantically dense output to the LLM.

It achieves 60โ€“90% token savings per tool call with less than 10ms of overhead.

The 4 Compression Strategies

  1. Smart Filtering: Strips out ANSI terminal escape codes, carriage-return animation overrides, spinner characters, and empty lines.
  2. Dynamic Grouping: Sequences of identical log outputs are collapsed (e.g., [120 identical lines: "PASS"]).
  3. Truncation: Outputs are intelligently capped to preserve the first few lines, the last lines (where errors appear), and a middle summary.
  4. Deduplication: Repeated stack trace frames are consolidated to preserve clean debugging signals.

RTK gain command output showing total tokens saved and cost reduction across a week of development with Claude Code.

Pro Tips & Caveats

  • Bash Tool Calls Only: The automatic global hook (rtk init -g) only wraps shell commands. Claude Code's native file tools (like Read, Grep, Edit) bypass the hook. Use terminal commands (like cat or rg) to ensure outputs are compressed.
  • Crates.io Naming Collision: The rtk crate name on crates.io points to an unrelated "Rust Type Kit" library. To install the token killer, install directly from the source:
  cargo install --git https://github.com/rtk-ai/rtk.git
Enter fullscreen mode Exit fullscreen mode
  • Fail-Safe Tee Logs: On command failure, RTK writes the full raw logs to ~/.local/share/rtk/tee/ so you can debug without losing details.

Read the complete setup guide, benchmarks, and configuration steps on MeshWorld

Top comments (0)