mcpField
R
Repomix

Repomix

本地服务
repomix.com开发工具29.1k今天更新

关于 Repomix

Repomix 是一个 MCP 服务,可将本地或远程代码库打包为适合 AI 阅读和检索的单一文件。它面向需要把整个代码库交给 LLM 或编码 Agent 处理的开发者,并提供 Token 统计和敏感凭证过滤。

主要功能

  1. 01打包整个代码库为单一文件
  2. 02按 .gitignore 等规则过滤文件
  3. 03统计每个文件及整个仓库的 Token 数
  4. 04使用 Secretlint 排除凭证类文件
  5. 05通过 Tree-sitter 压缩代码结构
  6. 06支持 XML、Markdown、JSON 输出

适用场景

  1. 01将代码库交给 LLM 进行代码审查或重构
  2. 02为大型项目生成文档或单元测试
  3. 03打包远程 GitHub 仓库进行分析

MCP 相关

该项目以 MCP 服务的形式提供,可向 MCP 客户端暴露代码库打包与检索能力。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"yamadashy-repomix": {
"command": "npx",
"args": [
"-y",
"repomix"
]
}
}
}
启动命令npx -y repomix

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmrepomix1.18.1

工具

6

收录的工具列表 · 更新于 2 周前

参数类型必填说明
styleenum否输出格式:xml(结构化标签,默认)、markdown(包含代码块,便于阅读)、json(键值形式,便于机器处理)或 plain(使用分隔符的简单文本)xml | markdown | json | plain
compressboolean否启用 Tree-sitter 压缩,以提取关键代码签名和结构,同时移除实现细节。在保留语义的同时,可减少约 70% 的 token 使用量。通常无需使用,因为 grep_repomix_output 支持增量检索内容。仅当需要获取大型代码库的全部内容时使用(默认:false)。
directorystring是要打包的目录(绝对路径)。此进程可读取的任何目录都可以打包。
ignorePatternsstring否使用 fast-glob 模式指定要排除的其他文件。多个模式可用逗号分隔(例如,"test/**,*.spec.js", "node_modules/**,dist/**")。这些模式会补充 .gitignore 和内置排除规则。
outputPatternsarray否按文件设置包含级别。按顺序评估模式,以第一个匹配项为准;directoryStructureOnly 的优先级高于 compress;如果匹配项未设置这两个标志,则强制包含完整内容(可用于在全局压缩时排除特定文件)。未匹配任何模式的文件将使用全局 compress 设置。此设置会覆盖目标仓库 repomix.config.json 中的 output.patterns。示例:设置 compress=true 和 outputPatterns=[{"pattern":"src/core/**"}],可在压缩其他所有内容的同时保留 src/core 的完整细节。
topFilesLengthinteger否在代码库分析的指标摘要中显示的最大文件数量(按文件大小排序,默认:10)
includePatternsstring否使用 fast-glob 模式指定要包含的文件。多个模式可用逗号分隔(例如,"**/*.{js,ts}", "src/**,docs/**")。仅处理匹配的文件。适用于聚焦代码库的特定部分。

详细介绍

特别感谢:

Warp 赞助商
Warp,专为使用多个 AI Agent 编码而打造

适用于 MacOS、Linux 和 Windows


CodeRabbit 赞助商 ### [CodeRabbit | AI 代码审查](https://coderabbit.link/repomix) [立即将代码审查耗时和 Bug 减半。](https://coderabbit.link/repomix)

Repomix

将代码库打包成适合 AI 使用的格式

在线使用 Repomix!👉 repomix.com

有问题想讨论?加入我们的 Discord!
分享你的使用体验和技巧
了解新功能的最新动态
获取配置和使用方面的帮助


npm npm Actions Status codecov CodeRabbit Pull Request Reviews Sponsors Discord

DeepWiki

📦 Repomix 是一款强大的工具,可将整个代码仓库打包成一个适合 AI 使用的文件。
当你需要将代码库提供给大模型(LLM)或 Claude、ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等其他 AI 工具时,它再合适不过。

欢迎赞助我。

Sponsor

Sponsors

🏆 开源奖项提名

我们倍感荣幸!Repomix 已获提名,角逐 JSNation Open Source Awards 2025 的 Powered by AI 类别奖项。

这离不开大家对 Repomix 的使用和支持。谢谢大家!

🎉 全新:Repomix 网站和 Discord 社区!

期待在那里与大家相见!

🌟 功能

  • 针对 AI 优化:以便于 AI 理解和处理的方式格式化代码库。
  • Token 计数:提供每个文件和整个仓库的 Token 数量,方便了解大模型的上下文限制。
  • 简单易用:只需一条命令即可打包整个仓库。
  • 可自定义:轻松配置要包含或排除的内容。
  • 了解 Git:自动遵循 .gitignore、.ignore 和 .repomixignore 文件。
  • 注重安全:集成 Secretlint,检测符合已知凭据格式的文件,并将其排除在输出之外。
  • 代码压缩:--compress 选项使用 Tree-sitter 提取关键代码元素,在保留结构的同时减少 Token 数量。

🚀 快速开始

使用 CLI 工具 >_

无需安装,即可在项目目录中立即试用 Repomix:

npx repomix@latest

也可以全局安装,以便反复使用:

# Install using npm
npm install -g repomix

# Alternatively using yarn
yarn global add repomix

# Alternatively using bun
bun add -g repomix

# Alternatively using Homebrew (macOS/Linux)
brew install repomix

# Then run in any project directory
repomix

就是这么简单!Repomix 会在当前目录中生成 repomix-output.xml 文件,其中以便于 AI 理解的格式包含整个仓库。

然后,你可以将此文件发送给 AI 助手,并附上类似这样的提示词:

This file contains all the files in the repository combined into one.
I want to refactor the code, so please review it first.

Repomix 文件使用方式 1

当你提出具体的修改要求时,AI 可能会据此生成代码。借助 Claude 的 Artifacts 等功能,你还可以输出多个文件,从而生成多个相互依赖的代码片段。

Repomix 文件使用方式 2

祝编码愉快!🚀

使用网站 🌐

想快速试用?访问官方网站 repomix.com。只需输入仓库名称,填写任何可选信息,然后点击 Pack 按钮,即可查看生成的输出。

可用选项

网站提供多项实用功能:

  • 可自定义输出格式(XML、Markdown 或纯文本)
  • 即时估算 Token 数量
  • 更多功能!
使用浏览器扩展 🧩

直接从任何 GitHub 仓库快速访问 Repomix!我们的 Chrome 扩展会在 GitHub 仓库页面添加一个方便使用的“Repomix”按钮。

Repomix 浏览器扩展

安装
功能
  • 一键从任何 GitHub 仓库访问 Repomix
  • 更多令人期待的功能即将推出!
使用 VSCode 扩展 ⚡️

由社区维护的 VSCode 扩展 Repomix Runner(由 massdo 创建)让你只需点击几下,就能直接在编辑器中运行 Repomix。你可以在任意文件夹中运行它、轻松管理输出,并通过 VSCode 直观的界面控制一切。

想要将输出保存为文件,还是只获取内容?需要自动清理吗?这个扩展都能满足你的需求。此外,它还能与你现有的 repomix.config.json 顺畅配合。

立即前往 VSCode Marketplace 试用! 源代码可在 GitHub 上获取。

替代工具 🛠️

如果你使用 Python,可以了解一下 Gitingest。它更适合 Python 生态系统和数据科学工作流: https://github.com/cyclotruc/gitingest

📊 使用方法

打包整个代码仓库:

repomix

打包指定目录:

repomix path/to/directory

使用 glob 模式打包指定文件或目录:

repomix --include "src/**/*.ts,**/*.md"

排除指定文件或目录:

repomix --ignore "**/*.log,tmp/"

打包远程代码仓库:

repomix --remote https://github.com/yamadashy/repomix

# You can also use GitHub shorthand:
repomix --remote yamadashy/repomix

# You can specify the branch name, tag, or commit hash:
repomix --remote https://github.com/yamadashy/repomix --remote-branch main

# Or use a specific commit hash:
repomix --remote https://github.com/yamadashy/repomix --remote-branch 935b695

# Another convenient way is specifying the branch's URL
repomix --remote https://github.com/yamadashy/repomix/tree/main

# Commit's URL is also supported
repomix --remote https://github.com/yamadashy/repomix/commit/836abcd7335137228ad77feb28655d85712680f1

从文件列表打包文件(通过 stdin 管道传入):

# Using find command
find src -name "*.ts" -type f | repomix --stdin

# Using git to get tracked files
git ls-files "*.ts" | repomix --stdin

# Using grep to find files containing specific content
grep -l "TODO" **/*.ts | repomix --stdin

# Using ripgrep to find files with specific content
rg -l "TODO|FIXME" --type ts | repomix --stdin

# Using ripgrep (rg) to find files
rg --files --type ts | repomix --stdin

# Using sharkdp/fd to find files
fd -e ts | repomix --stdin

# Using fzf to select from all files
fzf -m | repomix --stdin

# Interactive file selection with fzf
find . -name "*.ts" -type f | fzf -m | repomix --stdin

# Using ls with glob patterns
ls src/**/*.ts | repomix --stdin

# From a file containing file paths
cat file-list.txt | repomix --stdin

# Direct input with echo
echo -e "src/index.ts\nsrc/utils.ts" | repomix --stdin

--stdin 选项允许你将文件路径列表通过管道传给 Repomix,从而灵活选择要打包的文件。

使用 --stdin 时,指定的文件实际上会添加到包含模式中。这意味着常规的包含和忽略行为仍然适用——如果通过 stdin 指定的文件匹配忽略模式,仍会被排除。

说明

使用 --stdin 时,文件路径可以是相对路径或绝对路径,Repomix 会自动处理路径解析和去重。

在输出中包含 git 日志:

# Include git logs with default count (50 commits)
repomix --include-logs

# Include git logs with specific commit count
repomix --include-logs --include-logs-count 10

# Combine with diffs for comprehensive git context
repomix --include-logs --include-diffs

git 日志包含每次提交的日期、消息和文件路径,可为 AI 分析代码演进和开发模式提供有价值的上下文。

压缩输出:

repomix --compress

# You can also use it with remote repositories:
repomix --remote yamadashy/repomix --compress

初始化新的配置文件(repomix.config.json):

repomix --init

生成打包文件后,你可以将它与 ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等生成式 AI 工具搭配使用。

Docker 使用方法 🐳

你也可以使用 Docker 运行 Repomix。
如果你想在隔离环境中运行 Repomix,或更喜欢使用容器,这种方式会很有用。

基本用法(当前目录):

docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix

打包指定目录:

docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory

处理远程代码仓库,并将输出保存到 output 目录:

docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote https://github.com/yamadashy/repomix
提示词示例

使用 Repomix 生成打包文件后,你可以将它与 ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等 AI 工具搭配使用。 以下是一些示例提示词,助你快速上手:

代码审查与重构

进行全面的代码审查并提出重构建议:

This file contains my entire codebase. Please review the overall structure and suggest any improvements or refactoring opportunities, focusing on maintainability and scalability.
生成文档

生成项目文档:

Based on the codebase in this file, please generate a detailed README.md that includes an overview of the project, its main features, setup instructions, and usage examples.
生成测试用例

生成测试用例:

Analyze the code in this file and suggest a comprehensive set of unit tests for the main functions and classes. Include edge cases and potential error scenarios.
代码质量评估

评估代码质量及其对最佳实践的遵循情况:

Review the codebase for adherence to coding best practices and industry standards. Identify areas where the code could be improved in terms of readability, maintainability, and efficiency. Suggest specific changes to align the code with best practices.
库概览

从较高层次了解该库

This file contains the entire codebase of library. Please provide a comprehensive overview of the library, including its main purpose, key features, and overall architecture.

你可以根据自己的具体需求和所用 AI 工具的能力自由修改这些提示词。

社区讨论

欢迎查看我们的社区讨论,用户会在其中分享:

  • 他们使用 Repomix 搭配哪些 AI 工具
  • 他们发现的有效提示词
  • Repomix 如何帮助他们
  • 充分利用 AI 代码分析的技巧和窍门

欢迎加入讨论并分享你的体验!你的见解或许能帮助他人更好地使用 Repomix。

输出文件格式

Repomix 会生成一个单一文件,并在代码库的不同部分之间使用清晰的分隔符。
为了增强 AI 的理解能力,输出文件会以面向 AI 的说明开头,让 AI 模型更容易理解打包后仓库的上下文和结构。

XML 格式(默认)

XML 格式以层级方式组织内容:

This file is a merged representation of the entire codebase, combining all repository files into a single document.

<file_summary>
  (Metadata and usage AI instructions)
</file_summary>

<directory_structure>
src/
cli/
cliOutput.ts
index.ts

(...remaining directories)
</directory_structure>

<files>
<file path="src/index.js">
  // File contents here
</file>

(...remaining files)
</files>

<instruction>
(Custom instructions from `output.instructionFilePath`)
</instruction>

如果你想了解 XML 标签在 AI 场景中的潜力,请参阅:
https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags

当提示词包含上下文、指令和示例等多个组成部分时,XML 标签可能会带来显著帮助。它们能帮助 Claude 更准确地解析提示词,从而生成更高质量的输出。

这意味着 Repomix 的 XML 输出不仅是另一种格式,还可能是将代码库输入 AI 系统进行分析、代码审查或其他任务的更有效方式。

Markdown 格式

要生成 Markdown 格式的输出,请使用 --style markdown 选项:

repomix --style markdown

Markdown 格式以层级方式组织内容:

This file is a merged representation of the entire codebase, combining all repository files into a single document.

# File Summary

(Metadata and usage AI instructions)

# Repository Structure

```
src/
  cli/
    cliOutput.ts
    index.ts
```

(...remaining directories)

# Repository Files

## File: src/index.js

```
// File contents here
```

(...remaining files)

# Instruction

(Custom instructions from `output.instructionFilePath`)

这种格式结构清晰、易于阅读,既方便人类阅读,也便于 AI 系统解析。

JSON 格式

要生成 JSON 格式的输出,请使用 --style json 选项:

repomix --style json

JSON 格式会将内容组织为具有驼峰命名属性的层级 JSON 对象:

{
  "fileSummary": {
    "generationHeader": "This file is a merged representation of the entire codebase, combined into a single document by Repomix.",
    "purpose": "This file contains a packed representation of the entire repository's contents...",
    "fileFormat": "The content is organized as follows...",
    "usageGuidelines": "- This file should be treated as read-only...",
    "notes": "- Some files may have been excluded based on .gitignore, .ignore, and .repomixignore rules..."
  },
  "userProvidedHeader": "Custom header text if specified",
  "directoryStructure": "src/\n  cli/\n    cliOutput.ts\n    index.ts\n  config/\n    configLoader.ts",
  "files": {
    "src/index.js": "// File contents here",
    "src/utils.js": "// File contents here"
  },
  "instruction": "Custom instructions from instructionFilePath"
}

这种格式适用于:

  • 程序化处理:易于使用 JSON 库解析和操作
  • API 集成:可供 Web 服务和应用直接使用
  • AI 工具兼容性:为机器学习和 AI 系统提供结构化格式
  • 数据分析:借助 jq 等工具轻松提取特定信息
使用 jq 处理 JSON 输出

JSON 格式便于以编程方式提取特定信息:

# List all file paths
cat repomix-output.json | jq -r '.files | keys[]'

# Count total number of files
cat repomix-output.json | jq '.files | keys | length'

# Extract specific file content
cat repomix-output.json | jq -r '.files["README.md"]'
cat repomix-output.json | jq -r '.files["src/index.js"]'

# Find files by extension
cat repomix-output.json | jq -r '.files | keys[] | select(endswith(".ts"))'

# Get files containing specific text
cat repomix-output.json | jq -r '.files | to_entries[] | select(.value | contains("function")) | .key'

# Extract directory structure
cat repomix-output.json | jq -r '.directoryStructure'

# Get file summary information
cat repomix-output.json | jq '.fileSummary.purpose'
cat repomix-output.json | jq -r '.fileSummary.generationHeader'

# Extract user-provided header (if exists)
cat repomix-output.json | jq -r '.userProvidedHeader // "No header provided"'

# Create a file list with sizes
cat repomix-output.json | jq -r '.files | to_entries[] | "\(.key): \(.value | length) characters"'
纯文本格式

要生成纯文本格式的输出,请使用 --style plain 选项:

repomix --style plain
This file is a merged representation of the entire codebase, combining all repository files into a single document.

================================================================
File Summary
================================================================
(Metadata and usage AI instructions)

================================================================
Directory Structure
================================================================
src/
  cli/
    cliOutput.ts
    index.ts
  config/
    configLoader.ts

(...remaining directories)

================================================================
Files
================================================================

================
File: src/index.js
================
// File contents here

================
File: src/utils.js
================
// File contents here

(...remaining files)

================================================================
Instruction
================================================================
(Custom instructions from `output.instructionFilePath`)
命令行选项
基本选项
  • -v, --version:显示版本信息并退出
CLI 输入/输出选项
选项说明
--verbose启用详细调试日志(显示文件处理、令牌数量和配置详情)
--quiet除错误外,隐藏所有控制台输出(适用于脚本)
--stdout将打包后的输出直接写入 stdout,而非文件(隐藏所有日志)
--stdin从 stdin 读取文件路径,每行一个(指定的文件会直接处理)
--copy处理完成后,将生成的输出复制到系统剪贴板
--token-count-tree [threshold]显示带令牌数量的文件树;可选阈值,仅显示令牌数 ≥N 的文件(例如:--token-count-tree 100)
--top-files-len <number>在摘要中显示的最大文件数量(默认值:5)
Repomix 输出选项
选项描述
-o, --output <file>输出文件路径(默认:repomix-output.xml,使用 "-" 可输出到标准输出)
--style <style>输出格式:xml、markdown、json 或 plain(默认:xml)
--output-file-path-style <style>输出中显示文件路径的方式:target-relative 或 cwd-relative(默认:target-relative)
--parsable-style转义特殊字符以确保 XML/Markdown 格式有效(当输出包含会破坏格式的代码时需要此选项)
--compress使用 Tree-sitter 解析提取核心代码结构(类、函数、接口)
--output-show-line-numbers为输出中的每一行添加行号前缀
--no-file-summary从输出中省略文件摘要部分
--no-directory-structure从输出中省略目录树可视化内容
--no-files仅生成元数据,不包含文件内容(适用于仓库分析)
--remove-comments打包前移除所有代码注释
--remove-empty-lines移除所有文件中的空行
--truncate-base64截断较长的 base64 数据字符串,以减小输出体积
--header-text <text>在输出开头添加自定义文本
--instruction-file-path <path>包含要添加到输出中的自定义指令的文件路径
--split-output <size>将输出拆分为多个带编号的文件(例如:repomix-output.1.xml);大小可设为 500kb、2mb 或 1.5mb
--include-empty-directories在目录结构中包含没有文件的文件夹
--include-full-directory-structure在输出中显示完整目录树,包括与 --include 模式不匹配的文件
--no-git-sort-by-changes不按 git 更改频率对文件排序(默认:更改最多的文件排在最前)
--include-diffs添加 git 差异部分,显示工作树和暂存区中的更改
--include-logs添加包含提交信息和更改文件的 git 提交历史
--include-logs-count <count>使用 --include-logs 时包含的近期提交数量(默认:50)
文件选择选项
选项描述
--include <patterns>仅包含匹配这些 glob 模式的文件(以逗号分隔,例如:"src/**/*.js,*.md")
-i, --ignore <patterns>要排除的其他模式(以逗号分隔,例如:"*.test.js,docs/**")
--no-gitignore不使用 .gitignore 规则筛选文件
--no-dot-ignore不使用 .ignore 规则筛选文件
--no-default-patterns不应用内置忽略模式(node_modules、.git、构建目录等)
远程仓库选项
选项描述
--remote <url>克隆并打包远程仓库(GitHub URL 或 user/repo 格式)
--remote-branch <name>要使用的特定分支、标签或提交(默认:仓库的默认分支)
--remote-trust-config信任并加载远程仓库中的配置文件(出于安全考虑,默认禁用)。在交互式终端中,系统会显示配置并要求你确认
配置选项
选项描述
-c, --config <path>使用自定义配置文件,而不是 repomix.config.json
--init使用默认值创建新的 repomix.config.json 文件
--global与 --init 搭配使用时,在主目录而非当前目录中创建配置文件
安全选项
  • --no-security-check:跳过对 API 密钥和密码等敏感数据的扫描
Token 计数选项
  • --token-count-encoding <encoding>:用于计数的分词器模型:o200k_base(GPT-4o)、cl100k_base(GPT-3.5/4)等(默认值:o200k_base)
  • --token-budget <number>:当打包后的输出超过 N 个 token 时,以非零退出码失败。适用于 CI 流水线和 Agent 工作流,可确保输出不超出目标模型的上下文窗口。仍会生成输出;只有退出码会标示是否超出限制。
MCP
  • --mcp:作为模型上下文协议服务运行,以便与 AI 工具集成
  • --sandbox [dir]:(与 --mcp 一起使用)将 MCP 服务的文件工具限制在工作区目录中(默认为当前工作目录;例如 --sandbox path/to/project)——所有路径均相对于该根目录,拒绝绝对路径和主机路径,并禁用远程打包、技能生成以及附加外部输出。
Agent 技能生成
选项描述
--skill-generate [name]将输出生成为 Claude Agent Skills 格式,并写入 .claude/skills/<name>/ 目录(若省略名称,则自动生成)
--skill-project-name <name>覆盖生成的 Skills 描述中使用的项目名称
--skill-output <path>直接指定技能输出目录路径(跳过位置提示)
-f, --force跳过所有确认提示(技能目录覆盖、远程配置信任)
监视模式
  • -w, --watch:监视文件更改并自动重新打包。对快速连续的更改进行防抖处理(300ms),并在每次重新构建时记录时间戳。按 Ctrl+C 停止。

    监视模式仅适用于本地目录,因此不能与 --remote、位置参数中的远程仓库 URL、--stdout、--stdin、--split-output、--skill-generate 或 --copy 一起使用(无论是在命令行还是配置文件中设置)。

示例
# Basic usage
repomix

# Custom output
repomix -o output.xml --style xml

# Output to stdout
repomix --stdout > custom-output.txt

# Send output to stdout, then pipe into another command (for example, simonw/llm)
repomix --stdout | llm "Please explain what this code does."

# Custom output with compression
repomix --compress

# Process specific files
repomix --include "src/**/*.ts" --ignore "**/*.test.ts"

# Split output into multiple files (max size per part)
repomix --split-output 20mb

# Remote repository with branch
repomix --remote https://github.com/user/repo/tree/main

# Remote repository with commit
repomix --remote https://github.com/user/repo/commit/836abcd7335137228ad77feb28655d85712680f1

# Remote repository with shorthand
repomix --remote user/repo

# Watch mode — automatically re-pack on file changes
repomix --watch
repomix -w --include "src/**/*.ts"
更新 Repomix

要更新全局安装的 Repomix:

# Using npm
npm update -g repomix

# Using yarn
yarn global upgrade repomix

# Using bun
bun update -g repomix

使用 npx repomix 通常更方便,因为它始终使用最新版本。

远程仓库处理

Repomix 支持处理远程 Git 仓库,无需手动克隆。此功能可让你通过一条命令快速分析任何公开的 Git 仓库。

要处理远程仓库,请使用 --remote 选项并在后面指定仓库 URL:

repomix --remote https://github.com/yamadashy/repomix

你也可以使用 GitHub 的简写格式:

repomix --remote yamadashy/repomix

你可以指定分支名称、标签或提交哈希:

# Using --remote-branch option
repomix --remote https://github.com/yamadashy/repomix --remote-branch main

# Using branch's URL
repomix --remote https://github.com/yamadashy/repomix/tree/main

或者使用特定的提交哈希:

# Using --remote-branch option
repomix --remote https://github.com/yamadashy/repomix --remote-branch 935b695

# Using commit's URL
repomix --remote https://github.com/yamadashy/repomix/commit/836abcd7335137228ad77feb28655d85712680f1

说明

出于安全考虑,默认不会加载远程仓库中的配置文件(repomix.config.*)。这可以防止不受信任的仓库通过配置文件执行代码。仍会应用你的全局配置和 CLI 选项。若要信任远程仓库的配置,请使用 --remote-trust-config,或设置 REPOMIX_REMOTE_TRUST_CONFIG=true——在交互式终端中,Repomix 会显示该配置,并在加载前要求你确认。请参阅远程仓库配置信任。

使用 --config 和 --remote 时,必须提供绝对路径(例如 --config /home/user/repomix.config.json)。

代码压缩

--compress 选项使用 Tree-sitter 执行智能代码提取,重点保留重要的函数和类签名,同时移除实现细节。这有助于减少 token 数量,同时保留重要的结构信息。

repomix --compress

例如,以下代码:

import { ShoppingItem } from './shopping-item';

/**
 * Calculate the total price of shopping items
 */
const calculateTotal = (
  items: ShoppingItem[]
) => {
  let total = 0;
  for (const item of items) {
    total += item.price * item.quantity;
  }
  return total;
}

// Shopping item interface
interface Item {
  name: string;
  price: number;
  quantity: number;
}

将被压缩为:

import { ShoppingItem } from './shopping-item';
⋮----
/**
 * Calculate the total price of shopping items
 */
const calculateTotal = (
  items: ShoppingItem[]
) => {
⋮----
// Shopping item interface
interface Item {
  name: string;
  price: number;
  quantity: number;
}

说明

这是一项实验性功能,我们将根据用户反馈和实际使用情况持续改进。

单文件包含级别(output.patterns)

--compress 会对所有文件应用同一级别,而 output.patterns 可让你在配置文件中按 glob 单独控制详细程度。每个条目都会按 glob 匹配文件(匹配方式与 include/ignore 相同),并覆盖匹配文件的全局 output.compress 设置:

{
  "output": {
    "compress": false, // global default acts as the catch-all
    "patterns": [
      { "pattern": "docs/**/*", "compress": true },
      { "pattern": "website/**/*", "directoryStructureOnly": true }
    ]
  }
}

共有三个级别:

  • 完整内容(默认)——包含文件的完整内容。
  • 压缩(compress: true)——内容会经过与 --compress 相同的 Tree-sitter 流程处理。
  • 仅目录结构(directoryStructureOnly: true)——文件会列在目录结构中,但其内容块会从输出中完全省略。

语义:

  • 按数组顺序评估模式;对于给定文件,第一个匹配的模式优先生效。
  • 匹配模式中的标志会覆盖全局 output.compress 设置。匹配但未设置任何一个标志的模式会强制该文件使用完整内容(可用于将文件加入白名单,使其不受全局 compress 设置影响)。
  • 同时设置 directoryStructureOnly 和 compress 时,directoryStructureOnly 优先。
  • 如果没有模式匹配,则应用全局行为(完整内容,或当 output.compress 为 true 时压缩)。

此选项只能在配置文件中使用;没有用于按模式设置级别的 CLI 标志。

优化 Token 数量

了解代码库中 Token 的分布对于优化 AI 交互至关重要。使用 --token-count-tree 选项可查看项目中 Token 用量的可视化结果:

repomix --token-count-tree

这会显示代码库的层级视图及 Token 数量:

🔢 Token Count Tree:
────────────────────
└── src/ (70,925 tokens)
    ├── cli/ (12,714 tokens)
    │   ├── actions/ (7,546 tokens)
    │   └── reporters/ (990 tokens)
    └── core/ (41,600 tokens)
        ├── file/ (10,098 tokens)
        └── output/ (5,808 tokens)

你也可以设置最低 Token 阈值,以聚焦较大的文件:

repomix --token-count-tree 1000  # Only show files/directories with 1000+ tokens

这有助于你:

  • 找出 Token 密集型文件,这些文件可能超出 AI 的上下文限制
  • 使用 --include 和 --ignore 模式优化文件选择
  • 通过针对占比最大的文件规划压缩策略
  • 为 AI 分析准备代码时,平衡内容与上下文
为大型代码库拆分输出

处理大型代码库时,打包后的输出可能会超过某些 AI 工具施加的文件大小限制(例如 Google AI Studio 的 1MB 限制)。使用 --split-output 可自动将输出拆分为多个文件:

repomix --split-output 1mb

这会生成带编号的文件,例如:

  • repomix-output.1.xml
  • repomix-output.2.xml
  • repomix-output.3.xml

大小可使用单位指定:500kb、1mb、2mb、1.5mb 等。支持小数值。

说明

文件会按顶层目录分组,以保留上下文。单个文件或目录绝不会被拆分到多个输出文件中。

MCP 服务集成

Repomix 支持 Model Context Protocol(MCP),让 AI 助手可以直接与代码库交互。作为 MCP 服务运行时,Repomix 提供的工具可让 AI 助手打包本地或远程代码仓库以供分析,而无需手动准备文件。

repomix --mcp
沙盒模式

默认情况下,MCP 服务可以读取宿主用户有权访问的任何路径。这对可信的本地助手来说很方便,但当服务暴露给不可信的客户端或 Agent 时,权限范围就过大了。--sandbox 标志会将服务的文件工具限制在单个工作区目录内:

# Confine to the current working directory
repomix --mcp --sandbox

# Confine to a specific directory
repomix --mcp --sandbox path/to/project

启用沙盒模式后,所有路径都相对于工作区根目录(绝对路径、~、.. 和 Windows 驱动器/UNC 路径都会被拒绝,通过符号链接解析到根目录之外的路径也会被拒绝),不会加载配置文件,并且只会注册只读且受根目录限制的工具;远程打包、技能生成和附加外部输出功能均已禁用。原始文件工具(file_system_read_file、file_system_read_directory)仅在沙盒模式下可用,此时工作区根目录会限制其可访问的范围。这是对工具范围的应用层限制,并非操作系统层面的沙盒。

不使用 --sandbox 时,pack_codebase 会加载并信任要打包目录中的 repomix.config.*,与在该目录中从命令行运行 repomix 一样。配置文件本质上是代码:加载时可能会运行,并读取仓库之外的文件。如果助手可能会打包你不信任的目录,例如克隆的第三方仓库,请使用 --sandbox。详情请参阅 MCP 服务指南。

配置 MCP 服务

要将 Repomix 用作 Claude 等 AI 助手的 MCP 服务,你需要配置 MCP 设置:

对于 VS Code:

你可以使用以下任一方法在 VS Code 中安装 Repomix MCP 服务:

  1. 使用安装徽章:

在 VS Code 中安装 在 VS Code Insiders 中安装

  1. 使用命令行:
code --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'

对于 VS Code Insiders:

code-insiders --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'

对于 Cline(VS Code 扩展):

编辑 cline_mcp_settings.json 文件:

{
  "mcpServers": {
    "repomix": {
      "command": "npx",
      "args": [
        "-y",
        "repomix",
        "--mcp"
      ]
    }
  }
}

对于 Cursor:

在 Cursor 中,依次选择 Cursor Settings > MCP > + Add new global MCP server,添加新的 MCP 服务,并使用类似 Cline 的配置。

对于 Claude Desktop:

编辑 claude_desktop_config.json 文件,使用与 Cline 配置类似的设置。

对于 Claude Code:

要在 Claude Code 中将 Repomix 配置为 MCP 服务,请使用以下命令:

claude mcp add repomix -- npx -y repomix --mcp

或者,你也可以使用官方 Repomix 插件(请参阅下文的 Claude Code 插件部分)。

使用 Docker 代替 npx:

你可以使用 Docker 代替 npx 来运行 Repomix MCP 服务:

{
  "mcpServers": {
    "repomix-docker": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "ghcr.io/yamadashy/repomix",
        "--mcp"
      ]
    }
  }
}

配置完成后,你的 AI 助手便可直接使用 Repomix 的功能分析代码库,无需手动准备文件,从而提高代码分析工作流的效率。

可用的 MCP 工具

作为 MCP 服务运行时,Repomix 提供以下工具:

  1. pack_codebase:将本地代码目录打包为一个整合的 XML 文件,供 AI 分析
  • 参数:
    • directory:要打包的目录的绝对路径
    • compress:(可选,默认值:false)启用 Tree-sitter 压缩,提取关键代码签名和结构,同时移除实现细节。可在保留语义的同时减少约 70% 的 token 用量。通常无需启用,因为 grep_repomix_output 支持增量检索内容。仅在大型仓库中确实需要获取整个代码库内容时使用。
    • includePatterns:(可选)使用 fast-glob 模式指定要包含的文件。多个模式可用逗号分隔(例如,"/*.{js,ts}", "src/,docs/**")。仅处理匹配的文件。
    • ignorePatterns:(可选)使用 fast-glob 模式指定要额外排除的文件。多个模式可用逗号分隔(例如,"test/,*.spec.js", "node_modules/,dist/**")。这些模式会补充 .gitignore、.ignore 和内置排除规则。
    • outputPatterns:(可选)按文件设置包含级别,与配置文件中的 output.patterns 选项一致。一个由 { pattern, compress?, directoryStructureOnly? } 条目组成的数组;优先采用第一个匹配的模式,directoryStructureOnly 的优先级高于 compress,如果匹配项未设置这两个标志,则强制包含完整内容(可用于将文件排除在全局 compress 设置之外)。覆盖目标仓库 repomix.config.json 中的任何 output.patterns 设置。
    • topFilesLength:(可选,默认值:10)在代码库分析的指标摘要中显示的最大文件数(按文件大小排序)。
  1. attach_packed_output:附加现有的 Repomix 打包输出文件,供 AI 分析
  • 参数:
    • path:包含 repomix-output.xml 的目录路径,或打包后的仓库 XML 文件的直接路径
    • topFilesLength:(可选,默认值:10)在指标摘要中显示的最大文件数(按文件大小排序)
  • 功能:
    • 接受包含 repomix-output.xml 文件的目录,或 XML 文件的直接路径
    • 将该文件注册到 MCP 服务,并返回与 pack_codebase 工具相同的结构
    • 无需重新处理,即可访问现有的打包输出
    • 适用于处理之前生成的打包仓库
  1. pack_remote_repository:获取、克隆 GitHub 仓库,并将其打包为一个整合的 XML 文件,供 AI 分析
  • 参数:
    • remote:GitHub 仓库 URL 或 user/repo 格式(例如,“yamadashy/repomix”、“https://github.com/user/repo”或“https://github.com/user/repo/tree/branch”)
    • compress:(可选,默认为 false)启用 Tree-sitter 压缩,提取关键代码签名和结构,同时移除实现细节。在保留语义的同时,可将 token 用量减少约 70%。通常不需要启用,因为 grep_repomix_output 支持增量检索内容。仅当你需要获取大型仓库的完整代码库内容时才使用。
    • includePatterns:(可选)使用 fast-glob 模式指定要包含的文件。可用逗号分隔多个模式(例如,“/*.{js,ts}”、“src/,docs/**”)。只有匹配的文件才会被处理。
    • ignorePatterns:(可选)使用 fast-glob 模式指定要额外排除的文件。可用逗号分隔多个模式(例如,“test/,*.spec.js”、“node_modules/,dist/**”)。这些模式会补充 .gitignore、.ignore 和内置排除项。
    • outputPatterns:(可选)按文件设置包含级别,与配置文件中的 output.patterns 选项相同。由 { pattern, compress?, directoryStructureOnly? } 条目组成的数组;优先采用第一个匹配的模式;directoryStructureOnly 优先于 compress;如果匹配项未设置这两个标志,则会强制包含完整内容(适用于从全局 compress 设置中排除某些文件)。
    • topFilesLength:(可选,默认为 10)在代码库分析的指标摘要中显示的最大文件数量,按文件大小排序。
  1. read_repomix_output:读取 Repomix 生成的输出文件内容。支持指定行范围,分段读取大型文件。
  • 参数:
    • outputId:要读取的 Repomix 输出文件 ID
    • startLine:(可选)起始行号(从 1 开始,包含该行)。如果未指定,则从开头读取。
    • endLine:(可选)结束行号(从 1 开始,包含该行)。如果未指定,则读取至文件末尾。
  • 功能:
    • 专为基于 Web 的环境或沙盒应用设计
    • 使用 ID 获取之前生成的输出内容
    • 无需访问文件系统,即可读取已打包的代码库
    • 支持分段读取大型文件
  1. grep_repomix_output:使用类似 grep 的功能和 JavaScript RegExp 语法,在 Repomix 输出文件中搜索模式
  • 参数:
    • outputId:要搜索的 Repomix 输出文件 ID
    • pattern:搜索模式(JavaScript RegExp 正则表达式语法)
    • contextLines:(可选,默认为 0)每个匹配项前后显示的上下文行数。如果指定了 beforeLines/afterLines,则此设置会被覆盖。
    • beforeLines:(可选)每个匹配项前显示的上下文行数(类似 grep -B)。优先于 contextLines。
    • afterLines:(可选)每个匹配项后显示的上下文行数(类似 grep -A)。优先于 contextLines。
    • ignoreCase:(可选,默认为 false)执行不区分大小写的匹配
  • 功能:
    • 使用 JavaScript RegExp 语法,实现强大的模式匹配
    • 支持显示上下文行,帮助更好地理解匹配结果
    • 可分别控制匹配项前后的上下文行数
    • 支持区分大小写和不区分大小写的搜索选项
  1. file_system_read_file:读取沙盒工作区中的文件。仅在沙盒模式(--sandbox)下可用,此时工作区根目录限定了它可访问的范围。
  • 参数:
    • path:要读取的文件路径,相对于工作区根目录(例如 src/index.ts)
  • 注意:
    • 未使用 --sandbox 时不会注册
    • 如果内容匹配已知的密钥格式(Secretlint),则会拒绝读取,作为额外的启发式防护措施——访问边界是工作区根目录,而非扫描结果
  1. file_system_read_directory:列出沙盒工作区中目录的内容。仅在沙盒模式(--sandbox)下可用。
  • 参数:
    • path:要列出的目录路径,相对于工作区根目录(例如 . 或 src)
  • 功能:
    • 使用清晰的标识([FILE] 或 [DIR])显示文件和目录
    • 有助于探索项目结构并了解代码库的组织方式
Claude Code 插件

Repomix 为 Claude Code 提供官方插件,可与 AI 驱动的开发环境无缝集成。

安装

1. 添加 Repomix 插件市场:

/plugin marketplace add yamadashy/repomix

2. 安装插件:

# Install MCP server plugin (recommended foundation)
/plugin install repomix-mcp@repomix

# Install commands plugin (extends functionality)
/plugin install repomix-commands@repomix

# Install repository explorer plugin (AI-powered analysis)
/plugin install repomix-explorer@repomix

注意:建议将 repomix-mcp 插件作为基础。repomix-commands 插件提供便捷的斜杠命令,而 repomix-explorer 则增加 AI 驱动的分析能力。虽然可以单独安装,但同时使用这三个插件可获得最全面的体验。

或者,使用交互式插件安装程序:

/plugin

这将打开一个交互界面,供你浏览并安装可用插件。

可用插件

1. repomix-mcp(MCP 服务插件)

基础插件,通过 MCP 服务集成提供 AI 驱动的代码库分析功能。

功能:

  • 打包本地和远程代码库
  • 读取和搜索打包后的输出
  • 自动进行 Tree-sitter 压缩(令令牌减少约 70%)

2. repomix-commands(斜杠命令插件)

提供便捷的斜杠命令,并支持自然语言,方便快速执行操作。

可用命令:

  • /repomix-commands:pack-local - 使用各种选项打包本地代码库
  • /repomix-commands:pack-remote - 打包并分析远程 GitHub 代码库

使用示例:

/repomix-commands:pack-local
Pack this project as markdown with compression

/repomix-commands:pack-remote yamadashy/repomix
Pack only TypeScript files from the yamadashy/repomix repository

3. repomix-explorer(AI 分析 Agent 插件)

AI 驱动的代码库分析 Agent,使用 Repomix CLI 智能探索代码库。

功能:

  • 使用自然语言探索和分析代码库
  • 智能发现模式并理解代码结构
  • 使用 grep 和定向读取文件进行增量分析
  • 自动管理大型代码库的上下文

可用命令:

  • /repomix-explorer:explore-local - 在 AI 助手的帮助下分析本地代码库
  • /repomix-explorer:explore-remote - 在 AI 助手的帮助下分析远程 GitHub 代码库

使用示例:

/repomix-explorer:explore-local ./src
Find all authentication-related code

/repomix-explorer:explore-remote facebook/react
Show me the main component architecture

该 Agent 会自动:

  1. 运行 npx repomix@latest 打包代码库
  2. 使用 Grep 和 Read 工具高效搜索输出
  3. 提供全面分析,同时避免消耗过多上下文
优势
  • 无缝集成:Claude 无需手动准备即可直接分析代码库
  • 自然语言:使用对话式命令,无需记忆 CLI 语法
  • 始终最新:自动使用 npx repomix@latest 获取最新功能
  • 密钥扫描:Secretlint 会标记匹配已知凭据格式的文件,因此这些文件不会包含在输出中
  • 令牌优化:针对大型代码库进行 Tree-sitter 压缩

更多详情请参阅 .claude/plugins/ 目录中的插件文档。

Agent Skills 生成

Repomix 可以生成 Claude Agent Skills 格式的输出,创建结构化的 Skills 目录,供 AI 助手用作可复用的代码库参考。当你需要参考远程代码库中的实现时,这项功能尤其强大。

基本用法
# Generate Skills from local directory
repomix --skill-generate

# Generate with custom Skills name
repomix --skill-generate my-project-reference

# Generate with a custom project name in Skills descriptions
repomix --skill-generate --skill-project-name "My Project"

# Generate from remote repository
repomix --remote https://github.com/user/repo --skill-generate

运行命令时,Repomix 会提示你选择 Skills 的保存位置:

  1. 个人 Skills(~/.claude/skills/)- 可在计算机上的所有项目中使用
  2. 项目 Skills(.claude/skills/)- 可通过 git 与团队共享
非交互式用法

对于 CI 流水线和自动化脚本,可以使用 --skill-output 和 --force 跳过所有交互式提示:

# Specify output directory directly
repomix --skill-generate --skill-output ./my-skills

# Skip overwrite confirmation with --force
repomix --skill-generate --skill-output ./my-skills --force

# Full non-interactive example
repomix --remote user/repo --skill-generate my-skill --skill-output ./output --force
生成的结构

生成的 Skills 具有以下结构:

.claude/skills/<skill-name>/
├── SKILL.md                 # Main Skills metadata & documentation
└── references/
    ├── summary.md           # Purpose, format, and statistics
    ├── project-structure.md # Directory tree with line counts
    ├── files.md             # All file contents (grep-friendly)
    └── tech-stacks.md       # Languages, frameworks, dependencies
包含内容
  • SKILL.md:包含 Skills 元数据、文件/行数/令牌数统计、概述和使用说明
  • summary.md:说明 Skills 的用途和使用指南,并按文件类型和语言提供统计明细
  • project-structure.md:目录树中包含每个文件的行数,便于查找文件
  • files.md:包含所有文件内容,并带有语法高亮标题,便于使用 grep 搜索
  • tech-stacks.md:根据依赖文件(package.json、requirements.txt、Cargo.toml 等)自动检测每个包的技术栈
自动生成的 Skills 名称

如果未提供名称,Repomix 会自动生成一个:

repomix src/ --skill-generate                # → repomix-reference-src
repomix --remote user/repo --skill-generate  # → repomix-reference-repo
repomix --skill-generate CustomName          # → custom-name (normalized to kebab-case)
与 Repomix 功能集成

Skills 生成会遵循所有标准 Repomix 选项:

# Generate Skills with file filtering
repomix --skill-generate --include "src/**/*.ts" --ignore "**/*.test.ts"

# Generate Skills with compression
repomix --skill-generate --compress

# Generate Skills from remote repository
repomix --remote yamadashy/repomix --skill-generate
Repomix Explorer Skill(Agent Skills)

Repomix 提供开箱即用的 Repomix Explorer 技能,让 AI 编码助手能够使用 Repomix CLI 分析和探索代码库。该技能适用于多种 AI 工具,包括 Claude Code、Cursor、Codex、GitHub Copilot 等。

快速安装

对于 Claude Code,请安装官方 Repomix Explorer 插件:

/plugin marketplace add yamadashy/repomix
/plugin install repomix-explorer@repomix

对于 Codex、Cursor、OpenClaw 及其他兼容 Agent Skills 的助手,请使用 Skills CLI 安装独立技能:

npx skills add yamadashy/repomix --skill repomix-explorer

如需指定助手,请传入 --agent:

npx skills add yamadashy/repomix --skill repomix-explorer --agent codex
npx skills add yamadashy/repomix --skill repomix-explorer --agent openclaw

对于 Hermes Agent,请使用 Hermes Agent 原生的技能命令安装单文件技能:

hermes skills install https://raw.githubusercontent.com/yamadashy/repomix/main/skills/repomix-explorer/SKILL.md
功能

安装后,你可以通过自然语言指令分析代码库。

分析远程代码库:

"What's the structure of this repo?
https://github.com/facebook/react"

探索本地代码库:

"What's in this project?
~/projects/my-app"

这不仅有助于理解代码库,在你想参考其他代码库来实现功能时也很有用。

⚙️ 配置

Repomix 支持多种配置文件格式,灵活易用。

配置文件格式

Repomix 会按以下优先级顺序自动搜索配置文件:

  1. TypeScript(repomix.config.ts、repomix.config.mts、repomix.config.cts)
  2. JavaScript/ES 模块(repomix.config.js、repomix.config.mjs、repomix.config.cjs)
  3. JSON(repomix.config.json5、repomix.config.jsonc、repomix.config.json)
JSON 配置

在项目根目录创建 repomix.config.json 文件:

repomix --init

这将创建包含默认设置的 repomix.config.json 文件。

TypeScript 配置

TypeScript 配置文件可提供出色的开发体验,包括完整的类型检查和 IDE 支持。

安装:

如需使用 defineConfig 配置 TypeScript 或 JavaScript,必须将 Repomix 安装为开发依赖:

npm install -D repomix

示例:

// repomix.config.ts
import { defineConfig } from 'repomix';

export default defineConfig({
  output: {
    filePath: 'output.xml',
    style: 'xml',
    removeComments: true,
  },
  ignore: {
    customPatterns: ['**/node_modules/**', '**/dist/**'],
  },
});

优点:

  • ✅ 在 IDE 中进行完整的 TypeScript 类型检查
  • ✅ IDE 自动补全和 IntelliSense 表现出色
  • ✅ 使用动态值(时间戳、环境变量等)

动态值示例:

// repomix.config.ts
import { defineConfig } from 'repomix';

// Generate timestamp-based filename
const timestamp = new Date().toISOString().slice(0, 19).replace(/[:.]/g, '-');

export default defineConfig({
  output: {
    filePath: `output-${timestamp}.xml`,
    style: 'xml',
  },
});
JavaScript 配置

JavaScript 配置文件的工作方式与 TypeScript 相同,支持 defineConfig 和动态值。

配置选项

以下是配置选项的说明:

选项描述默认值
input.maxFileSize要处理的最大文件大小(字节)。大于此大小的文件将被跳过50000000
input.processors有序数组,包含 { pattern, command, timeout?, onError? } 条目,用于运行外部命令,在打包前转换匹配的文件(例如 JSON→TOON)。第一个匹配的 glob 优先。可运行任意命令,因此仅在本地 CLI 运行时(以及使用 --remote-trust-config 的远程仓库中)运行。参见文件处理器未设置
output.filePath输出文件的名称"repomix-output.xml"
output.style输出的格式(xml、markdown、json、plain)"xml"
output.filePathStyle输出中显示文件路径的方式(target-relative 会让路径相对于各目标根目录,cwd-relative 会让路径相对于当前工作目录)"target-relative"
output.parsableStyle是否根据所选格式的架构对输出进行转义。请注意,这可能会增加 token 数量。false
output.compress是否执行智能代码提取以减少 token 数量false
output.patterns各文件的包含级别。有序数组,包含 { pattern, compress?, directoryStructureOnly? } 条目;第一个匹配的 glob 优先,并覆盖该文件的全局 output.compress 设置。参见各文件的包含级别未设置
output.headerText要包含在文件头部的自定义文本null
output.instructionFilePath包含详细自定义指令的文件路径null
output.fileSummary是否在输出开头包含摘要部分true
output.directoryStructure是否在输出中包含目录结构true
output.files是否在输出中包含文件内容true
output.removeComments是否移除受支持文件类型中的注释false
output.removeEmptyLines是否移除输出中的空行false
output.showLineNumbers是否为输出中的每一行添加行号false
output.truncateBase64是否截断较长的 base64 数据字符串(例如图片)以减少 token 数量false
output.copyToClipboard除了保存文件外,是否将输出复制到系统剪贴板false
output.splitOutput按每个分片的最大大小将输出拆分为多个带编号的文件(例如,1000000 表示约 1 MB)。确保每个文件不超过限制,并避免将文件拆分到多个分片中未设置
output.topFilesLength在摘要中显示的顶级文件数量。如果设为 0,则不显示摘要5
output.tokenCountTree是否显示包含 token 数量摘要的文件树。可以是布尔值或数字(token 数量阈值)false
output.tokenBudget当打包后的输出超过此 token 数量时,以非零退出码失败。此设置可用于限制 CI/Agent 上下文;输出仍会生成未设置
output.includeEmptyDirectories是否在仓库结构中包含空目录false
output.includeFullDirectoryStructure使用 include 模式时,是否显示完整目录树(遵循忽略模式),同时仍只处理包含的文件。这会为 AI 分析提供完整的仓库上下文false
output.git.sortByChanges是否按 git 更改次数对文件排序(更改次数较多的文件排在底部)true
output.git.sortByChangesMaxCommits分析 git 更改时要检查的最大提交数100
output.git.includeDiffs是否在输出中包含 git 差异(分别包含工作树和暂存区中的更改)false
output.git.includeLogs是否在输出中包含 git 日志(包含带日期、消息和文件路径的提交历史记录)false
output.git.includeLogsCount要包含的 git 日志提交数量50
include要包含的文件模式(使用 glob 模式)[]
ignore.useGitignore是否使用项目 .gitignore 文件中的模式true
ignore.useDotIgnore是否使用项目 .ignore 文件中的模式true
ignore.useDefaultPatterns是否使用默认忽略模式true
ignore.customPatterns其他要忽略的模式(使用 glob 模式)[]
security.enableSecurityCheck是否对文件执行安全检查true
tokenCount.encoding与 OpenAI 兼容的分词所用的 token 计数编码(例如,GPT-4o 使用 o200k_base,GPT-4/3.5 使用 cl100k_base)。由 gpt-tokenizer 提供支持。"o200k_base"
配置文件支持 JSON5 语法,允许使用:
  • 注释(单行和多行)
  • 对象和数组中的尾随逗号
  • 不加引号的属性名称
  • 更宽松的字符串语法
架构验证

在配置文件中添加 $schema 属性,即可启用架构验证:

{
  "$schema": "https://repomix.com/schemas/latest/schema.json",
  "output": {
    "filePath": "repomix-output.xml",
    "style": "xml"
  }
}

这可以在支持 JSON 架构的编辑器中提供自动补全和验证。

配置示例

配置示例:

{
  "$schema": "https://repomix.com/schemas/latest/schema.json",
  "input": {
    "maxFileSize": 50000000,
    // Optional: transform matching files with an external command before packing (local CLI only)
    // "processors": [
    //   { "pattern": "**/*.json", "command": "npx @toon-format/cli {file}" }
    // ]
  },
  "output": {
    "filePath": "repomix-output.xml",
    "style": "xml",
    "filePathStyle": "target-relative",
    "parsableStyle": false,
    "compress": false,
    // Optional: override the inclusion level per glob (first match wins)
    // "patterns": [
    //   { "pattern": "docs/**/*", "compress": true },
    //   { "pattern": "website/**/*", "directoryStructureOnly": true }
    // ],
    "headerText": "Custom header information for the packed file.",
    "fileSummary": true,
    "directoryStructure": true,
    "files": true,
    "removeComments": false,
    "removeEmptyLines": false,
    "topFilesLength": 5,
    "tokenCountTree": false, // or true, or a number like 10 for minimum token threshold
    // "tokenBudget": 180000, // optional: fail when the packed output exceeds this many tokens
    "showLineNumbers": false,
    "truncateBase64": false,
    "copyToClipboard": false,
    // "splitOutput": 1000000, // optional: split output into multiple ~1MB files
    "includeEmptyDirectories": false,
    "git": {
      "sortByChanges": true,
      "sortByChangesMaxCommits": 100,
      "includeDiffs": false,
      "includeLogs": false,
      "includeLogsCount": 50
    }
  },
  "include": ["**/*"],
  "ignore": {
    "useGitignore": true,
    "useDefaultPatterns": true,
    // Patterns can also be specified in .repomixignore
    "customPatterns": [
      "additional-folder",
      "**/*.log"
    ],
  },
  "security": {
    "enableSecurityCheck": true
  },
  "tokenCount": {
    "encoding": "o200k_base"
  }
}
全局配置

创建全局配置文件:

repomix --init --global

全局配置文件将创建于:

  • Windows:%LOCALAPPDATA%\Repomix\repomix.config.json
  • macOS/Linux:$XDG_CONFIG_HOME/repomix/repomix.config.json 或 ~/.config/repomix/repomix.config.json

注意:本地配置(如果存在)的优先级高于全局配置。

包含和忽略
包含模式

Repomix 现在支持使用glob 模式指定要包含的文件。这让文件选择更加灵活且强大:

  • 使用 **/*.js 包含任意目录中的所有 JavaScript 文件
  • 使用 src/**/* 包含 src 目录及其子目录中的所有文件
  • 组合多个模式,例如 ["src/**/*.js", "**/*.md"],以包含 src 中的 JavaScript 文件和所有 Markdown 文件
忽略模式

Repomix 提供多种方法,可设置忽略模式,在打包过程中排除特定文件或目录:

  • .gitignore:默认情况下,会使用项目 .gitignore 文件和 .git/info/exclude 中列出的模式。可通过 ignore.useGitignore 设置或 --no-gitignore CLI 选项控制此行为。
  • .ignore:可在项目根目录中使用 .ignore 文件,格式与 .gitignore 相同。ripgrep 和 silver searcher 等工具会遵循此文件,从而减少维护多个忽略文件的需要。可通过 ignore.useDotIgnore 设置或 --no-dot-ignore CLI 选项控制此行为。
  • 默认模式:Repomix 包含一组默认排除的常见文件和目录(例如 node_modules、.git、二进制文件)。可通过 ignore.useDefaultPatterns 设置或 --no-default-patterns CLI 选项控制此功能。更多详情请参阅 defaultIgnore.ts。
  • .repomixignore:可在项目根目录中创建 .repomixignore 文件,以定义 Repomix 专用的忽略模式。此文件的格式与 .gitignore 相同。
  • 自定义模式:可在配置文件中使用 ignore.customPatterns 选项指定其他忽略模式。可使用 -i, --ignore 命令行选项覆盖此设置。

优先级顺序(从高到低):

  1. 自定义模式(ignore.customPatterns)
  2. 忽略文件(.repomixignore、.ignore、.gitignore 和 .git/info/exclude):
    • 在嵌套目录中,较深目录中的文件优先级更高
    • 在同一目录中,这些文件会以不特定的顺序合并
  3. 默认模式(如果 ignore.useDefaultPatterns 为 true 且未使用 --no-default-patterns)

此方法可根据项目需求灵活配置文件排除规则。它能确保排除涉及安全的敏感文件和大型二进制文件,从而优化生成的打包文件大小,同时防止机密信息泄露。

注意:默认情况下,二进制文件不会包含在打包输出中,但其路径会列在输出文件的“Repository Structure”部分。这既能完整展示仓库结构,又能让打包文件保持精简且基于文本。

自定义指令

output.instructionFilePath 选项允许你指定一个单独的文件,其中包含有关项目的详细指令或 上下文。这有助于 AI 系统了解项目的具体背景和要求,从而提供更相关、更贴合需求的分析或建议。

以下是此功能的使用示例:

  1. 在项目根目录中创建一个名为 repomix-instruction.md 的文件:
# Coding Guidelines

- Follow the Airbnb JavaScript Style Guide
- Suggest splitting files into smaller, focused units when appropriate
- Add comments for non-obvious logic. Keep all text in English
- All new features should have corresponding unit tests

# Generate Comprehensive Output

- Include all content without abbreviation, unless specified otherwise
- Optimize for handling large codebases while maintaining output quality
  1. 在 repomix.config.json 中添加 instructionFilePath 选项:
{
  "output": {
    "instructionFilePath": "repomix-instruction.md",
    // other options...
  }
}

Repomix 生成输出时,会在专门的部分中包含 repomix-instruction.md 的内容。

注意:指令内容会附加到输出文件的末尾。对于 AI 系统来说,这种位置安排可能尤其有效。 如果你想了解这样做可能有益的原因,Anthropic 在其文档中提供了一些见解:
https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/long-context-tips

将长篇数据放在顶部:将长文档和输入(约 20K+ 个 token)放在提示词靠前的位置,位于查询、 指令和示例之前。这可以显著提升 Claude 在所有模型上的性能。 在测试中,将查询放在末尾最多可将响应质量提升 30%,尤其适用于复杂的多文档输入。

移除注释

当 output.removeComments 设置为 true 时,Repomix 会尝试从支持的文件类型中移除注释。此 功能有助于减小输出文件的大小,并聚焦于核心代码内容。

支持的语言包括:
HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell 和 YAML。

注意:为避免意外移除代码,注释移除过程较为保守。在复杂情况下,可能会保留部分注释。

文件处理器

input.processors 会运行外部命令,在文件内容打包前对其进行转换。每个条目通过 glob 匹配文件(匹配方式与 include/ignore 相同),并将匹配文件的内容替换为命令的标准输出——适用于减少 token 或转换格式,例如 JSON→TOON、SVG 压缩或将笔记本转换为脚本。

{
  "input": {
    "processors": [
      { "pattern": "**/*.json", "command": "npx @toon-format/cli {file}" }
    ]
  }
}

必填的 {file} 占位符会替换为一个临时文件,该文件保存了原文件的内容;命令的标准输出则会成为新内容。模式按顺序求值,第一个匹配项生效(每个文件只应用一个处理器)。每个条目还接受 timeout(毫秒,默认值为 60000)和 onError("fail" 表示中止打包,且为默认值;"skip" 表示发出警告并保留原始内容)。

命令示例(每条命令都与适用的 pattern 配对):

模式command功能
**/*.jsonjq -c . {file}移除空白字符,压缩 JSON
**/*.jsonnpx @toon-format/cli {file}将 JSON 转换为 TOON,这是一种紧凑且节省 token 的格式
**/*.svgnpx svgo -i {file} -o -压缩 SVG
**/*.ipynbjupyter nbconvert --to script --stdout {file}将 Jupyter 笔记本转换为纯 Python 脚本

每个文件只应用一个处理器(第一个匹配项生效),并确保调用的工具位于你的 PATH 中(基于 npx 的命令会在首次使用时下载工具)。

警告

文件处理器会运行配置文件中的任意命令,因此默认拒绝执行:

  • 仅在本地 CLI 运行时启用,此时 Repomix 假定工作目录中的配置由你本人编写——与 npm 脚本或 Makefile 的信任边界相同。与运行这些脚本一样,如果你在获取自他人的仓库中运行 repomix,却没有先检查其 repomix.config.json,其中的处理器命令就会在你的计算机上执行。打包不可信仓库前,请先检查其配置。
  • 库 API(pack() / runCli())、MCP 服务和托管版 repomix.com 均禁用此功能。
  • 对于远程仓库(--remote),只有在显式传入 --remote-trust-config 时,才会信任克隆下来的配置及其处理器;否则甚至不会加载远程配置。

启动时和错误消息中会打印已启用的处理器,因此请通过环境变量引用凭据(例如 $TOKEN),这些变量会以未展开的形式记录,而不要将凭据直接写入命令。超时后,Repomix 会终止命令的 shell,但自行启动了长期运行的后台进程的命令可能会使这些进程继续运行。详情请参阅配置指南。

🔍 安全检查

Repomix 提供安全检查功能,使用 Secretlint 检测文件中 可能敏感的信息。此功能可帮助你在分享打包后的仓库之前,发现潜在的安全风险。

打包完成后,安全检查结果会显示在 CLI 输出中。如果检测到可疑 文件,你会看到这些文件的列表以及一条警告消息。

输出示例:

🔍 Security Check:
──────────────────
2 suspicious file(s) detected:
1. src/utils/test.txt
2. tests/utils/secretLintUtils.test.ts

Please review these files for potentially sensitive information.

默认情况下,Repomix 的安全检查功能处于启用状态。你可以在配置文件中将 security.enableSecurityCheck 设为 false 来禁用此功能:

{
  "security": {
    "enableSecurityCheck": false
  }
}

或者使用 --no-security-check 命令行选项:

repomix --no-security-check

说明

禁用安全检查可能会暴露敏感信息。请谨慎使用此选项,仅在必要时启用, 例如处理包含示例凭据的测试文件或文档时。

远程仓库配置的信任

repomix.config.* 是代码,而不只是数据:加载 .ts / .js 配置时会执行它,input.processors 会运行外部命令,路径选项也可能读取仓库外的文件。从不熟悉的仓库加载配置,就如同运行它的 Makefile。

因此,默认情况下绝不会加载克隆仓库中的配置。你的全局配置和 CLI 选项仍会生效。

在交互式终端中选择使用 --remote-trust-config(或 REPOMIX_REMOTE_TRUST_CONFIG=true)后,Repomix 会显示即将运行的配置,并在加载前征求你的同意:

  • 是,仅本次 — 仅信任本次运行。
  • 是,以后不再询问此仓库 — 此决定会绑定到内容:系统会记录你批准的配置哈希,因此如果该仓库之后提供了不同的配置,就会再次询问你(类似 direnv allow 模式)。
  • 否(默认选项)— 中止,不加载配置。

显示的配置由仓库作者编写,因此控制字符、ANSI 字符和双向文本字符都会经过转义,输出有长度限制,每行配置都会添加前缀,并且会拒绝指向克隆目录外部的符号链接配置——你审阅的内容就是实际运行的内容。

使用 --force、在 CI 等非交互式 Shell 中,以及你选择始终信任该仓库后,系统都会跳过提示。

重要

内容固定仅涵盖入口配置文件。.ts / .js 配置可以 import 其他文件,而 input.processors 可以调用外部脚本;这两者都不会进行哈希处理。请将“以后不再询问”视为对仓库的信任,而不只是对你查看的文件的信任。

请参阅安全指南,了解完整的信任模型。

🤖 在 GitHub Actions 中使用 Repomix

你也可以在 GitHub Actions 工作流中使用 Repomix。这有助于自动打包代码库,以供 AI 分析。

基本用法:

- name: Pack repository with Repomix
  uses: yamadashy/repomix/.github/actions/repomix@main
  with:
    output: repomix-output.xml
    style: xml

使用 --style 生成不同格式的输出:

- name: Pack repository with Repomix
  uses: yamadashy/repomix/.github/actions/repomix@main
  with:
    output: repomix-output.md
    style: markdown
- name: Pack repository with Repomix (JSON format)
  uses: yamadashy/repomix/.github/actions/repomix@main
  with:
    output: repomix-output.json
    style: json

压缩并打包指定目录:

- name: Pack repository with Repomix
  uses: yamadashy/repomix/.github/actions/repomix@main
  with:
    directories: src tests
    include: "**/*.ts,**/*.md"
    ignore: "**/*.test.ts"
    output: repomix-output.txt
    compress: true

将输出文件作为构件上传:

- name: Pack repository with Repomix
  uses: yamadashy/repomix/.github/actions/repomix@main
  with:
    directories: src
    output: repomix-output.txt
    compress: true

- name: Upload Repomix output
  uses: actions/upload-artifact@v7
  with:
    name: repomix-output
    path: repomix-output.txt

完整的工作流示例:

name: Pack repository with Repomix

on:
  workflow_dispatch:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  pack-repo:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v7

      - name: Pack repository with Repomix
        uses: yamadashy/repomix/.github/actions/repomix@main
        with:
          output: repomix-output.xml

      - name: Upload Repomix output
        uses: actions/upload-artifact@v7
        with:
          name: repomix-output.xml
          path: repomix-output.xml
          retention-days: 30

请参阅此处的完整工作流示例。

Action 输入
名称描述默认值
directories要处理的目录列表,以空格分隔(例如,src tests docs).
include要包含的文件 glob 模式,以逗号分隔(例如,**/*.ts,**/*.md)""
ignore要忽略的文件 glob 模式,以逗号分隔(例如,**/*.test.ts,**/node_modules/**)""
output打包文件的相对路径(扩展名决定格式:.txt、.md、.xml)repomix-output.xml
compress启用智能压缩,通过删减实现细节来减小输出体积true
style输出样式(xml、markdown、json、plain)xml
additional-args传递给 repomix CLI 的额外原始参数(例如,--no-file-summary --no-security-check)""
repomix-version要安装的 npm 包版本(支持 semver 范围、标签或特定版本,如 0.2.25)latest
Action 输出
名称描述
output_file生成的输出文件路径。可在后续步骤中用于上传构件、处理 LLM 或执行其他操作。该文件包含根据指定选项生成的格式化代码库表示。

📚 将 Repomix 用作库

除了将 Repomix 用作 CLI 工具,你也可以在 Node.js 应用中将其用作库。

安装
npm install repomix
基本用法
import { runCli, type CliOptions } from 'repomix';

// Process current directory with custom options
async function packProject() {
  const options = {
    output: 'output.xml',
    style: 'xml',
    compress: true,
    quiet: true
  } as CliOptions;
  
  const result = await runCli(['.'], process.cwd(), options);
  return result.packResult;
}
处理远程仓库
import { runCli, type CliOptions } from 'repomix';

// Clone and process a GitHub repo
async function processRemoteRepo(repoUrl) {
  const options = {
    remote: repoUrl,
    output: 'output.xml',
    compress: true
  } as CliOptions;
  
  return await runCli(['.'], process.cwd(), options);
}
使用核心组件

如果需要更多控制权,可以使用低级 API:

import { searchFiles, collectFiles, processFiles, TokenCounter } from 'repomix';

async function analyzeFiles(directory) {
  // Find and collect files
  const { filePaths } = await searchFiles(directory, { /* config */ });
  const rawFiles = await collectFiles(filePaths, directory);
  const processedFiles = await processFiles(rawFiles, { /* config */ });
  
  // Count tokens
  const tokenCounter = new TokenCounter('o200k_base');
  
  // Return analysis results
  return processedFiles.map(file => ({
    path: file.path,
    tokens: tokenCounter.countTokens(file.content)
  }));
}

更多示例,请查看源代码 website/server/src/remoteRepo.ts,其中演示了 repomix.com 如何使用此库。

打包

使用 Rolldown 或 esbuild 等工具打包 repomix 时,某些依赖项必须保持外部依赖,并且需要复制 WASM 文件:

外部依赖(无法打包):

  • tinypool - 使用文件路径启动工作线程

需要复制的 WASM 文件:

  • web-tree-sitter.wasm → 与打包后的 JS 位于同一目录(代码压缩功能所必需)
  • Tree-sitter 语言文件 → 由 REPOMIX_WASM_DIR 环境变量指定的目录

如需查看可运行示例,请参阅 website/server/scripts/bundle.mjs。

🌍 社区项目

探索 Repomix 社区打造的精彩项目!

  • Repomix Runner - VSCode 扩展,可将文件打包为单个输出,供 AI 处理
  • Repomix Desktop - 使用 Python 和 CustomTkinter 为 Repomix 构建的 GUI 桌面应用
  • Python Repomix - 基于 AST 压缩的 Python 实现
  • Rulefy - 使用 Claude AI 将 GitHub 仓库转换为自定义 Cursor AI 规则
  • Codebase MCP - 使用 Repomix 进行 AI 驱动代码库分析的 MCP 服务
  • vibe-tools - 面向 AI Agent 的命令行工具集,提供网页搜索、仓库分析和浏览器自动化功能

更多详情,请访问我们的社区项目页面。

🤝 贡献

我们欢迎社区贡献!如需开始,请参阅我们的贡献指南。

贡献者
贡献者

🔒 隐私政策

请参阅我们的隐私政策。

📜 许可证

本项目采用 MIT License 许可。

    返回顶部

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。