rtk (Rust Token Killer) sits between a coding agent and the shell. It runs the command the agent asked for and hands back a shorter version of the output, so fewer tokens land in the context window.

What it is

rtk is a single Rust binary from rtk-ai. You use it as a prefix: rtk git status, rtk vitest run, rtk grep. For each supported command it applies four tricks: it drops noise and boilerplate, groups similar lines (files, errors), truncates long lists, and collapses repeated log lines into a count. Test runners show only failures; git log shrinks to hash, author and subject.

You do not have to teach the agent to type rtk. rtk init -g installs a hook in Claude Code: a PreToolUse hook on the Bash tool that rewrites the command through updatedInput before it runs, so git status becomes rtk git status without the model knowing.

The CLI is Apache-2.0. Its engine and an optional API proxy daemon are under BUSL-1.1 (source-available); an Apache-only rtk-oss edition leaves the engine out. Telemetry is off unless you opt in.

What problem it solves

Every tool result stays in the conversation and is sent again with every later request (see Tokens and Prompt caching). A test run that prints 2,000 passing tests, a full git diff or a recursive find can each add tens of thousands of tokens that ride along for the rest of the session. The Claude Code costs guide suggests exactly this fix: filter command output in a hook before Claude sees it. rtk is that filter, prebuilt for over a hundred commands.

How to try it

brew install rtk          # macOS / Linux
rtk gain                  # sanity check: shows the savings dashboard
rtk init -g               # install the global Claude Code hook, then restart Claude Code

There is another, unrelated crate called rtk on crates.io. If rtk gain says “command not found” or something odd, you have the wrong one.

Then work as usual and check what it saved:

rtk gain              # totals and the top commands by tokens saved
rtk gain -p           # only the current project
rtk discover          # commands in your Claude Code history that rtk could have compressed

Usage example

Frontend

In a Vite + React project, the agent runs the test suite after each change. With the hook in place, Claude asks for npx vitest run, the hook turns it into rtk vitest run, and instead of every passing spec the agent sees the summary and the failing tests with their errors:

# what Claude asked for
npx vitest run src/components
# what actually ran
rtk vitest run src/components

The author of the post this page comes from saw 82% saved on vitest runs and 95% on jest runs in a pet project.

Backend

In a Node/Express service, a review task often starts with a diff against main. A raw git diff main...HEAD on a feature branch can be hundreds of kilobytes. Through rtk the agent gets only the changed lines, grouped by file; in the author’s stats such diffs shrank by about 94%. rtk tsc does the same for TypeScript errors, grouping them by file instead of printing each one with its full context.

Who it’s for and when

Anyone who runs Claude Code on a subscription and hits usage limits, or pays per token on the API. It pays off most in sessions with lots of tests, diffs, searches and logs. On a session that is mostly conversation and file edits it saves little, because it never touches those.

Gotchas

  • Only the Bash tool. Claude Code’s built-in Read, Grep and Glob tools do not go through the hook. A lot of file reading bypasses rtk unless the agent uses shell commands or rtk read / rtk grep directly.
  • It can cut something the agent needs. When that happens the agent can re-run the command without the filter, which costs one more tool call. rtk also keeps elided output, retrievable by hash with rtk recall.
  • Approximate numbers. rtk estimates tokens as bytes divided by four, with no real tokenizer. The percentages are reliable; the absolute token counts are rough.
  • Savings dilute. rtk shrinks only command output, which is one part of each request. Your overall usage drops by much less than the per-command percentages.
  • It does not break the prompt cache. Output is filtered once, before it enters the history, so later requests see the same bytes.

Citations

  1. Manage costs effectively: reduce token usage
  2. Hooks reference: PreToolUse and updatedInput
  3. rtk repository and README