仓库混合器
Repomix MCP服务器通过将本地或远程存储库打包成优化的单个文件,使AI模型能够高效地分析代码库。通过Tree-sitter进行智能压缩,可以在保留代码结构和关键签名的同时,显著减少令牌使用量。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"repomix": {
"args": [
"-y",
"repomix",
"--mcp"
],
"command": "npx"
}
}
}
服务介绍
ð¦ Repomix 是一个强大的工具,可以将整个代码仓库打包成一个单一的、对AI友好的文件。
当您需要将代码库提供给大型语言模型(LLMs)或其他AI工具如Claude, ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok等时,它非常适用。
ð 新闻:Repomix 网站和 Discord 社区!
- 在 repomix.com 上通过浏览器试用 Repomix
- 加入我们的 Discord 服务器 获取支持和讨论
我们期待在那里见到您!
ð 特性
- AI优化:以AI易于理解和处理的方式格式化您的代码库。
- 令牌计数:为每个文件和整个仓库提供令牌计数,对于LLM上下文限制非常有用。
- 简单易用:只需一条命令即可打包整个仓库。
- 可定制:轻松配置包含或排除的内容。
- Git感知:自动尊重您的
.gitignore文件和.git/info/exclude。 - 注重安全:集成Secretlint进行强有力的安全检查,以检测并防止敏感信息被包含。
- 代码压缩:
--compress选项使用Tree-sitter提取关键代码元素,在保持结构的同时减少令牌数量。
ð 快速开始
使用CLI工具 >_
您可以在项目目录中即时尝试Repomix,无需安装:
npx repomix
或者全局安装以便重复使用:
# Install using npm
npm install -g repomix
# Alternatively using yarn
yarn global add 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.

当你提出具体的更改建议时,AI 可能能够据此生成代码。借助类似 Claude 的 Artifacts 功能,你甚至可以输出多个文件,从而生成多个相互依赖的代码片段。

愉快地编码吧!ð
使用网站 ð
想快速试用吗?请访问官方网站 repomix.com。只需输入你的仓库名称,填写任何可选细节,然后点击 Pack 按钮即可查看生成的输出。
可用选项
该网站提供了几个方便的功能:
- 可自定义的输出格式(XML、Markdown 或纯文本)
- 即时令牌计数估计
- 还有很多!
使用 VSCode 扩展程序 â¡ï¸
一个由社区维护的 VSCode 扩展程序让你只需点击几下就可以在编辑器内运行 Repomix。可以在任意文件夹上运行它,无缝管理输出,并通过 VSCode 直观的界面控制一切。
想要将输出保存为文件还是只获取内容?需要自动清理吗?这个扩展程序都能满足你。此外,它还能与现有的 repomix.config.json 无缝协作。
现在就去 VSCode 市场试试看吧!
源代码可在 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
要压缩输出:
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>
对于对AI环境中XML标签潜力感兴趣的用户:
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系统解析。
纯文本格式
要生成纯文本格式的输出,请使用--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: 显示工具版本
输出选项
-o, --output <file>: 指定输出文件名--style <style>: 指定输出样式 (xml,markdown,plain)--parsable-style: 根据所选样式模式启用可解析的输出。请注意,这可能会增加 token 数量。--compress: 执行智能代码提取,专注于基本的函数和类签名以减少 token 数量--output-show-line-numbers: 在输出中显示行号--copy: 除了生成输出外,还将内容复制到系统剪贴板--no-file-summary: 禁用文件摘要部分的输出--no-directory-structure: 禁用目录结构部分的输出--remove-comments: 从支持的文件类型中移除注释--remove-empty-lines: 从输出中移除空行--header-text <text>: 自定义文本包含在文件头中--instruction-file-path <path>: 包含详细自定义指令的文件路径--include-empty-directories: 在输出中包含空目录--no-git-sort-by-changes: 禁用按 git 变更次数排序文件(默认启用)
过滤选项
--include <patterns>: 包含模式列表(逗号分隔)-i, --ignore <patterns>: 额外忽略模式(逗号分隔)--no-gitignore: 禁用 .gitignore 文件使用--no-default-patterns: 禁用默认模式
远程仓库选项
--remote <url>: 处理远程 Git 仓库--remote-branch <name>: 指定远程分支名称、标签或提交哈希(默认为仓库的默认分支)
配置选项
-c, --config <path>: 自定义配置文件路径--init: 创建配置文件--global: 使用全局配置
安全选项
--no-security-check: 禁用安全检查
Token 计数选项
--token-count-encoding <encoding>: 指定 token 计数编码(例如,o200k_base,cl100k_base)
MCP
--mcp: 作为 MCP (Model Context Protocol) 服务器运行
其他选项
--top-files-len <number>: 在摘要中显示的顶级文件数量--verbose: 启用详细日志记录--quiet: 禁用所有标准输出
示例:
repomix -o custom-output.txt
repomix -i "*.log,tmp" -v
repomix -c ./custom-config.json
repomix --style xml
repomix --remote https://github.com/user/repo
npx repomix src
更新 Repomix
要更新全局安装的 Repomix:
# Using npm
npm update -g repomix
# Using yarn
yarn global upgrade 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
代码压缩
--compress 选项利用 Tree-sitter 进行智能代码提取,专注于重要的函数和类签名,同时移除实现细节。这有助于减少令牌数量,同时保留重要的结构信息。
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;
}
[!NOTE]
这是一个实验性功能,我们将根据用户反馈和实际使用情况积极改进
MCP 集成
Repomix 支持 Model Context Protocol (MCP),允许 AI 助手直接与您的代码库交互。当作为 MCP 服务器运行时,Repomix 提供工具,使 AI 助手能够打包本地或远程仓库进行分析,而无需手动准备文件。
repomix --mcp
可用的 MCP 工具
当作为 MCP 服务器运行时,Repomix 提供以下工具:
- pack_codebase: 将本地代码目录打包成一个整合文件,用于 AI 分析
- 参数:
directory: 要打包的目录的绝对路径compress: (可选,默认: true)是否执行智能代码提取includePatterns: (可选)包含模式的逗号分隔列表ignorePatterns: (可选)忽略模式的逗号分隔列表
- pack_remote_repository: 获取、克隆并打包一个 GitHub 仓库
- 参数:
remote: GitHub 仓库 URL 或 user/repo 格式(例如:yamadashy/repomix)compress: (可选,默认: true)是否执行智能代码提取includePatterns: (可选)包含模式的逗号分隔列表ignorePatterns: (可选)忽略模式的逗号分隔列表
- read_repomix_output: 在无法直接访问文件的环境中读取 Repomix 输出文件的内容
- 参数:
outputId: 要读取的 Repomix 输出文件的 ID
- 特性:
- 特别设计用于基于 Web 的环境或沙盒应用程序
- 使用其 ID 检索之前生成输出的内容
- 在不需要文件系统访问的情况下提供对打包代码库的安全访问
- file_system_read_file: 使用绝对路径并带有安全验证来读取文件
- 参数:
path: 要读取的文件的绝对路径
- 安全特性:
- 使用 Secretlint 实现安全验证
- 防止访问包含敏感信息的文件
- 验证绝对路径以防止目录遍历攻击
- file_system_read_directory: 使用绝对路径列出目录内容
- 参数:
path: 要列出的目录的绝对路径
- 特性:
- 显示带有清晰指示符(
[FILE]或[DIR])的文件和目录 - 提供带有适当错误处理的安全目录遍历
- 验证路径并确保它们是绝对路径
- 显示带有清晰指示符(
配置 MCP 服务器
要将 Repomix 用作 Claude 等 AI 助手的 MCP 服务器,您需要配置 MCP 设置:
对于 Cline(VS Code 扩展):
编辑 cline_mcp_settings.json 文件:
{
"mcpServers": {
"repomix": {
"command": "npx",
"args": [
"-y",
"repomix",
"--mcp"
]
}
}
}
对于 Claude 桌面版:
使用与 Cline 的配置类似的设置编辑 claude_desktop_config.json 文件。
配置完成后,您的 AI 助手可以直接使用 Repomix 的功能来分析代码库,而无需手动准备文件,从而使代码分析工作流程更加高效。
âï¸ 配置
在项目根目录中创建一个 repomix.config.json 文件以进行自定义配置。
repomix --init
以下是配置选项的说明:
| Option | Description | Default |
|---|---|---|
output.filePath |
The name of the output file | "repomix-output.xml" |
output.style |
The style of the output (xml, markdown, plain) |
"xml" |
output.parsableStyle |
Whether to escape the output based on the chosen style schema. Note that this can increase token count. | false |
output.compress |
Whether to perform intelligent code extraction to reduce token count | false |
output.headerText |
Custom text to include in the file header | null |
output.instructionFilePath |
Path to a file containing detailed custom instructions | null |
output.fileSummary |
Whether to include a summary section at the beginning of the output | true |
output.directoryStructure |
Whether to include the directory structure in the output | true |
output.removeComments |
Whether to remove comments from supported file types | false |
output.removeEmptyLines |
Whether to remove empty lines from the output | false |
output.showLineNumbers |
Whether to add line numbers to each line in the output | false |
output.copyToClipboard |
Whether to copy the output to system clipboard in addition to saving the file | false |
output.topFilesLength |
Number of top files to display in the summary. If set to 0, no summary will be displayed | 5 |
output.includeEmptyDirectories |
Whether to include empty directories in the repository structure | false |
output.git.sortByChanges |
Whether to sort files by git change count (files with more changes appear at the bottom) | true |
output.git.sortByChangesMaxCommits |
Maximum number of commits to analyze for git changes | 100 |
include |
Patterns of files to include (using glob patterns) | [] |
ignore.useGitignore |
Whether to use patterns from the project's .gitignore file |
true |
ignore.useDefaultPatterns |
Whether to use default ignore patterns | true |
ignore.customPatterns |
Additional patterns to ignore (using glob patterns) | [] |
security.enableSecurityCheck |
Whether to perform security checks on files | true |
tokenCount.encoding |
Token count encoding for AI model context limits (e.g., o200k_base, cl100k_base) |
"o200k_base" |
配置文件支持 JSON5 语法,这允许:
- 注释(单行和多行)
- 对象和数组中的尾随逗号
- 未加引号的属性名
- 更宽松的字符串语法
示例配置:
{
"output": {
"filePath": "repomix-output.xml",
"style": "xml",
"parsableStyle": true,
"compress": false,
"headerText": "Custom header information for the packed file.",
"fileSummary": true,
"directoryStructure": true,
"removeComments": false,
"removeEmptyLines": false,
"showLineNumbers": false,
"copyToClipboard": true,
"topFilesLength": 5,
"includeEmptyDirectories": false,
"git": {
"sortByChanges": true,
"sortByChangesMaxCommits": 100
}
},
"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命令行选项来控制。 - 默认模式:Repomix 包含了一个常见的排除文件和目录的默认列表(例如,node_modules, .git, 二进制文件)。此功能可以通过
ignore.useDefaultPatterns设置或--no-default-patterns命令行选项来控制。详情请参阅 defaultIgnore.ts。 - .repomixignore:您可以在项目根目录下创建一个
.repomixignore文件来定义 Repomix 特定的忽略模式。该文件遵循与.gitignore相同的格式。 - 自定义模式:可以使用配置文件中的
ignore.customPatterns选项指定额外的忽略模式。您可以使用-i, --ignore命令行选项覆盖此设置。
优先级顺序(从高到低):
- 自定义模式
ignore.customPatterns .repomixignore.gitignore和.git/info/exclude(如果ignore.useGitignore为真且未使用--no-gitignore)- 默认模式(如果
ignore.useDefaultPatterns为真且未使用--no-default-patterns)
这种方法根据项目的需要提供了灵活的文件排除配置。它有助于通过确保排除安全敏感文件和大型二进制文件来优化生成的打包文件的大小,同时防止机密信息泄露。
注意:二进制文件默认不会被打包到输出文件中,但它们的路径会列在输出文件的“仓库结构”部分。这提供了一个完整的仓库结构概览,同时保持打包文件高效且基于文本。
自定义指令
output.instructionFilePath 选项允许你指定一个单独的文件,该文件包含有关项目的详细说明或上下文。这使得AI系统能够理解项目的特定上下文和要求,从而可能产生更相关和定制化的分析或建议。
以下是如何使用此功能的一个示例:
- 在项目根目录下创建一个名为
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
- 在你的
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+个标记)放置于提示词的顶部,位于查询、指令和示例之上。这可以显著提高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。
注意:注释移除过程是保守的,以避免意外删除代码。在复杂情况下,某些注释可能会被保留。
🛡️ 安全检查
Repomix 包含一个安全检查特性,该特性使用 Secretlint 来检测您文件中的潜在敏感信息。这个功能帮助你在共享打包后的仓库前识别出可能的安全风险。
安全检查的结果将在打包过程完成后显示在CLI输出中。如果检测到任何可疑文件,你会看到这些文件的列表以及一条警告消息。
示例输出:
ð Security Check:
ââââââââââââââââââ
2 suspicious file(s) det