Tools

RTK: compress terminal output before it reaches Claude Code to save tokens

TL;DR

RTK (Rust Token Killer) is a CLI that compresses terminal command output before it enters an AI agent’s context. For Claude Code it installs a PreToolUse hook that automatically rewrites git status to rtk git status, and so on.

When Claude Code runs git status, npm test or docker ps, the command's entire output goes into context, including hundreds of log lines, repeated warnings and decorative formatting the agent doesn't need. In repos with large test suites, this output can be a significant share of a session's input tokens. RTK (Rust Token Killer) tackles exactly that: it compresses terminal command output before it reaches the model.

The problem RTK targets

Every model call resends the whole conversation history, including the results of every command run. A single pytest run printing 400 lines gets sent again on every later turn. Cutting lines that carry no information (repeated paths, banners, progress bars) both lowers cost and reduces "noise" for the agent reading the results.

How it works

  1. Install RTK, then run rtk init -g to add a hook to Claude Code.
  2. A PreToolUse hook intercepts the agent's Bash commands and rewrites them as RTK versions, e.g. git status → rtk git status.
  3. RTK runs the real command, condenses the output per command type and returns it.
  4. The agent receives compressed output that still has enough information to decide the next step.
PointDetail
Support100+ commands: git, gh, npm/pnpm, jest/vitest, tsc, pytest, ruff, go test, cargo, docker, kubectl, terraform…
SavingsUp to about 90% of bash output according to the project; since bash output is only part of input tokens, total cost drops less
LimitsOnly intercepts the Bash tool; Claude Code's built-in Read/Grep/Glob tools don't go through the hook
LicenceThe CLI is Apache-2.0; some engine/proxy components are BUSL-1.1 (there's a pure Apache-2.0 rtk-oss build)

When is it worth it?

  • Repos with large test suites, long build logs, many command runs per session.
  • Long sessions where old output keeps being resent.
  • Teams wanting lower cost without changing how they work: the hook is transparent to the agent.

Risks to manage

  • Over-compression: for important commands (failing tests, build errors), check the agent still sees enough error detail. If needed, run the original command to compare.
  • Name clash: another project is also called "rtk" on crates.io. After installing, run rtk --version and rtk gain to confirm it's the right package.
  • A broad hook: the hook rewrites every Bash command; read the source and configuration before enabling it on company repos.
  • Advertised numbers: the 90% figure is the project's own. Measure before/after on your repo.

How to measure the effect

  1. Run a standard task (for example fixing a bug with tests) with and without RTK.
  2. Compare input tokens in the usage report of both sessions.
  3. Check quality: did the agent fix it correctly, did it have to rerun commands for missing information?

How to apply it

  • Dev: try it on a large repo for a week and record the real token reduction.
  • Tech Lead: if it works, add the hook configuration to the team's onboarding docs.
  • PM: this is one of the lowest-risk ways to cut AI cost because output quality doesn't change, but only report measured numbers, not advertised ones.

Sources & references

  1. README rtk-ai/rtk