RTK (Rust Token Killer) is a single-binary CLI written in Rust that acts as a command-output rewriting system for AI coding assistants. Its goal is not magic compression but engineering-level filtering of shell output so that tools like Claude Code spend fewer tokens on irrelevant noise. Source: https://github.com/rtk-ai/rtk | Homepage: https://www.rtk-ai.app
Key points
- The problem: In a typical 30-minute Claude Code session, raw output from commands like
git status,cargo test,ls -la,docker psconsumes ~118,000 tokens. After RTK filtering this drops to ~23,900 — an ~80% saving, worth roughly $1–2 per session at Claude 3.5 Sonnet pricing. - Four FilterModes (from
src/core/stream.rs): Streaming (line-by-line real-time filtering), Buffered (process full output after completion), CaptureOnly (for telemetry baselines), and Passthrough (safe fallback for unrecognized commands). - BlockStreamFilter engine: A trait-based handler pipeline (
should_skip,is_block_start,is_block_continuation,format_summary) that works like a compiler's lexer. For example,cargo testhandlers skipCompiling...noise, collect failed-test stack traces, and emit summaries likeFAILED: 2/15 tests. - Engineering safeguards: a 10 MiB hard cap (
RAW_CAP = 10_485_760) on captured output, aChildGuardRAII wrapper thatwait()s children on drop to prevent zombies, and dual reader threads for stdout/stderr merged via mpsc. - Per-ecosystem handlers: A
Languageenum (Rust, Python, JavaScript, TypeScript, Go, C, C++, Java, Ruby, Shell, Data, Unknown) with dedicated modules per toolchain (git, go, js, python, ruby, dotnet, cloud, jvm...) covering 100+ commands — structured understanding of output formats, not regex hard-matching. - Transparent hooks: A PreToolUse-style hook rewrites
git statustortk git statusbefore execution. Exit codes: 0 = Allow (rewritten), 1 = Default (passthrough), 2 = Deny, 3 = Ask (user confirmation). RTK never guesses at commands it doesn't understand. - Token tracking: SQLite database at
~/.local/share/rtk/tracking.db(WAL mode, 90-day cleanup) records input/output tokens, savings percentage, execution time, and project paths.rtk gainreports totals, per-command top 10, timelines, and per-project filtering (usingGLOBinstead ofLIKEto avoid_wildcard pitfalls). Token counts are character-based approximations, sufficient for savings ratios but not billing. - Telemetry: opt-in, anonymous, aggregate-only (category distribution, savings totals, top uncovered commands). Never collects source code, file paths, or secrets;
rtk telemetry forgetrequests server-side deletion. - Not a universal compressor: Claude Code built-in tools (Read, Grep, Glob) bypass the Bash hook entirely.
- Aggressive filtering can lose context useful for debugging. Mitigations: a
teemechanism saves full raw output on failure to~/.local/share/rtk/tee/, and--verboseincreases output detail. - Installation complexity varies: Windows lacks native hook support (WSL only); non-Claude tools may need manual rule files.
- Ecosystem lock-in: deep integration creates dependency, though MIT licensing and simple hook design keep this manageable.
Multi-tool ecosystem
RTK adapts to 13 AI coding tools with different extension points:
| Tool | Hook mechanism | Install |
|------|---------------|---------|
| Claude Code | PreToolUse hook (settings.json) | rtk init -g |
| GitHub Copilot | PreToolUse hook | rtk init -g --copilot |
| Cursor | preToolUse hook (hooks.json) | rtk init -g --agent cursor |
| Gemini CLI | BeforeTool hook | rtk init -g --gemini |
| Codex | AGENTS.md + RTK.md injection | rtk init -g --codex |
| Windsurf | .windsurfrules | rtk init --agent windsurf |
| Cline / Roo Code | .clinerules | rtk init --agent cline |
| OpenCode | TypeScript plugin | rtk init -g --opencode |
| Others | plugin APIs / rule files | see repo docs |
Installation code uses atomic writes (NamedTempFile + persist()), automatic .json.bak backups, migration away from the legacy rtk-rewrite.sh script, and idempotent re-runs.
Limitations and risks
Verdict
RTK is an engineering-grade output-rewriting layer, not a silver bullet: structured per-ecosystem understanding, <10ms streaming latency, transparent interception, safe passthrough fallback, observable savings via SQLite, and cross-tool coverage. For heavy AI-assisted developers, one install can save 60–80% of tokens per session — but for uncovered commands, built-in tool calls, and context-sensitive debugging, it won't help.
Install: brew install rtk or curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh