本文为 repomix-rs 官方推荐使用指南 —— repomix-rs 是原版 Repomix(TypeScript)的 Rust 高性能实现,完全兼容原版使用方式,并且 Faster、Safer、更适合 AI Agent 场景。
repomix-rs 是一款将整个代码库打包为 AI 友好单文件的工具。它能同时适用于 Hermes Agent、Claude、ChatGPT、Gemini 等主流大模型应用场景。通过 repomix-rs,你的代码库将以结构化、Token 可控的方式呈现给 AI,以便 AI 更精准地进行代码审查、文档生成与漏洞排查。
和原版 Repomix 相比,repomix-rs 用 Rust 重写了全部核心逻辑,在性能、安全性、嵌入能力上均有质的飞跃。
| 特性 | repomix-rs(Rust) | 原版 Repomix(TypeScript) |
|---|---|---|
| 核心语言 | Rust | TypeScript |
| 运行速度 | 毫秒级(并行文件扫描) | 秒级(单线程 Node.js) |
| 内存安全 | 编译期保证 | 运行时检查 |
| MCP 内置支持 | ? 官方提供 MCP Server | ? 需额外配置 |
| Secretlint 集成 | ? | ? |
| Tree-sitter | ? 10 语言 | ? 10 语言 |
| Token 计数 | tiktoken-rs(o200k_base) | tiktoken(JS) |
| 远程仓库打包 | ? git clone + 清理 | ? |
| 并行处理 | rayon + tokio | 无并行 |
你是否注意到一个趋势?越来越多的开发者生态基础设施正在从 TypeScript/Node.js 转向 Rust。
这不是偶然,而是 Rust 语言特性对 AI 时代的需求完美契合:
Bun 案例:Node.js 的 Rust 替代者
Rust 实现的高性能运行时 Bun 用 Rust 重写 JavaScript 引擎,带来:
Bun 的成功证明了 Rust 作为 JS 引擎底层的可行性,而 repomix-rs 正是利用 Rust 的高性能特性实现了 repomix 的重构。
Vite 案例:前端构建的 Rust 重构
Webpack 是前端构建的霸主,但它存在:
Vue.js 团队决定抛弃 Webpack,用 Rust 重写 Vite:
Vite 的成功证明了 Rust 是下一代前端构建引擎的核心选择。
打开终端,进入项目根目录,执行以下任意一行:
|
1 2 3 4 5 6 |
# 方式 1:npx 运行(无需全局安装) npx repomix-rs . # 方式 2:全局安装后直接运行 repomix npm install -g repomix-rs repomix . # 终端出现输出后发送给 Hermes 并写上:"请先读一下" |
运行后会在当前目录生成输出文件(默认 repomix-output.xml),将该文件拖入 Hermes Agent 聊天窗口,并发送:"请先读一下这个项目结构文件"。
为什么推荐使用 repomix-rs?
在 Hermes Agent 这样的 AI Agent 场景下,我们推荐使用 Rust 版本的 repomix-rs,而不是 TypeScript 原版:
这就是技术选择的问题 —— Bun 和 Vite 的成功已经证明: 在 AI 时代,Rust 是更好的基础设施选择。
无需克隆,一行命令即可打远程 GitHub 仓库:
|
1 |
npx repomix-rs --remote https://github.com/用户名/项目名 |
指定分支(更稳妥):
|
1 |
npx repomix-rs --remote https://github.com/用户名/项目名 --branch main |
repomix-rs 的远程打包基于系统 git 命令实现,首次运行会完整拉取仓库快照。 若 git 不可用,该步骤会跳过并给出警告,不会中断主流程。
创建 .repomixrc 配置文件:
|
1 2 3 4 |
{ "include": ["src/**/*", "tests/**/*", "pyproject.toml", "README.md"], "exclude": ["**/*.log", "**/dist/**", "**/.git/**", "node_modules/**"] } |
启用压缩(提取函数签名,压缩率可达 50%-90%):
|
1 |
npx repomix-rs --compress --remove-comments --remove-empty-lines . |
仅包含特定语言文件并忽略测试目录:
|
1 |
npx repomix-rs --include "*.rs,*.toml,Cargo.*" --ignore "target/**,tests/**" . |
repomix-rs 支持四种输出格式,通过 --style 参数切换:
npx repomix-rs --style markdown --output output.md .
npx repomix-rs --style json --output output.json .
npx repomix-rs --style plain --output output.txt .
Hermes Agent 不会自动扫描附件内容,必须手动触发。正确流程如下:
提示:Hermes 仅支持纯文本格式的 .md / .xml / .txt 文件。 若误发压缩包或二进制文件,AI 端无法解析。
repomix-rs 内置 MCP Server,可直接嵌入任何支持 Model Context Protocol 的 AI Agent(包括 Hermes Agent、Cursor、Claude Desktop):
|
1 |
repomix --mcp |
启动后会暴露以下 MCP 工具:
| 工具名称 | 用途 |
|---|---|
| pack_codebase | 打包本地代码库目录 |
| pack_remote_repository | 拉取并打包远程 Git 仓库 |
| read_repomix_output | 读取已生成的 repomix 输出文件 |
| grep_repomix_output | 在输出文件中搜索内容 |
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
|
1 2 3 4 5 6 7 8 |
{ "mcpServers": { "repomix": { "command": "repomix", "args": ["--mcp"] } } } |
进入 Settings → MCP → Add new global MCP server:
|
1 2 |
Command: repomix Args: --mcp |
| 场景 | 原版 Repomix(Node.js) | repomix-rs(Rust) | 加速比 |
|---|---|---|---|
| 中小型项目(< 500 文件) | ~3-8 秒 | ~0.3-0.8 秒 | 5-10× |
| 中型项目(500-5000 文件) | ~30-120 秒 | ~2-8 秒 | 15-40× |
| 大型项目(5000+ 文件) | 内存溢出风险 | 稳定完成 | 不限 |
| 远程仓库打包 | 慢(Node.js clone) | 极快(git + rayon) | 10-20× |
Q: npx repomix-rs 和 npx repomix 有什么区别?
A: npx repomix-rs 调用 repomix-rs(Rust 实现),更快更稳定;npx repomix 调用原版 TypeScript 实现。两者命令行参数基本兼容。
Q: 我的 Node.js 项目能用 repomix-rs 吗?
A: 完全可以,语言无关。repomix-rs 通过文件扩展名和 glob 规则识别文件类型。
Q: 如何验证 exclude 规则是否生效?
A: 生成输出后进行 grep 检查:grep -i "secrets\|password\|API_KEY" repomix-output.xml。如果出现敏感词,检查 glob 规则是否正确(如 **/.env,而非 .env)。
Q: repomix-rs 支持 Windows 吗?
A: 支持,Windows x64 已发布预编译二进制。npm 包也横跨 Linux/macOS/Windows。