Scripts2026年5月1日·1 分钟阅读

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.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
RTK Overview
安全暂存命令
npx -y tokrepo@latest install 58a018a0-4557-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产