← All posts

AI tool reviews › Tokens and context

What is RTK? A Rust CLI that trims AI agents' shell output

RTK (Rust Token Killer) filters git, ls and test output before an AI coding agent reads it. How its Claude Code hook works, and what I measured.

If you’ve looked for ways to make Claude Code or another coding agent use fewer tokens, you’ve probably come across the name RTK, often with a promise of up to 90% less command output. You can see where it starts in any terminal. When an agent runs git status or a test suite, it reads every line that comes back, and the hints written for people, the progress dots, and the tests that passed all become input tokens.

RTK, short for Rust Token Killer, is a command-line tool shipped as a single Rust binary. It runs commands such as git, ls, and test runners for the agent and compresses their output before the agent sees it. It isn’t a skill or an MCP server, and in Claude Code it attaches through a hook that rewrites shell commands. The repository was created on January 22, 2026, and its changelog begins a week later with version 0.2.1, released while the project still lived under the personal GitHub account of Patrick Szymkowiak, whom the README lists as founder. It now lives at rtk-ai/rtk, and when I checked the GitHub API on October 28, 2026, it had 84,807 stars and its newest release was 1.1.0 from October 25 (changelog).

What RTK installs and when it steps in

RTK’s parts are the rtk binary, with subcommands such as rtk git status, a hook, and a short instruction file. A hook is a command the harness runs at a fixed moment in the agent’s loop, and rtk init -g installs both the hook and the file. When I ran it with --dry-run, which only prints the changes, it planned to add a PreToolUse hook to ~/.claude/settings.json that calls rtk hook claude.

PreToolUse fires just before a tool runs, and its matcher, Bash, limits it to shell commands. Claude Code hands the tool call to the hook as JSON on standard input, and the hooks documentation says a hook can answer with updatedInput to replace the tool’s arguments before it runs. Here are two tool calls piped in by hand.

echo '{"tool_name":"Bash","tool_input":{"command":"git status"}}' | rtk hook claude
echo '{"tool_name":"Bash","tool_input":{"command":"echo hi"}}' | rtk hook claude
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git status"}}}

git status became rtk git status, while for echo hi, which RTK has no rule for, the hook returned nothing, so the original command runs as is. The same documentation says Claude Code checks permissions against the command the hook returns. That’s why RTK reads the Bash rules in your settings files, approves the rewritten command only when one of them allows the original, and leaves the rest to Claude Code. In my headless runs I gave permissions with --allowedTools, which RTK doesn’t read, so I allowed Bash(rtk *) as well.

The instruction file is ~/.claude/RTK.md, which rtk init -g pulls into your global CLAUDE.md with an @RTK.md import line, so it loads at the start of every session (memory). At the default level it’s eight lines (453 bytes, or 98 tokens by tiktoken) saying the output is condensed and that a command should be rerun through rtk bypass only when its result is unusable. Since the hook and filters run outside the model, it’s the only part that is always in the context. Note, though, that the hook sees only Bash calls, so Claude Code’s built-in Read, Grep, and Glob tools go around it. And among the 18 agents RTK lists, a few, such as Windsurf and Cline, get no hook, only a rules file asking the model to type rtk itself (supported agents).

The same commands, with and without RTK

To see it for myself, I made a small Python repository with five commits and a few uncommitted changes. One of its six pytest tests fails on purpose, because shipping(50) returns 5 instead of 0. Then, with rtk 1.0.1 on macOS, I ran each command as typed and as the hook rewrites it. First, plain git status.

On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   shop/cart.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	shop/coupons.py

And here is rtk git status.

* main
M  README.md
 M shop/cart.py
?? shop/coupons.py

The hints in parentheses are gone, but the two-letter codes of git’s short format still tell the staged README.md from the unstaged cart.py. The failing test was what I cared about most, so here is rtk pytest -q.

Pytest: 5 passed, 1 failed in 0.01s

Failures:
1. [FAIL] test_shipping_at_threshold
     tests/test_cart.py:25: in test_shipping_at_threshold
     assert shipping(50) == 0
     E   assert 5 == 0

The test name, the file and line, the assertion, and the actual value all made it through, and the exit code stayed 1. Of the failure details, pytest’s explanation line + where 5 = shipping(50) and the exception name AssertionError didn’t make it. The 1.1.0 changelog includes a fix to keep the E lines of failure blocks, so a newer version may keep the first. I used -q on both sides because without it pytest prints the folder’s full path, and RTK adds -q and --tb=short on its own anyway. Here are five commands in bytes and in tokens counted with OpenAI’s tiktoken (o200k_base), which are estimates, since Claude’s tokenizer differs.

Command Without RTK With RTK Tokens
git status 407 B, 110 tokens 55 B, 20 tokens 82% fewer
git log 728 B, 298 tokens 259 B, 80 tokens 73% fewer
git diff 381 B, 114 tokens 305 B, 89 tokens 22% fewer
ls -R 134 B, 47 tokens 204 B, 93 tokens 98% more
pytest -q 589 B, 112 tokens 195 B, 63 tokens 44% fewer

git log kept only the short hash, subject, relative date, and author name, and git diff lost only its header lines. RTK’s own counter, bytes divided by 4, put the raw git log at 182 tokens where tiktoken counted 298, because long hashes split into many tokens. The README says as much: RTK ships no tokenizer, so its percentages are reliable but the absolute token numbers are approximate (How RTK Savings Work). I’ll come back to the ls -R row further down.

What changed across a whole Claude Code session

Single commands don’t show a whole session, so I also gave Claude Code the same job twice, without and with the hook. The prompt asked it to run the three commands separately, then say what was uncommitted, how many commits there were, and which test failed and why. Both runs used Claude Haiku 5.5 (claude-haiku-5-5) on Claude Code 2.1.304 on October 28, 2026, each on a fresh copy of the project. To keep RTK out of my own setup, I added the hook with --settings and the text of RTK.md with --append-system-prompt-file for that run only, instead of running rtk init -g.

Both runs answered correctly, down to shipping(50) returning 5 right at the threshold. The three tool results shrank from 1,732 to 518 bytes, or from 522 to 166 tokens by tiktoken. Yet the session’s total input as Claude Code reported it, cached tokens included, only went from 39,607 to 39,430 tokens, less than half a percent. The system prompt and tool definitions that ride along with every turn simply dwarf a few hundred tokens of command output. The cost went from $0.00253 to $0.00244, mostly because the second run happened to write fewer output tokens (363 against 544). In a first attempt with a looser prompt, the run without RTK spent an extra turn on a combined command my permissions blocked, and that moved the totals more than RTK did. It’s just as RTK’s own explanation says: 90% fewer output bytes doesn’t make a session 90% cheaper. Of course, this was one small run, not a benchmark, and in a long session full of logs the shell’s share would be larger.

How it differs from similar tools

RTK works on one thing, the output of shell commands before the agent reads it. context-mode is an MCP server, a program that offers an agent extra tools over the Model Context Protocol, and its sandbox tools keep large raw outputs out of the context. Caveman includes a skill that makes the agent’s own replies terse, and since its 4.0 release it also bundles a part that shrinks logs and test output. The simplest alternative is a line in CLAUDE.md asking for quiet flags such as git log --oneline or pytest -q. My pytest row suggests part of RTK’s effect comes from flags like these, but RTK doesn’t rely on the agent’s memory, and it covers more than 100 commands. I didn’t try the engine and the RTK Proxy for API traffic that arrived with v1 (RTK v1).

Where it fits, and what you give up

RTK is most likely to pay off when an agent deals with long, repetitive output, such as large test suites, builds, and logs, and it does less when outputs are already short, as in my project, or when the agent mostly uses Read and Grep. And the more a task depends on exact details, the more it’s worth checking what each filter drops. ls -R showed this most clearly.

docs/
shop/
tests/
README.md  97B
pyproject.toml  118B
notes.md  33B
__init__.py  0B
cart.py  426B
coupons.py  28B
__init__.py  0B
test_cart.py  473B
... (3 filtered)
[+3 hidden: rtk recall 64889d8d1ce3]

The output grew instead of shrinking, and the folder headers such as ./shop: were set aside, so you can’t tell which __init__.py is in shop and which is in tests. Following the hint, rtk recall printed just those three lines. When you need the original output, rtk bypass runs a command without filtering, a command prefixed with RTK_DISABLED=1 is left alone by the hook, and exclude_commands in config.toml keeps chosen commands from being rewritten at all (configuration). When a command fails or a list gets trimmed, RTK may also keep the full output locally behind a rtk recall hint.

There are a few other costs. On my Mac, the hook took about 21 ms per call and rewritten commands ran 4 to 15 ms longer (medians of 30 runs), while the README says under 10 ms. In my run, RTK’s local SQLite database recorded each command as typed and as rewritten, the project folder path, estimated tokens, and run time, plus a session ID for each hook decision. By default it keeps that history for 90 days. Telemetry is off by default, and if you opt in, it sends at most one anonymous ping a day with counts and command names, not command contents (telemetry). The CLI is Apache-2.0, but the standard binary links a BUSL-1.1 compression engine whose grant covers production use, and there’s an Apache-2.0-only rtk-oss edition (editions).

Installing it and a first thing to try

These are the official commands from the README and the installation guide. The install script downloads the release archive, checks its SHA-256 against the published checksums, and puts the binary in ~/.local/bin.

brew install rtk          # macOS / Linux
# or, without Homebrew:
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
rtk --version && rtk gain # gain must work; another project is also called rtk
rtk init -g --dry-run     # print what would change, write nothing
rtk init -g               # hook + RTK.md for Claude Code, then restart it
rtk init -g --uninstall   # undo; brew uninstall rtk removes the binary

Before installing the hook, I’d suggest running rtk git status and your usual test command next to the plain versions in one of your own repositories and comparing them with wc -c. You’ll see right away what the filters keep and drop. I tested rtk 1.0.1 on October 28, 2026, on macOS with Claude Code 2.1.304, and the newest release that day was 1.1.0 from October 25.

AI tools helped with the research for this post.