编程助手 · 中文选型解读

rtk

已解读GitHubApache-2.0Rust

rtk是一款命令行代理工具,可拦截、压缩AI编程助手执行的Shell命令输出,降低大语言模型的token消耗,单Rust二进制文件无额外依赖。

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

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

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

rtk是一款命令行代理工具,可拦截、压缩AI编程助手执行的Shell命令输出,降低大语言模型的token消耗,单Rust二进制文件无额外依赖。

解决什么问题
企业使用AI编程助手时,助手执行Shell命令返回的大量冗余输出会占用大语言模型的上下文token(大语言模型处理文本的最小单位,消耗量直接决定API调用成本),既推高使用成本,还可能挤占有效上下文空间,影响输出质量。
适合什么团队
适合重度使用AI编程助手、智能开发代理的技术团队,以及需要控制大模型调用成本、优化AI编程体验的研发管理团队。
使用前注意
本工具仅降低命令输出对应的token消耗,整体账单降幅不等于输出压缩比例;安装时需注意与crates.io上同名的Rust Type Kit工具区分;仅对Bash调用的命令生效。

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

项目导读

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

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

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

项目导读

项目定位

rtk是一款面向AI开发场景的命令行代理工具,核心作用是在AI编程助手、智能开发代理调用Shell命令时,拦截并压缩命令返回的输出,降低大语言模型(LLM,可理解、生成自然语言及代码的人工智能模型)的token消耗。工具由Rust语言开发,仅为单二进制文件,无任何额外依赖,单请求处理开销低于10ms,几乎不会影响命令执行效率。

核心压缩能力

rtk目前支持100+常用开发命令的输出优化,针对不同类型命令采用四类压缩策略,保障关键信息不丢失的前提下减少冗余内容:

  1. 智能过滤:去除注释、空白字符、固定模板类冗余信息
  2. 分组聚合:将同目录文件、同类型错误等同类内容合并展示
  3. 截断保留:仅保留上下文相关的核心内容,剔除无意义的重复片段
  4. 重复内容去重:将重复出现的日志行合并为计数展示

针对常用命令的具体优化规则包括:

  • 文件类命令:ls/tree输出改为带文件计数的树结构,cat仅返回文件结构与特征信息而非全量内容
  • Git类命令:git status输出简化为分组统计格式,git log仅保留哈希值、提交人、提交主题,代码提交、推送类操作仅返回确认信息
  • 测试类命令:各类语言的测试框架输出仅保留失败用例信息,成功用例仅展示总数量
  • 运维类命令:docker ps仅返回核心字段信息

适配范围与使用方式

rtk目前可适配市面主流AI编程助手与智能开发代理,包括Claude Code、Copilot、Gemini CLI、Cursor、Windsurf、Kimi AI等。

使用流程非常简单,无需改造现有AI工具配置:

  1. 完成rtk安装后,执行对应AI工具的初始化命令(如针对Cursor执行rtk init -g --agent cursor,针对全局默认AI工具执行rtk init -g)
  2. 重启对应AI工具即可自动生效,AI助手调用的Shell命令会自动被rtk拦截处理,返回压缩后的输出

如果需要对AI工具内置的读文件、搜索等非Shell调用功能使用压缩能力,可手动调用rtk read、rtk grep等命令获取压缩后的结果。

安装部署方式

rtk提供多平台的一键安装方式,部署成本极低:

  • macOS推荐使用Homebrew安装:执行brew install rtk即可
  • Windows推荐使用winget安装:执行winget install rtk-ai.rtk即可,无需手动配置环境变量
  • Linux/macOS也可使用官方一键脚本安装:curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
  • 也可直接从发布页下载对应系统的预编译二进制文件,放到系统PATH路径下即可使用

安装完成后执行rtk --version即可验证是否安装成功,若使用Cargo安装需指定官方Git地址,避免安装到crates.io上同名的Rust Type Kit工具。

成本节约说明

rtk最多可减少90%的Shell命令输出内容,但需要注意:这个比例仅为命令输出部分的压缩比例,不等于整体大模型账单的降幅。大模型的输入token还包括用户提示词、系统提示词、历史对话内容,而总账单还包含大模型输出token的成本,因此实际账单降幅会低于输出压缩比例。

rtk给出的token消耗数值为按“字节数/4”估算的近似值,压缩比例数据准确,但绝对token数值仅作参考。此外rtk不会破坏大模型的Prompt缓存机制,更小的输出内容反而会降低缓存的读写成本。

许可证与采用建议

rtk采用Apache-2.0许可证,商业使用无限制,无需开源企业内部的相关代码。

建议已经规模化使用AI编程助手、智能开发代理的技术团队优先试用:工具接入成本极低,无需改变现有开发流程,可快速验证成本优化效果;如果团队对大模型上下文容量有较高要求,也可通过rtk减少冗余内容占用,提升AI输出的准确性。

可核对的事实层

官方资料与来源

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

```bash
brew install rtk                                              # macOS / Linux
winget install rtk-ai.rtk                                     # Windows
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
```

Then check you have the right package — another project named "rtk" exists on crates.io:

```bash
rtk --version   # any current version
rtk gain        # must show the savings dashboard, not "command not found"
```

> Cargo, pre-built binaries, native Windows, WSL, and uninstall: **[Installation guide](https://www.rtk-ai.app/guide/getting-started/installation)**

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

核对上游原始说明节选

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

Agent-agnostic token optimization: compress, route, filter, and more. One composable pipeline across everything your AI agent reads and sends — built on RTK's battle-tested bash-output compression (up to 90% smaller).

Website • Install • Troubleshooting • Architecture • Discord

English • Francais • 中文 • 日本語 • 한국어 • Espanol • Português

---

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

Angular builds are supported with rtk ng build: compact build tables with every bundle and diagnostic retained.

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 | | ast-grep | Groups structural matches by file, caps overflow | | 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 reduces the bash output your agent reads. That is what RTK measures, and it is not the same as cutting your bill by the same amount.

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

brew install rtk                                              # macOS / Linux
winget install rtk-ai.rtk                                     # Windows
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh

Then check you have the right package — another project named "rtk" exists on crates.io:

rtk --version   # any current version
rtk gain        # must show the savings dashboard, not "command not found"
Cargo, pre-built binaries, native Windows, WSL, and uninstall: Installation guide

What You Install

RTK ships as three downloads. The two rtk editions install a binary with the same name — hooks, scripts and agent config work unchanged across both — so they cannot be installed together. Uninstall one before installing the other.

flowchart TD
    agent["Your coding agent"]

    subgraph editions["Pick one · both install a binary named rtk"]
        direction LR
        full["<b>rtk</b><br/>Apache-2.0 + BUSL-1.1<br/>hooks · filters · engine"]
        oss["<b>rtk-oss</b><br/>Apache-2.0 only<br/>hooks · filters"]
    end

    proxy["<b>rtk-proxy</b><br/>BUSL-1.1<br/>compresses API traffic"]

    agent -->|"command output"| full
    agent -->|"command output"| oss
    agent -.->|"API traffic"| proxy

    classDef apache stroke:#2da44e,stroke-width:2px,fill:none
    classDef busl stroke:#0969da,stroke-width:2px,fill:none
    classDef mixed stroke:#8250df,stroke-width:2px,fill:none
    classDef plain stroke:#8c959f,stroke-width:1px,fill:none
    class full mixed
    class oss apache
    class proxy busl
    class agent plain
    style editions fill:none,stroke:#d0d7de,stroke-dasharray:4 4

| Download | Licence | Contains | |---|---|---| | rtk- | Apache-2.0 + BUSL-1.1 | Hook core, every command filter, and the compression engine | | rtk-oss- | Apache-2.0 only | Hook core and every command filter. No engine. | | rtk-proxy- | BUSL-1.1 | The RTK Proxy daemon. Never bundled with either rtk. |

Production use is free, engine and daemon included. What the BUSL grant does not cover is offering RTK or a derivative to third parties as a commercial product or service — for that, contact contact@rtk-ai.app.

curl -fsSL .../install.sh | RTK_EDITION=oss sh    # Apache-2.0 edition
brew install rtk-ai/tap/rtk-oss
What the Apache-2.0 edition omits and where the licence boundary falls: Editions and Licensing

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
rtk init --agent trae           # Trae (project: .trae/hooks.json)
rtk init -g --agent trae        # Trae global: ~/.trae and existing ~/.trae-cn

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

The agent receives compact output without ever calling rtk explicitly.

The hook only fires on Bash tool calls. Built-in tools like Read, Grep and Glob do not pass through it. Use shell commands (cat, rg, find) or call rtk read, rtk grep, rtk find directly.

Per-agent setup, --dry-run, and uninstall: Quick Start · Supported Agents

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
Does RTK break Claude's prompt cache? No. RTK filters output once per command. The result is stored in history and cached normally on subsequent API calls, so the cache keeps working as expected. Smaller outputs also mean cheaper cache writes and reads. See Troubleshooting for details.

Supported AI Tools

RTK supports 18 AI coding tools. Each integration rewrites shell commands to rtk equivalents, reducing the bash output the agent reads where the agent supports command interception.

| Tool | Install | Method | |------|---------|--------| | Claude Code | rtk init -g | PreToolUse hook (native binary) | | GitHub Copilot (VS Code) | rtk init -g --copilot | PreToolUse hook — transparent rewrite | | GitHub Copilot CLI | rtk init -g --copilot | PreToolUse deny-with-suggestion (CLI limitation) | | Cursor | rtk init -g --agent cursor | preToolUse hook (hooks.json) | | Gemini CLI | rtk init -g --gemini | BeforeTool hook | | Codex | rtk init -g --codex | PreToolUse hook (updatedInput) + AGENTS.md | | Windsurf | rtk init -g --agent windsurf | .windsurfrules (project-scoped) | | Cline / Roo Code | rtk init --agent cline | .clinerules (project-scoped) | | OpenCode | rtk init -g --opencode | Plugin TS (execute.before / tool.execute.before), needs 1.18.29 or newer | | OpenClaw | openclaw plugins install ./openclaw | Plugin TS (beforetoolcall) | | Pi | rtk init -g --agent pi (g

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