Key Points 3 min read
  • The problem isn't the AI — it's that command output is stuffed with things meaningless to an AI: color escape codes, blank lines, repeated headers, verbose stack traces.
  • RTK intercepts and compresses output before it hits the context, saving 60–90% of tokens on common commands, with under 10ms overhead — a single Rust binary, zero dependencies.
  • It complements 9Router: RTK compresses 'command output' while 9Router handles 'provider routing and cost' — two entirely different dimensions.
Table of Contents

When you write code with Claude Code, a single git diff can eat up thousands of tokens. The problem isn’t that the AI is dumb — it’s that the output itself is full of stuff that means nothing to an AI: color escape codes, blank lines, repeated headers, verbose stack traces. You pay for those tokens all the same, your context window gets filled all the same, and none of it helps the model understand your code.

RTK (Rust Token Killer) takes this angle: it intercepts, filters, and compresses command output before it enters the AI context, then hands a clean version to the LLM. It’s a single Rust binary, zero dependencies, supports 100+ commands, and adds under 10ms of overhead. The project has 66k stars on GitHub, is actively maintained, and is Apache 2.0 licensed.

Design Philosophy: Compress the Noise, Not the Signal

RTK doesn’t mindlessly truncate output — it does semantic compression tailored to each command’s output format: stripping ANSI color codes, collapsing repeated blocks, removing meaningless whitespace, and keeping the parts that actually carry information. For an AI, what matters about git status is “which files changed,” not the pile of formatting and prompt text around it.

The official estimate for a 30-minute Claude Code session (a medium-sized TypeScript / Rust project):

CommandCountOriginal tokensAfter RTKSavings
ls / tree10×2,000400−80%
cat / read20×40,00012,000−70%
grep / rg16,0003,200−80%
git status10×3,000600−80%
git diff10,0002,500−75%
git add/commit/push1,600120−92%
cargo test / npm test25,0002,500−90%
pytest / go test14,0001,400−90%
Total~118,000~23,900−80%

This is an estimate for a medium-sized project; actual savings vary with project size. Overall it lands in the 60–90% range.

Installation and Setup

# Homebrew (recommended)
brew install rtk

# Or one-line install (Linux / macOS)
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh

# Or from source
cargo install --git https://github.com/rtk-ai/rtk

Wire it into your AI coding tool (it writes the right config for each tool):

rtk init -g --copilot     # GitHub Copilot
rtk init -g --claude      # Claude Code
# Same idea for other tools

After that, whenever the tool runs a shell command, the output passes through RTK’s compression before entering the context. Your workflow doesn’t change at all — the AI just sees a cleaner version.

How It Differs from Vector Compression / Provider Routing

RTK solves token waste at the command-output layer, which is easy to confuse with two other things:

  • It is not response compression on the model side, and it doesn’t touch your prompt; it only acts on the “tool output → context” segment.
  • It’s complementary to, not competing with, 9Router: 9Router solves “multi-provider switching and cost” at the request-routing layer, while RTK solves “context getting blown out by noise” at the output layer. Using both together causes no conflict.

A naming note: 9Router ships a compression middleware also called RTK, but that’s 9Router’s own thing — it just happens to share an acronym with this standalone Rust tool.

Who It’s For

Anyone using a CLI-based AI coding tool (Claude Code, Copilot, Codex, Cursor…) who frequently has the AI run commands like git, tests, grep, or docker. The bigger the project and the more often the AI runs commands, the more tokens you save. The cost is near zero: one binary, <10ms overhead, no change to your workflow.

References

Ask this article

Answers come from this article only. Click any prompt below or open the chat at the bottom right.

🇺🇸 English

When you're coding with something like Claude Code, here's a number that might make you wince: a single `git diff` can burn through thousands of tokens. And the frustrating part? It's not because the AI is struggling to understand your code. It's because the output you're feeding it is full of junk that means absolutely nothing to a language model — color escape codes, blank lines, repeated headers, bloated stack traces. You pay for every one of those tokens, your context window fills up with them, and none of it helps the model do its job.

That's the problem a tool called RTK — Rust Token Killer — sets out to solve. And the angle is clever. Instead of touching the AI or your prompts, it sits in between. It intercepts command output, filters it, and compresses it *before* it ever reaches the AI context. Then it hands the model a clean version. It's a single Rust binary, zero dependencies, supports over a hundred commands, and adds less than ten milliseconds of overhead. The project's sitting at 66,000 stars on GitHub, it's actively maintained, and it's Apache 2.0 licensed.

So let's talk about the philosophy here, because it's the whole point. RTK is *not* mindlessly chopping off the end of your output. It does what you might call semantic compression — it understands each command's output format and tailors the cleanup. It strips ANSI color codes, collapses repeated blocks, removes meaningless whitespace, and keeps the parts that actually carry information. Think about it this way: when an AI looks at `git status`, the thing that matters is "which files changed." Not the wall of formatting and prompt text wrapped around it.

Now, what does that actually save you? The team put together an estimate for a 30-minute Claude Code session on a medium-sized TypeScript or Rust project, and the numbers are pretty striking. Listing files with `ls` and `tree` drops by about 80 percent. Reading files with `cat` — around 70 percent. Searching with `grep` — 80 percent. The git commands are where it gets dramatic: `git status` down 80 percent, `git diff` down 75, and the add-commit-push cycle compressed by a staggering 92 percent. And the test runners — `cargo test`, `npm test`, `pytest`, `go test` — those get slashed by 90 percent, which makes sense when you picture how noisy test output normally is.

Add it all up, and that session goes from roughly 118,000 tokens down to about 23,900. That's an 80 percent cut. Now, the honest caveat: this is an estimate, and real savings depend on your project size. Overall it lands somewhere in the 60 to 90 percent range — but either way, it's substantial.

Getting it running is genuinely simple. If you're on a Mac, `brew install rtk` and you're done. There's also a one-line curl install script for Linux and macOS, or you can build it from source with cargo. Then you wire it into your AI tool — and RTK writes the correct config for each one automatically. There's a flag for GitHub Copilot, a flag for Claude Code, and the same idea for the other tools. After that, your workflow doesn't change at all. Every time the tool runs a shell command, the output quietly passes through RTK's compression before hitting the context. The AI just sees a cleaner version, and you don't have to think about it.

One thing worth clearing up, because it's easy to get confused: RTK operates at the *command-output* layer, and that's a specific spot in the pipeline. It is not response compression on the model's side — it doesn't touch your prompt at all. It only acts on that one segment, the journey from tool output into context. And it's worth contrasting it with something like 9Router, which solves a different problem entirely. 9Router works at the request-routing layer — it's about switching between multiple providers and managing cost. RTK works at the output layer — it's about your context getting blown out by noise. They're complementary, not competing. You can run both together with no conflict. Quick naming heads-up, though: 9Router actually ships its own compression middleware that *also* happens to be called RTK. Different thing. They just share an acronym.

So who's this actually for? Anyone using a CLI-based AI coding tool — Claude Code, Copilot, Codex, Cursor — who regularly has the AI run commands like git, tests, grep, or docker. And here's the rule of thumb: the bigger your project and the more often the AI reaches for the command line, the more you save. The cost of finding out is basically nothing — one binary, under ten milliseconds of overhead, no change to how you work.

So let me leave you with the three things worth holding onto. First: the waste isn't the AI's fault — it's the formatting noise in command output, and RTK kills it at the source before it ever costs you a token. Second: the savings are real and large, on the order of 60 to 90 percent, with the heaviest wins coming from test runs and git operations. And third: it's a zero-friction add — install it, point it at your tool once, and your workflow stays exactly the same while your context window suddenly breathes a lot easier. If you're paying for tokens and letting an AI drive your terminal, this is about as close to free money as it gets.

🇹🇼 中文

裝一個 Rust 寫的小工具,就能讓你的 AI coding 助手少吃六到九成的 token——這就是今天要聊的 RTK,全名 Rust Token Killer。

先說問題出在哪。你用 Claude Code 寫程式,光是跑一次 git diff,就可能吃掉好幾千個 token。但這不是因為 AI 笨,而是指令輸出本身塞滿了對模型毫無意義的東西——終端機的顏色控制碼、一堆空白行、重複的標頭、又臭又長的 stack trace。這些東西你照樣付費、context window 照樣被佔滿,可是對模型理解你的程式碼,一點幫助都沒有。

RTK 的切入點很聰明:它在命令輸出「進入 AI context 之前」就先攔截、過濾、壓縮,然後把乾淨的版本才交給模型。它是單一一顆 Rust binary、零依賴、支援超過一百種指令,而且 overhead 低於十毫秒。專案在 GitHub 上有六萬六千顆星,更新很活躍,採 Apache 2.0 授權。

來談談它的設計哲學,這是關鍵:RTK 壓的是「噪音」,不是「訊息」。它不是無腦把輸出截斷,而是針對每一種指令的輸出格式做語意壓縮——去掉 ANSI 顏色碼、把重複的區塊摺疊起來、移除沒意義的空白,但真正有資訊量的部分完整保留。換個角度想,對 AI 來說,git status 真正重要的是「哪些檔案被改了」,而不是那一堆排版跟提示文字。

官方有給一組估算,情境是一段三十分鐘的 Claude Code session,跑在一個中型的 TypeScript 或 Rust 專案上。整體效果大概是這樣:列檔案的 ls、tree 這類大約省八成;讀檔案的 cat、read 省七成;跑測試的部分最誇張——cargo test、npm test、pytest、go test 這些通常省到九成,因為測試輸出最囉嗦;而 git add、commit、push 這種,幾乎省到九成二。整段加起來,原本大約十一萬八千 token,壓到大約兩萬三千九,整體掉了八成。當然這是中型專案的估算,實際省多少看你專案大小,但大致都落在六到九成這個區間。

安裝也很簡單。Mac 上推薦用 Homebrew,一行 brew install rtk 就好;Linux 跟 macOS 也可以用官方的一行 curl 安裝腳本;或者你想從原始碼裝,用 cargo install 指定 git 倉庫也行。

接到 AI 工具上更省事。它有個 rtk init 指令,加上對應的旗標——像 dash dash claude 就是接 Claude Code、dash dash copilot 就是接 GitHub Copilot——它會幫你把設定寫好。接好之後,工具呼叫 shell 指令時,輸出會自動先經過 RTK 壓縮才進 context。你的工作流程完全不用改,唯一的差別是 AI 看到的版本變乾淨了。

這裡要特別澄清一個容易混淆的地方:RTK 解的是「指令輸出層」的浪費,它跟兩件事不一樣。第一,它不是 model 端的回應壓縮,也不會去動你的 prompt,它只管「工具輸出到 context」這一段。第二,它跟 9Router 是互補的,不是競爭關係——9Router 處理的是「請求路由層」,解決多 provider 切換跟成本的問題;RTK 處理的是「輸出層」,解決 context 被噪音撐爆。兩個一起用沒有任何衝突。

不過有個命名上的小陷阱要提醒你:9Router 內建一個剛好也叫 RTK 的壓縮 middleware,但那是 9Router 自己家的東西,跟我們今天講的這個獨立 Rust 工具,只是縮寫剛好撞名,別搞混了。

那誰適合用?簡單說,只要你用的是 CLI 形式的 AI coding 工具——Claude Code、Copilot、Codex、Cursor 都算——而且常讓 AI 去跑 git、跑測試、跑 grep、跑 docker 這些指令,那就值得裝。專案越大、AI 跑指令越頻繁,省下的 token 就越可觀。

最後幫你收三個重點。第一,RTK 的核心是在指令輸出進入 context 之前先做語意壓縮,砍掉顏色碼、重複跟空白這些噪音,但保留真正的訊息,所以能省六到九成 token。第二,它的代價幾乎是零——一顆 binary、十毫秒以內的 overhead,而且你的工作流程完全不變。第三,記住它的定位:它動的是「輸出層」,跟改 prompt 或做 provider 路由是不同層次的事,可以跟那些工具搭著一起用。如果你每天都在燒 token 跟 AI 寫程式,這個工具很值得花五分鐘裝起來試試。

Tags

Related Articles

RAG's Five Stages: From Pipeline to Reasoning Retrieval, and the Naive RAG on My Own Site

Over the past two years RAG evolved from a 'linear pipeline' to 'loop-based reasoning'. It maps cleanly to five stages: Naive, Advanced, Modular, Graph, Agentic. The real inflection point is control moving from pipeline to agent — a System 1 → System 2 shift. Looking back at engineer-news's own RAG stack, it's stuck at the Naive edge — so this post also lays out what to fix next.

Building a Real RAG: 5 Infra Lessons from InfiniFlow's 2024 Year-in-Review

The previous post zoomed out for a five-stage panorama of RAG. This one zooms in on the five infra lessons any real RAG has to face: document ingestion, contextualized chunking, three-lane hybrid search, tensor reranker, and GraphRAG's semantic gap. Each lesson is checked against engineer-news's current stack, ending with a priority list for a personal site.