# rtk

> A command-line proxy that shrinks shell output before your AI coding agent reads it

- Repository: https://github.com/rtk-ai/rtk
- Category: Token & cost savings
- Stars: 84,321 · Forks: 5,356 · Language: Rust · License: Apache-2.0
- Experience: Beginner friendly
- Page: https://ir.adyog.com/repos/rtk-ai/rtk/

AI coding agents run shell commands constantly, and the raw output is often long: full git diffs, progress bars, hundreds of passing tests. All of that lands in the model's context and costs tokens. RTK sits between the agent and the command and passes along a shorter version.

It works through a hook. When the agent runs a Bash command like `git status`, the hook rewrites it to `rtk git status`. RTK runs the real command, then trims the result by filtering noise, grouping similar items, truncating, and collapsing repeated lines into counts. The agent never has to call `rtk` itself.

The README is careful about what the numbers mean. Up to 90% is the cut in bash output only, not in your bill, because bash output is just one part of the input and input is only part of the cost. Token counts are estimated as bytes divided by four, so the percentages are more reliable than the absolute numbers. It also says the filtering does not break Claude's prompt cache.

## What it does

- **Compact output for 100+ commands**: Covers git, GitHub CLI, test runners (pytest, jest, cargo, go), linters, package managers, Docker, kubectl, AWS and Pulumi. Test runs show failures only, with passing tests collapsed to a count.
- **Automatic command rewriting**: A hook rewrites Bash calls such as `git status` to `rtk git status` before they run. Plugin-based agents like Hermes use their plugin API instead.
- **Works with many agents**: `rtk init` has setup options for Claude Code, Copilot, Gemini CLI, Codex, Cursor, Windsurf, Cline, Kilo Code and several others.
- **Smart file reading**: `rtk read` shows signatures and structure instead of full bodies, and `rtk smart` gives a two-line summary of a code file. Built-in tools like Read, Grep and Glob in Claude Code bypass the hook, so you call these directly.
- **Savings dashboard**: `rtk gain` shows how much output RTK has trimmed. The tool is one Rust binary with under 10ms of overhead per command.

## What you could build

- Cut the noise from test and build output when an agent runs cargo, pytest or npm test in a loop.
- Keep long agent sessions inside the context window by shrinking git diff, log and status output.
- Make Docker, kubectl or AWS CLI output readable for an agent without it wading through full JSON or logs.
- Check how much bash output your agent reads by running rtk gain after a working session.
- Set up the same output compression across several agents, such as Claude Code, Cursor and Gemini CLI.

## Who it's for

Developers who use a terminal-based AI coding agent and are comfortable installing a CLI tool; knowing which agent you use is enough to start.

## Get started

Install RTK with Homebrew (or winget, the install script, or cargo), then run `rtk init` with the flag for your agent. Restart the agent, run a command like `git status`, and check `rtk gain` to see the savings. If `rtk gain` fails you may have the unrelated Rust Type Kit package, so install with cargo from the GitHub repo.

```
brew install rtk
```
```
rtk init -g
```
```
rtk gain
```

Tags: token-optimization, cli, claude-code, rust, developer-tools
