编程助手 · 中文选型解读

rtk

已解读GitHubApache-2.0Rust

rtk是基于Rust开发的命令行代理工具,拦截AI编程助手的命令输出并压缩后传入大模型上下文,降低token消耗。

79.6kstar今天仍有更新维护状态Apache-2.0 · 可评估商用商用提醒
在 GitHub 查看官方项目
适合解决辅助写代码、审查和处理研发任务
更适合研发团队和有内部系统建设能力的企业
投入判断上手门槛:中。需要代码权限、安全策略和研发流程配合
一分钟看懂

这个项目值得继续研究吗?

AI 依据上游资料解读 · 2026/9/9

rtk是基于Rust开发的命令行代理工具,拦截AI编程助手的命令输出并压缩后传入大模型上下文,降低token消耗。

解决什么问题
企业在使用AI编程助手时,shell命令返回的大量冗余输出会占用过多大模型输入token(大语言模型的计价单位),不仅推高AI使用成本,还会挤占有效上下文空间,降低AI响应质量。
适合什么团队
适合有大规模AI辅助编程需求、使用Claude Code、Cursor等主流AI编程工具,希望控制大模型调用成本的企业技术团队。
使用前注意
该工具仅压缩命令输出体积,无法直接等同账单降幅;安装需注意与crates.io上同名工具区分;AI工具内置非shell调用的操作需手动调用rtk命令生效。

本页用于缩短初步筛选时间,不构成技术、采购或法律结论。 正式使用前请在真实业务数据上验证,并以官方说明与许可证为准。

项目导读

从官方资料看清能力、部署与采用边界

AI 翻译整理 · 保留官方来源

以下内容依据项目公开 README 或模型卡翻译整理,代码、命令和产品名保持原样。

项目导读

项目定位

rtk是一款专门为AI编程场景打造的命令行代理工具,核心作用是在AI助手调用shell命令后,将返回的输出内容过滤压缩,再传入LLM(大语言模型)的上下文窗口,从而减少不必要的token消耗。该工具由Rust开发,为单二进制文件,无额外依赖,运行延迟低于10ms,目前已支持100+研发常用命令。

核心优化能力

rtk针对不同类型的命令采用四类优化策略:

  1. 智能过滤:移除注释、空白字符、冗余提示等无效内容
  2. 内容分组:将同类内容聚合展示,比如按目录归类文件、按类型归类错误
  3. 合理截断:保留核心有效上下文,删除重复冗余内容
  4. 去重合并:将重复的日志行合并并标注出现次数

针对常见研发场景的优化效果如下:

  • 文件操作类(ls、cat、grep等):将长列表、全文本输出转为结构化精简内容,仅保留核心结构和特征
  • Git操作类(status、diff、log等):压缩多余提示信息,仅保留核心状态、变更摘要
  • 测试执行类(pytest、go test、cargo test等):仅返回失败用例信息,通过用例仅展示统计数量
  • 代码检查类(ruff、sqlfluff、golangci-lint等):按规则和文件分组展示问题,移除冗余格式内容

需要注意的是,rtk统计的60%-90%降幅是指bash输出内容的体积降幅,并非直接对应大模型账单降幅:输入token除了命令输出外,还包含用户prompt、系统prompt和对话历史,而账单还包含输出token成本,因此实际账单降幅会低于该比例。rtk的token统计为按字节估算,比例数据可靠但绝对数值为近似值。

快速使用方式

rtk目前已兼容市面主流AI编程工具,包括Claude Code、GitHub Copilot、Gemini CLI、Cursor、Windsurf、Kimi AI等。

使用流程非常简单:

  1. 完成安装后,执行对应AI工具的初始化命令,比如针对Claude Code/Copilot执行rtk init -g,针对Cursor执行rtk init -g --agent cursor
  2. 重启对应AI工具即可生效,后续AI调用的shell命令会自动被rtk拦截优化,AI侧收到的是压缩后的输出内容

需要注意的是,rtk的自动钩子仅对bash调用的命令生效,若使用AI工具内置的Read、Grep等非shell能力,需要手动调用rtk read、rtk grep等命令才能享受优化效果。

安装要求与方式

rtk支持macOS、Linux、Windows三大操作系统,无额外硬件或软件依赖,安装方式灵活:

  • macOS推荐使用Homebrew安装:执行brew install rtk即可
  • Linux/macOS可使用一键脚本安装:执行curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh,默认安装到/.local/bin目录,按提示添加到PATH即可
  • Rust环境用户可通过cargo install --git https://github.com/rtk-ai/rtk安装
  • 也可直接从官方release页面下载对应系统的预编译二进制文件,放置到PATH目录即可

安装完成后可执行rtk --version和rtk gain验证安装是否成功,若执行rtk gain失败,需检查是否安装了crates.io上同名的Rust Type Kit工具,需卸载后通过官方指定方式重新安装。

许可证与采用建议

rtk采用Apache-2.0开源许可证,企业可免费商用,也可对源码进行修改二次开发。 建议企业先选择部分使用AI编程助手频率较高的研发团队试点,运行1-2个计费周期统计实际的成本降幅,验证符合预期后再在全研发体系推广。

可核对的事实层

官方资料与来源

查看来源 →
  • agentic-coding
  • ai-coding
  • anthropic
  • claude-code
  • cli
  • command-line-tool
  • cost-reduction
  • developer-tools
  • llm
  • open-source
  • productivity
  • rust
默认分支develop
关注仓库215
复刻次数5.0k
开放议题1.8k
近期更新2026/9/8
仓库状态未标记归档
上游部署线索
## Installation

### Homebrew (recommended)

```bash
brew install rtk
```

### Quick Install (Linux/macOS)

```bash
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
```

> Installs to `~/.local/bin`. Add to PATH if needed:
> ```bash
> echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc  # or ~/.zshrc
> ```

### Cargo

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

### Pre-built Binaries

Download from [releases](https://github.com/rtk-ai/rtk/releases):
- macOS: `rtk-x86_64-apple-darwin.tar.gz` / `rtk-aarch64-apple-darwin.tar.gz`
- Linux: `rtk-x86_64-unknown-linux-musl.tar.gz` / `rtk-aarch64-unknown-linux-gnu.tar.gz`
- Windows: `rtk-x86_64-pc-windows-msvc.zip`

> **Windows users**: Extract the zip and place `rtk.exe` somewhere in your PATH (e.g. `C:\Users\<you>\.local\bin`). Run RTK from **Command Prompt**, **PowerShell**, or *

该片段来自项目 README,仅用于初步判断;实际部署请以官方文档为准。

核对上游原始说明节选

CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies

High-performance CLI proxy that cuts up to 90% of the bash output your agent reads

Website &bull; Install &bull; Troubleshooting &bull; Architecture &bull; Discord

English &bull; Francais &bull; 中文 &bull; 日本語 &bull; 한국어 &bull; Espanol &bull; Português

---

rtk filters and compresses command outputs before they reach your LLM context. Single Rust binary, 100+ supported commands, <10ms overhead.

What RTK Does

RTK intercepts shell commands and compresses their output before your agent reads it.

| Operation | What RTK does to the output | |-----------|-----------------------------| | ls / tree | Tree format with file counts instead of one line per entry | | cat / read | Smart file reading: signatures and structure over full bodies | | grep / rg | Truncates long lines, groups matches by file | | git status | Compact stat format, grouped by state | | git diff | Reduced context, headers stripped | | git log | Hash, author and subject only | | git add/commit/push | Confirmation line instead of full progress output | | cargo test / npm test | Failures only, passing tests collapsed to a count | | ruff check | Grouped by rule and file | | sqlfluff lint | Grouped by rule and file | | pytest | Failures only, traceback trimmed | | go test | NDJSON parsed, failures only | | docker ps | Essential fields only |

How Savings Work

RTK cuts up to 90% of the bash output your agent reads. That is what RTK measures, and it is not the same as cutting your bill by 90%.

Bash output is one contributor to input tokens, alongside your prompt, the system prompt and conversation history. Input tokens are in turn only part of the bill, which also counts output tokens. The reduction dilutes at every step.

The token counts RTK reports are estimated as bytes / 4 — RTK ships no tokenizer, so the percentages are reliable but the absolute token numbers are approximate.

Full explanation: How RTK Savings Work

Installation

Homebrew (recommended)

brew install rtk

Quick Install (Linux/macOS)

curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
Installs to /.local/bin. Add to PATH if needed:
```bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> /.bashrc # or /.zshrc
```

Cargo

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

Pre-built Binaries

Download from releases:

  • macOS: rtk-x8664-apple-darwin.tar.gz / rtk-aarch64-apple-darwin.tar.gz
  • Linux: rtk-x8664-unknown-linux-musl.tar.gz / rtk-aarch64-unknown-linux-gnu.tar.gz
  • Windows: rtk-x8664-pc-windows-msvc.zip
Windows users: Extract the zip and place rtk.exe somewhere in your PATH (e.g. C:\Users\\.local\bin). Run RTK from Command Prompt, PowerShell, or Windows Terminal — do not double-click the .exe (it will flash and close). The full hook system works natively on Windows (and in WSL). See Windows setup below for details.

Verify Installation

rtk --version   # Should show "rtk 0.28.2"
rtk gain        # Should show the savings dashboard
Name collision warning: Another project named "rtk" (Rust Type Kit) exists on crates.io. If rtk gain fails, you have the wrong package. Use cargo install --git above instead.

Quick Start

# 1. Install for your AI tool
rtk init -g                     # Claude Code / Copilot (default)
rtk init -g --gemini            # Gemini CLI
rtk init -g --codex             # Codex (OpenAI)
rtk init -g --agent cursor      # Cursor
rtk init -g --agent windsurf    # Windsurf
rtk init --agent cline          # Cline / Roo Code
rtk init --agent kilocode       # Kilo Code
rtk init --agent antigravity    # Google Antigravity
rtk init --agent kimi           # Kimi AI
rtk init -g --agent pi          # Pi
rtk init --agent omp            # Oh My Pi (OMP)
rtk init --agent hermes         # Hermes
rtk init -g --agent droid       # Factory Droid

# 2. Restart your AI tool, then test
git status  # Automatically rewritten to rtk git status

Hook-based agents rewrite Bash commands (e.g., git status -> rtk git status) before execution. Plugin-based agents, including Hermes, use their plugin API to rewrite commands before execution. The agent receives compact output without needing to call rtk explicitly.

Important: the hook only runs on Bash tool calls. Claude Code built-in tools like Read, Grep, and Glob do not pass through the Bash hook, so they are not auto-rewritten. To get RTK's compact output for those workflows, use shell commands (cat/head/tail, rg/grep, find) or call rtk read, rtk grep, or rtk find directly.

How It Works

  Without rtk:                                    With rtk:

  Claude  --git status-->  shell  -->  git         Claude  --git status-->  RTK  -->  git
    ^                                   |            ^                      |          |
    |         full raw output           |            |  compact output      | filter   |
    +-----------------------------------+            +------- (filtered) ---+----------+

Four strategies applied per command type:

  1. Smart Filtering - Removes noise (comments, whitespace, boilerplate)
  2. Grouping - Aggregates similar items (files by directory, errors by type)
  3. Truncation - Keeps relevant context, cuts redundancy
  4. Deduplication - Collapses repeated log lines with counts

Commands

Percentages below are reductions in bash output, not reductions in your bill. See How Savings Work.

Files

rtk ls .                        # Compact directory tree
rtk read file.rs                # Smart file reading
rtk read file.rs -l aggressive  # Signatures only (strips bodies)
rtk smart file.rs               # 2-line heuristic code summary
rtk find "*.rs" .               # Compact find results
rtk grep "pattern" .            # Grouped search results
rtk diff file1 file2            # Condensed diff (exit 1 if files differ)

Git

rtk git status                  # Compact status
rtk git log -n 10               # One-line commits
rtk git diff                    # Condensed diff
rtk git add                     # -> "ok"
rtk git commit -m "msg"         # -> "ok abc1234"
rtk git push                    # -> "ok main"
rtk git pull                    # -> "ok 3 files +10 -2"

GitHub CLI

rtk gh pr list                  # Compact PR listing
rtk gh pr view 42               # PR details + checks
rtk gh issue list               # Compact issue listing
rtk gh run list                 # Workflow run status

Test Runners

rtk jest                        # Jest compact (failures only)
rtk vitest                      # Vitest compact (failures only)
rtk playwright test             # E2E results (failures only)
rtk pytest                      # Python tests (-90%)
rtk phpt                        # PHP .phpt tests (run-tests.php, -99%)
rtk go test                     # Go tests (NDJSON, -90%)
rtk cargo test                  # Cargo tests (-90%)
rtk rake test                   # Ruby minitest (-90%)
rtk rspec                       # RSpec tests (JSON, -60%+)
rtk err <cmd>                   # Filter errors only from any command
rtk test <cmd>                  # Generic test wrapper - failures only (-90%)

Build & Lint

rtk lint                        # ESLint grouped by rule/file
rtk lint biome                  # Supports other linters
rtk sqlfluff lint               # SQL linting (JSON, -75%)
rtk sqlfluff lint models/       # Lint a specific directory (pass path after `lint`)
rtk tsc                         # TypeScript errors grouped by file
rtk next build                  # Next.js build compact
rtk prettier --check .          # Files needing formatting
rtk cargo build                 # Cargo build (-80%)
rtk cargo clippy                # Cargo clippy (-80%)
rtk ruff check                  # Python linting (JSON, -80%)
rtk golangci-lint run           # Go linting (JSON, -85%)
rtk rubocop                     # Ruby linting (JSON, -60%+)
rtk mvnd verify                 # Maven Daemon (same filters as rtk mvn)
rtk sbt test                    # ScalaTest output (-90%)
rtk sbt compile                 # Compilation errors only (-75%)
rtk sbt run                     # Strip SBT preamble noise

Package Managers

rtk pnpm list                   # Compact dependency tree
rtk uv run pytest               # Preserve uv env, keep program output
rtk pip list                    # Python packages (auto-detect uv)
rtk pip outdated                # Outdated packages
rtk bundle install              # Ruby gems (strip Using lines)
rtk prisma generate             # Schema generation (no ASCII art)

Runtimes

rtk bun install                  # Strip progress and version lines
rtk bun test                     # Failures only (-90%)
rtk bun build                    # Errors only when writing to disk, else passthrough
rtk bunx tsc           

上游文档较长,此处为节选。完整内容见官方项目。