Cut Claude Code Token Costs by Up to 90% with This Open‑Source Rust Proxy

RTK is a Rust‑based CLI proxy that filters and compresses shell command output for LLM agents, slashing token usage by 60‑90% with less than 10 ms overhead, supporting over 100 commands, multiple AI tools, and configurable privacy‑safe telemetry.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Cut Claude Code Token Costs by Up to 90% with This Open‑Source Rust Proxy

Problem

LLM agents such as Claude Code or Cursor send the raw output of shell commands to the model. The output often contains hundreds or thousands of irrelevant characters, leading to excessive token consumption.

Solution – RTK (Rust Token Killer)

RTK is a standalone Rust binary that intercepts command output before it reaches the LLM, applying filtering, compression, deduplication, and truncation.

Typical token savings of 60 %–90 % are observed in medium‑to‑large TypeScript and Rust projects. The tool adds less than 10 ms overhead per command and has zero runtime dependencies.

Usage

Automatic hook (Bash)

After installing RTK, configure a hook for Claude Code. The hook rewrites Bash calls, for example:

# Original agent command
git status
# Executed after hook
rtk git status

New sessions automatically pick up the hook; restart the agent after installation.

Note: the hook only rewrites Bash‑based tool invocations. Built‑in read/grep/glob commands in Claude Code are not intercepted and must be called explicitly as rtk grep or rtk cat.

Manual invocation

rtk git diff HEAD~1    # compress diff output
rtk ls -R src         # trim directory listing
rtk cargo test        # collapse passed tests, keep key info

RTK includes built‑in compression strategies for over 100 common development commands (git operations, test output, directory listings, npm ls, etc.).

Supported AI tools

Full hook integration with Claude Code, plugin for Hermes, support for Cursor, and a total of 13+ agents, each with its own integration method documented in the project repository.

Platform compatibility

Linux, macOS, WSL – full functionality with automatic hook.

Native Windows (cmd/PowerShell) – no automatic rewrite hook; use manual rtk calls or run via WSL for the full experience.

Configuration & fault tolerance

Configuration file locations:

~/.config/rtk/config.toml
# macOS alternative
~/Library/Application Support/rtk/config.toml

Users can adjust filter granularity and add custom rules. If a command fails, RTK forwards the complete unfiltered output to the LLM, avoiding the need to re‑run the command.

Privacy

Anonymous telemetry is disabled by default. Enabling it with rtk telemetry enable sends only aggregated counts and anonymized command names (first three words); source code, file paths, parameters, secrets, and environment variables are never collected.

Open‑source

Source code and releases are hosted at https://github.com/rtk-ai/rtk

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

cliAI agentsLLMRustopen sourcertktoken reduction
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.