Test Category

Test Blog Post

Starter template for writing out a blog post using MDX/JSX and Next.js.

No Name Exists

Abdullah Muhammad

Published on May 22, 20265 min read 9 views

Share:
Article Cover Image

Introduction

Whether you are using Claude Code or Codex as agents for coding, one thing is clear: you want your agents to be as productive and efficient as possible with the allocated token budget.

In this short article, we will highlight a popular Rust binary which you can install and integrate into your development workflow, allowing you to save on tokens.

You do not need to have experience with Rust or its package manager, Cargo.

This step-by-step guide will walk you through the entire setup process.


What is RTK?

Rust Token Killer or RTK for short, is a Rust binary built specifically to reduce the amount of token usage of your Claude Code agent.

It sits between the Claude Code execution shell and the LLM context, filtering command output before it reaches the model.

What it does:

  • Intercepts Shell/Tool output
  • Strips Noise (logs, test results, etc.)
  • Compresses output before Claude sees it
  • Reduces token usage based on noisy workflows

You can find the official RTK GitHub repository here.


What are Rust and Cargo?

Rust is a systems programming language that operates much closer to hardware than higher-level languages such as Java, Python, and TypeScript. It focuses on performance, memory, and concurrency.

As such, it is an ideal language for back-end services, CLI tools, compilers, and even the blockchain (Solana uses it for smart contract functionality).

Cargo is a build tool as well as Rust's package manager. It is to Rust what NPM, PIP, and the Go package manager are to JavaScript, Python, and Go, respectively.

It allows users to publish "crates" which are simply Rust packages to the Cargo registry. This enables other users and developers alike to install these crates and use them in their own Rust projects.

Installation Process

In this section, we will walkthrough the installation process for both Rust/Cargo as well as the RTK binary.

I am using the Windows operating system so we will use Windows-based commands for installing Rust/Cargo as well as the RTK binary.


Installing Rust and Cargo

You can install both Rust and Cargo with the following command:

winget install Rustlang.Rustup

You can verify installation using the following two commands:

rustc --version
cargo --version

If there are any issues with the installation process, you can visit the official installation docs here.


Installing the RTK Binary

Once you have verified and installed Rust and Cargo, we can proceed with installing the RTK tool.

This Cargo command will take care of everything:

cargo install --git https://github.com/rtk-ai/rtk

For optimal usage, you can read up the README.md file inside this GitHub repository. It is detailed and covers how to use it in your development workflow.

You can verify successful installation with the help of the following two commands:

rtk --version
rtk --help

The first should output the latest version of the RTK tool (which at the time of this writing is 0.34.3) and the second should detail a comprehensive list of commands you can use with the RTK tool.

Optimal Usage

RTK wraps common "noisy" commands utilized by Claude Code in your development workflow. These can include commands related to Git, NPM, Docker, and many other command development tools.

The goal is to reduce unnecessary token consumption by minimizing command output, allowing tokens to be spent on higher-value tasks such as coding and reasoning rather than routine operations like version control, builds, and testing.

To ensure proper usage in your development workflow, you will need to add RTK inside your project using the following command:

rtk init

Since I use Claude Code with the Cursor IDE, the newer command looks something like this:

rtk init -g --agent cursor

This specific command initializes RTK in your project so Claude Code can work with it.

It creates a .rtk directory (at the location where you ran this command) that contains a filters.toml file.

This configuration file controls RTK filtering behaviour based on specific commands used by Claude Code.


RTK Best Practices

To utilize RTK effectively, you should have a dedicated section inside your CLAUDE.md file which describes to the Claude Code agent on how to best use it.

You can clone this GitHub Repository. The directory we will work with is located here /demos/Demo80_RTK_Claude_Optimizer.

The following markdown file serves as an example of how you would add RTK related instructions inside a CLAUDE.md file:

GitHub GistMarkdown
## RTK (Rust Token Killer)

This project uses RTK (Rust Token Killer) to reduce LLM context token usage by filtering, compacting, and summarizing noisy terminal output before it reaches Claude Code.

### RTK Usage Rules

- Prefer RTK-wrapped commands whenever possible.
- If an RTK equivalent exists, use it instead of the raw command.
- Avoid excessive terminal output that wastes context tokens.
- Prefer focused inspection over dumping entire logs, diffs, or recursive directory trees.
- Use error-focused and summary-focused RTK commands when debugging.

### Preferred Command Patterns

Use RTK for common development workflows:

```bash
rtk pnpm install
rtk pnpm build
rtk pnpm test
rtk npm install
rtk npm test
rtk next build
rtk cargo test
rtk tsc
rtk prisma migrate status

rtk git status
rtk git diff
rtk diff

rtk jest
rtk vitest
rtk lint
rtk prettier
rtk playwright
rtk pytest
rtk mypy
rtk ruff

rtk docker ps
rtk docker logs
rtk kubectl get pods
rtk aws sts get-caller-identity

rtk ls
rtk tree
rtk find . -name "*.ts"
rtk read package.json
rtk deps

rtk err pnpm build
rtk summary pnpm build
Sample instructions for guiding Claude Code on using the RTK tool

It may seem like a lot of instructions, but adequately detailing all of them this way will ensure optimal token usage during development.

Committing the .rtk directory really depends on your development workflow. If this is a local-only preference, you may not need to commit this directory to Git or any other source code management tool.

However, if you intend on sharing it as part of the development workflow, you should note that users who clone your repository may not have RTK installed locally.

In fact, it may be wise to add a line or two inside the CLAUDE.md file to tell the Claude Code agent to bypass RTK instructions if the Rust binary is not installed locally.

If you choose not to commit this directory, you can simply add it to your .gitignore file like other common directories such as .claude, .cursor, .github, and so on.


RTK for Generating Token Usage Reports

In this section, we will cover a common RTK command for analyzing token usage and efficiency.

If you run rtk gain inside your project directory using Claude Code, you should see something like this:

No Image Found
RTK can be used to generate a Claude Code token usage report

Running rtk gain inside Claude Code will detail a nice summary of the tokens saved based on the different development tool commands utilized.

Saving on tokens improves developer efficiency because it enables them to allocate tokens for higher-value tasks.

This also highlights the importance of good context and AI prompting. Providing noisy context causes your Claude Code agent to increase token usage and reduce efficiency.

Remember, Context → Instruction → Input → Output.

Conclusion

We covered a handy Rust binary called RTK which can help you save on Claude Code tokens.

As agentic development continues to grow, it is important to get the most out of your agents while also ensuring token usage is optimized for development purposes.

We covered the installation process of Rust/Cargo and the RTK binary. We highlighted best practices of using the RTK binary in your development workflow (CLAUDE.md integration, .rtk directory, etc.).

In the list below, you will find links to the official RTK GitHub repository as well as links to the Rust docs, Cargo docs (Rust's package manager), and the GitHub repository used in this article:

I hope you found this article helpful and look forward to more in the future.

Thank you!

No Name

Abdullah Muhammad

Blogger. Software Engineer. Designer.

Subscribe to the newsletter

Get new articles, code samples, and project updates delivered straight to your inbox.