ScriptsMay 1, 2026·3 min read

RTK — CLI Proxy That Cuts LLM Token Usage

RTK is a single-binary Rust CLI proxy that intercepts common developer commands and compresses their output before it reaches your LLM, reducing token consumption without changing your workflow.

Introduction

RTK sits between your AI coding agent and the shell, intercepting command output and applying format-aware compression so the LLM receives fewer tokens. It ships as a single Rust binary with zero runtime dependencies, making it trivial to drop into any agentic workflow.

What RTK Does

  • Intercepts stdout/stderr of arbitrary shell commands and rewrites them into a compact representation
  • Applies format-specific reducers for JSON, diffs, directory listings, logs, and build output
  • Preserves semantic content while stripping redundant whitespace, ANSI codes, and boilerplate
  • Works transparently with Claude Code, Codex CLI, and other agentic tools
  • Outputs original content when piped to a non-LLM consumer via TTY detection

Architecture Overview

RTK spawns the target command as a child process, captures its output streams, and passes them through a pipeline of format detectors and compressors. Each compressor is a pure function that pattern-matches on the input structure. The final output is emitted to stdout so the calling agent reads the reduced version. Because it is a thin wrapper with no daemon, startup overhead is sub-millisecond.

Self-Hosting & Configuration

  • Install from source with cargo install rtk or grab a static binary from the GitHub releases page
  • No configuration file required — sensible defaults cover most use cases
  • Set RTK_PASSTHROUGH=1 to disable compression for debugging
  • Custom reducers can be added via a TOML config at ~/.config/rtk/config.toml
  • Integrates with Claude Code by prefixing shell commands or aliasing common tools

Key Features

  • Single static binary, no Python or Node dependency
  • Sub-millisecond startup; negligible overhead on command execution
  • Format-aware compression preserves meaning while dramatically shrinking output
  • TTY detection prevents accidental compression of human-facing output
  • Open source under MIT license with active community contributions

Comparison with Similar Tools

  • LLMLingua — prompt compression at the model level; RTK compresses at the shell output level before the prompt is built
  • Repomix — packs entire repos into a single file for context; RTK focuses on individual command output
  • Context window managers — most operate on chat history; RTK targets raw tool output

FAQ

Q: Does RTK change the command's behavior? A: No. RTK only post-processes stdout/stderr. The underlying command runs exactly as it would without RTK.

Q: Which AI agents does it work with? A: Any agent that shells out to run commands — Claude Code, Codex CLI, OpenCode, and custom setups.

Q: Can I disable it for specific commands? A: Yes, set RTK_PASSTHROUGH=1 or use the --raw flag.

Q: Is it safe for production CI pipelines? A: RTK is designed for interactive agentic use. In CI, run commands directly without the wrapper.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets