Steven Gonsalvez

Software Engineer

FreeToken Saving|

rtk + Headroom: Trim at the Shell, Compress on the Wire

Two token trimmers that stack: rtk is a Rust CLI proxy that filters dev-command output at the shell (60-90% off ls, grep, git, tests), and Headroom is a local compression proxy that compresses tool output, logs, files and RAG chunks on the wire, with CacheAligner to protect your prompt cache. Real numbers from two days of use.

Visit tool →

sketchnote: rtk trims at the shell - git status, tests, JSON, bash hook, failures only, big output to small

Half your agent's context goes on output nobody reads. A cargo test run is 25,000 tokens of green dots. git status is 2,000 tokens to say "three files changed". The agent only needs the failures and the filenames, but it pays for the whole dump every time.

There are two places to trim that: at the shell, before the output ever comes back, and on the wire, in the request itself as it crosses to the model. rtk does the first, Headroom does the second, and they stack. Both are part of the Token Saving stack.

rtk: trim at the shell

rtk sits between your agent and the shell and trims command output before it reaches the context window. Single Rust binary, 100+ commands, under 10ms overhead. It claims 60-90% savings on the common ones, and the per-command breakdown in its README backs that up: tests -90%, grep -80%, git commit down to ok abc1234.

brew install rtk
rtk init -g          # Claude Code / Copilot (also --codex, --gemini, --agent cursor)

Restart the agent and that's it. A bash hook rewrites git status to rtk git status before it runs, so the agent gets the compact version without knowing rtk exists. One caveat worth knowing: the hook only fires on Bash calls, so Claude Code's built-in Read/Grep/Glob skip it. Use shell cat/rg (or rtk read/rtk grep) if you want those trimmed too. Run rtk gain any time to see how many tokens it has saved you.

Headroom: compress on the wire

sketchnote: headroom on the wire - proxy, MCP, library, CacheAligner, CCR, RAG, between agent and model

Headroom sits between your agent and the model API and compresses what crosses the wire: tool output, logs, files, RAG chunks. It's all deterministic or a small local model, so it never spends API tokens to do the compressing. Two clever bits: CacheAligner keeps volatile tokens (dates, UUIDs) out of your prompt prefix so the cache keeps hitting, and CCR caches the original under a hash so the model can fetch it back if it needs it.

Run it as a proxy (one env var), an MCP server, or a library. If you take the MCP route, front it with mcporter rather than wiring the server in raw. Honest number, to their credit for publishing it: the median saving across 50,000+ real sessions was 4.8%, with the big wins on tool-heavy work.

What it saved me

Two days of real data, both running together (Headroom live, rtk installed) across roughly ten sessions with Headroom on and about four with rtk:

Usage Analytics savings tab: Headroom 28.7M saved (live), RTK 4.9M (installed), NET measured 33.6M (Headroom + RTK)

33.6M tokens in two days, measured not modelled. Small sample and rough session counts, but the split matches what you'd expect: Headroom does the heavy lifting on the wire across every session it touches, rtk chips in on the shell-heavy ones. Install once, save on every turn after.

Share𝕏in

Comments & Reactions