Tools #AI Agents #Claude Code #Productivity #Rust

RTK Terminal Token Reducer Installation and Hands-on Test: Cut Claude Code Costs by Over 70%

RTK (Rust Token Killer) is a high-performance Rust-based CLI proxy tool that automatically filters and compresses terminal output, saving 60-90% of token usage for AI-assisted development.

5 min read/ Medium

Introduction: Why Do We Need to Compress Terminal Output?

When using AI tools such as Claude Code, Cursor, or Cline, the AI often needs to run commands like git status, npm list, or test suites. The raw output from these commands usually includes lots of repeated logs, unnecessary whitespace, and prompt text.

All of that noise gets pushed into the LLM context without missing a single character. This does not just cause token usage to spike, which raises cost, but also slows down AI responses and can even interfere with the AI's judgment.

RTK (Rust Token Killer) works as a proxy between the terminal and AI tools. Before output is sent to the LLM, it performs aggressive filtering and compression. In my tests, it can save 60% to 90% of token usage.


📈 Test Results: Directly Saved 72% of Tokens

While developing this site, just running the most basic ls and git status commands already let RTK save us 72% of token usage:

RTK 節省 Token 效果

Savings shown after running rtk gain

Across common day-to-day development commands, RTK's token reduction is quite noticeable:

CommandRaw Output Characters / Token CountAfter RTK CompressionSavings Ratio (Reduction)
vitest (when tests fail)102,199 characters377 characters-99.6%
git status529 characters217 characters-59.0%
pnpm list~8,000 tokens~2,400 tokens-70.0%
cargo test / pytest25,000 tokens2,500 tokens-90.0%

Over longer use, a 30-minute AI coding session can bring total token usage down from 150,000 to around 45,000. API cost drops to roughly 30% of the original, and AI response speed improves a lot as well.

Quick Reference for Common Optimized Commands

Even without relying on automatic rewriting, you can manually tell the AI to use rtk commands in the conversation:

  • Tree-style directory structure (automatically hides noise such as node_modules):
    bash
    rtk ls .
    
  • Smart file reading and code compression:
    bash
    rtk read src/App.tsx
    
  • Extract signatures only (shows only class and function definitions, without implementation details; saves the most tokens):
    bash
    rtk read src/utils.ts -l aggressive
    
  • Condensed test output (automatically intercepts stdout; passing tests only show ok, while failures extract only the failed assertion):
    bash
    rtk test cargo test
    

⚠️ Pitfall Guide: Installing the Right RTK Matters

!WARNINGThere are two completely different projects on crates.io named rtk:

  1. Rust Token Killer (this project) - an LLM terminal token optimizer (repository: rtk-ai/rtk)
  2. Rust Type Kit (another project) - a code structure query and type generation tool (repository: reachingforthejack/rtk)

Before installation or while using it, the AI assistant should always verify that the correct version is installed:

bash
# Check version
rtk --version

# Key check: verify that the token statistics command runs correctly
rtk gain
  • If rtk gain successfully shows a statistics table, it is correct. If it fails but still shows a version number, you installed the wrong Rust Type Kit. Run cargo uninstall rtk first to remove it.

Installation and Global Setup

1. Install the Correct Rust Token Killer

On macOS or Linux, I recommend installing it with Homebrew or the quick script:

bash
# Method A: Install with Homebrew (recommended)
brew install rtk

# Method B: Install with the quick script
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh

# Method C: Build from Git source (avoids the crates.io name conflict)
cargo install --git https://github.com/rtk-ai/rtk

2. Global Auto-Rewrite Hook

To let an AI Agent automatically apply RTK when running commands, such as rewriting git status into rtk git status, we can install the global hook:

bash
rtk init -g

💡 The system will prompt Patch settings.json? [y/N]. Enter y. This writes the PreToolUse interceptor into Claude Code's settings file and automatically creates a backup at ~/.claude/settings.json.bak. Restart Claude Code and it will take effect.


💻 Windows / WSL Compatibility Notes

!IMPORTANTWindows users should note these compatibility limits:

  • WSL (fully supported): Works the same as Linux and supports the auto-rewrite Hook.
  • Native Windows (partially supported): The auto-rewrite Hook does not work. Initialization falls back to CLAUDE.md instruction guidance mode, and users need to manually add the rtk prefix in the terminal, such as rtk git status. (Do not double-click rtk.exe; it is only meant to be called from the CLI.)

💡 AI Assistant Checklist

As an AI assistant, follow these checks before running commands:

  • Check installation: Use rtk --version to check availability, and use rtk gain to verify that it is the correct Token Killer.
  • Initialize the project: If it has not been initialized yet, run rtk init.
  • Run through the proxy: For commands that produce verbose output, such as git, pnpm, test runners, and so on, always use rtk as the proxy.

Golden Rule: The AI assistant should proactively use rtk to proxy all highly verbose terminal commands, keeping the context window clean and efficient.