RTK: The Complete Guide to CLI Token Optimization for AI Coding
Every time your AI coding agent runs git status, cargo test, or ls -la, it feeds hundreds or thousands of tokens of raw output into the LLM context window — most of it noise. RTK (Rust Token Killer) fixes this. With 3,800+ GitHub stars and growing fast, RTK is a high-performance CLI proxy that reduces LLM token consumption by 60-90% on common developer commands. Single Rust binary, zero dependencies, <10ms overhead.
What Is RTK?
RTK sits between your AI coding agent (Claude Code, Cursor, Codex, etc.) and the shell. It intercepts command outputs, filters out noise, compresses the results, and returns only what the LLM needs.
The result: Your LLM gets the same actionable information in 10-90% fewer tokens.
Without RTK: With RTK:
Claude --git status--> shell --> git Claude --git status--> RTK --> git
^ | ^ |
| ~2,000 tokens | | ~200 tokens |
+-----(raw output)---+ +---(filtered)-------+
- Language: Rust
- License: MIT
- Stars: 3,800+ ⭐
- Releases: 48
- Zero dependencies, single binary
How It Works: Four Strategies
RTK applies four compression strategies per command type:
1. Smart Filtering
Removes noise — comments, whitespace, boilerplate, progress bars, ASCII art.
2. Grouping
Aggregates similar items — files by directory, errors by type, warnings by rule.
3. Truncation
Keeps relevant context, cuts redundancy — only failing tests shown, not all passing ones.
4. Deduplication
Collapses repeated log lines with counts — [repeated 47 times] instead of 47 identical lines.
Token Savings in Practice
| Command | Without RTK | With RTK | Savings |
|---|---|---|---|
ls -la | ~800 tokens (45 lines) | ~150 tokens (12 lines) | 81% |
git push | ~200 tokens (15 lines) | ~10 tokens (1 line: ok main) | 95% |
git status | ~2,000 tokens | ~200 tokens | 90% |
cargo test (failure) | 200+ lines | ~20 lines (failures only) | 90% |
npm test | verbose output | failures only | 90% |
git diff | full diff | condensed diff | 80% |
ruff check | full lint output | JSON grouped | 80% |
docker ps | full table | compact list | 75% |
Users report 83.7% average reduction across 7,000+ commands in real-world sessions.
Supported Commands
RTK supports 30+ command categories:
Files
rtk ls . # Token-optimized directory tree
rtk read file.rs # Smart file reading
rtk read file.rs -l aggressive # Signatures only
rtk smart file.rs # 2-line heuristic summary
rtk find "*.rs" . # Compact find results
rtk grep "pattern" . # Grouped search results
Git
rtk git status # Compact status
rtk git log -n 10 # One-line commits
rtk git diff # Condensed diff
rtk git add # -> "ok"
rtk git commit -m "msg" # -> "ok abc1234"
rtk git push # -> "ok main"
GitHub CLI
rtk gh pr list # Compact PR listing
rtk gh pr view 42 # PR details + checks
rtk gh issue list # Compact issue listing
Test Runners
rtk test cargo test # Failures only (-90%)
rtk pytest # Python tests (-90%)
rtk go test # Go tests (-90%)
rtk vitest run # Vitest compact
rtk playwright test # E2E failures only
Build & Lint
rtk tsc # TypeScript errors grouped
rtk lint # ESLint grouped by rule/file
rtk cargo build # Cargo build (-80%)
rtk cargo clippy # Cargo clippy (-80%)
rtk ruff check # Python linting (-80%)
rtk next build # Next.js build compact
Package Managers, Containers, Data
rtk pnpm list # Compact dependency tree
rtk pip list # Python packages
rtk docker ps # Compact container list
rtk kubectl pods # Compact pod list
rtk json config.json # Structure without values
rtk curl <url> # Auto-detect JSON + schema
Installation
Homebrew (Recommended)
brew install rtk
Quick Install (Linux/macOS)
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
Cargo
cargo install --git https://github.com/rtk-ai/rtk
Pre-built Binaries
Available for macOS (x86/ARM), Linux (x86/ARM), and Windows from the releases page.
Auto-Rewrite Hook (Recommended)
The killer feature — a transparent hook that automatically rewrites commands:
rtk init --global # Install hook
# Restart Claude Code
# Now: git status -> automatically becomes rtk git status
Claude never sees the rewrite. It just gets compressed output. 100% adoption across all conversations and subagents, zero manual effort.
Commands auto-rewritten: git, gh, cargo, cat/head/tail, rg/grep, ls, vitest/jest, tsc, eslint/biome, prettier, playwright, prisma, ruff, pytest, pip, go, golangci-lint, docker, kubectl, curl, pnpm.
Token Savings Analytics
RTK tracks your savings:
rtk gain # Summary stats
rtk gain --graph # ASCII graph (last 30 days)
rtk gain --history # Recent command history
rtk gain --daily # Day-by-day breakdown
rtk discover # Find missed savings opportunities
Configuration
Config file at ~/.config/rtk/config.toml:
[hooks]
exclude_commands = ["curl", "playwright"] # skip rewrite
[tee]
enabled = true # save raw output on failure
mode = "failures" # "failures", "always", or "never"
max_files = 20 # rotation limit
Tee: Full Output Recovery — When a command fails, RTK saves the full unfiltered output so the LLM can read it without re-executing.
RTK vs Alternatives
Category: This tool is a CLI tool for reducing LLM token consumption on developer commands.
| Feature | RTK | Repomix |
|---|---|---|
| Focus | CLI command output compression | Codebase packing into single file |
| Stars | 3.8K ⭐ | 22.3K ⭐ |
| License | MIT | MIT |
| Language | Rust (single binary, zero deps) | TypeScript (Node.js) |
| What It Compresses | 30+ CLI commands (git, tests, lint, docker...) | Entire repo into AI-friendly file |
| Compression Target | Terminal output → LLM context | Codebase → single prompt |
| Token Reduction | 60-90% (per command) | ~70% (Tree-sitter code compression) |
| Overhead | <10ms per command | One-time packing |
| Auto-Rewrite Hook | ✅ Transparent command interception | ❌ Manual usage |
| Real-Time | ✅ Every command, every session | ❌ Batch/one-time |
| Analytics | ✅ rtk gain (savings tracking, graphs) | Token count per file |
| Test Output | ✅ Failures only (-90%) | N/A |
| Git Operations | ✅ Status/diff/log/push/pull | N/A |
| Docker/K8s | ✅ | N/A |
| Tee Recovery | ✅ Full output on failure | N/A |
| MCP Support | ❌ | ✅ MCP server |
When to choose RTK: You use an AI coding agent (Claude Code, Cursor, Codex) daily and want to automatically reduce token consumption on every shell command — git, tests, builds, linting, docker, kubectl. The auto-rewrite hook means zero effort after setup. Rust binary = blazing fast, zero dependencies.
When to choose Repomix: You want to pack your entire codebase into a single AI-friendly file for one-shot prompts or conversations. Great for feeding a whole project into Claude/ChatGPT. Tree-sitter-based code compression. Different approach: batch codebase packing vs. real-time command compression.
They're complementary: Use RTK for real-time command output compression during agentic coding sessions, and Repomix when you need to feed your full codebase into an LLM prompt.
Conclusion
RTK solves a real, often overlooked problem: the majority of tokens your AI coding agent consumes aren't your code or prompts — they're verbose CLI output. With 60-90% token reduction across 30+ commands, a transparent auto-rewrite hook, built-in analytics, and <10ms overhead from a single Rust binary, RTK is the simplest way to cut your AI coding costs. Install it once with brew install rtk, run rtk init --global, and forget about it.
