Special thanks to:
Warp,专为使用多个AI代理进行编码而构建
Pack your codebase into AI-friendly formats
Use Repomix online! 👉 repomix.com
Need discussion? Join us on Discord!
Share your experience and tips
Stay updated on new features
Get help with configuration and usage
📦 Repomix是一个强大的工具,可以将整个存储库打包成一个对AI友好的文件。
当你需要将代码库提供给大型语言模型(LLM)或其他人工智能工具(如Claude)时,它是完美的, ChatGPT、DeepSeek、困惑、双子座、Gemma、Llama、Grok等。
请考虑赞助我。
🏆 开源奖提名
我们很荣幸!Repomix已被提名为 由AI驱动 类别在 2025年JSNation开源奖.
如果没有你们所有人使用和支持Repomix,这是不可能的。非常感谢。
🎉 新增:Repomix网站和Discord社区!
- 在浏览器中尝试Repomix repomix.com
- 加入我们 Discord服务器 寻求支持和讨论
我们期待在那里见到你!
🌟 特性
- AI优化:以易于人工智能理解和处理的方式格式化代码库。
- 令牌计数:为每个文件和整个存储库提供令牌计数,这对LLM上下文限制很有用。
- 简单易用:只需一个命令即可打包整个存储库。
- 可定制的:轻松配置要包含或排除的内容。
- Git感知:自动尊重您的
.gitignore,.ignore,以及.repomixignore文件夹。 - 注重安全:合并 分泌 用于强大的安全检查,以检测和防止包含敏感信息。
- 代码压缩:The
--compress选项使用 树保姆 提取关键代码元素,在保留结构的同时减少令牌计数。
🚀 快速开始
使用CLI工具 >_
您可以在项目目录中立即尝试Repomix,而无需安装:
BASH``` 1npx repomix@latest
或者全局安装以供重复使用:
BASH```
1
2
3
4
5
6
7
8
9
10# 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助手,并显示如下提示:
1
2This file contains all the files in the repository combined into one.
I want to refactor the code, so please review it first.
当你提出具体的更改时,人工智能可能会相应地生成代码。具有像Claude这样的功能 工件,您可能会输出多个文件,从而生成多个相互依存的工件 代码。
编码愉快! 🚀
使用网站🌐
想快速尝试一下吗?请访问官方网站 repomix.com。只需输入您的存储库 name,填写任何可选的详细信息,然后单击 包装 按钮查看生成的输出。
可用选项
该网站提供了几个方便的功能:
- 可定制的输出格式(XML、Markdown或纯文本)
- 即时令牌计数估计
- 更多!
使用浏览器扩展🧩
直接从任何GitHub存储库即时访问Repomix!我们的Chrome扩展程序在GitHub存储库页面上添加了一个方便的“Repomix”按钮。
安装
- Chrome扩展程序: Repomix-Chrome网上商店
- Firefox附加组件: Repomix-Firefox附加组件
特性
- 一键访问任何GitHub存储库的Repomix
- 更多精彩功能即将推出!
使用VSCode扩展⚡️
一个由社区维护的VSCode扩展名为 Repomix跑步者 (由创建 massdo)只需点击几下,您就可以在编辑器中运行Repomix。在任何文件夹上运行它,无缝管理输出,并通过VSCode的直观界面控制一切。
想要输出文件还是内容?需要自动清理吗?此扩展已覆盖您。此外,它与您现有的repomix.config.json兼容。
替代工具🛠️
如果你正在使用Python,你可能想看看 Gitingest,更适合Python生态系统和数据
科学工作流程:
https://github.com/cyclotruc/gitingest
📊 用法
要打包整个存储库,请执行以下操作:
BASH``` 1repomix
要打包特定目录,请执行以下操作:
BASH```
1repomix path/to/directory
打包特定文件或目录 使用 球状图案:
BASH``` 1repomix —include “src//*.ts,/*.md”
要排除特定文件或目录,请执行以下操作:
BASH```
1repomix --ignore "**/*.log,tmp/"
要打包远程存储库,请执行以下操作:
BASH``` 1 2 3 4 5 6 7 8 9 10 11repomix —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管道):
BASH```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22# 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日志:
BASH``` 1 2 3 4 5 6# 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分析提供了有价值的上下文。
要压缩输出,请执行以下操作:
BASH```
1
2
3repomix --compress
# You can also use it with remote repositories:
repomix --remote yamadashy/repomix --compress
初始化新的配置文件(repomix.config.json):
BASH``` 1repomix —init
生成打包文件后,您可以将其与ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok等生成型AI工具一起使用。
### Docker使用🐳
您还可以使用Docker运行Repomix。
如果您想在隔离环境中运行Repomix或更喜欢使用容器,这很有用。
基本用法(当前目录):
BASH```
1docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix
要打包特定目录,请执行以下操作:
BASH``` 1docker run -v .:/app -it —rm ghcr.io/yamadashy/repomix path/to/directory
处理远程存储库并输出到 `output` 目录:
BASH```
1docker 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工具一起使用。 以下是一些示例提示,以帮助您开始:
代码审查和重构
有关全面的代码审查和重构建议:
1This file contains my entire codebase. Please review the overall structure and suggest any improvements or refactoring opportunities, focusing on maintainability and scalability.
文档生成
要生成项目文档,请执行以下操作:
1Based 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.
测试用例生成
生成测试用例:
1Analyze 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.
代码质量评估
评估代码质量和对最佳实践的遵守情况:
1Review 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.
图书馆概况
深入了解图书馆
1This 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在代码库的不同部分之间生成一个具有清晰分隔符的单个文件。
为了增强对人工智能的理解,输出文件以面向人工智能的解释开头,使人工智能模型更容易 了解打包存储库的上下文和结构。
XML格式(默认)
XML格式以层次结构的方式构建内容:
XML```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20This 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>
output.instructionFilePath)
对于那些对XML标签在人工智能环境中的潜力感兴趣的人:
[https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags)
> 当您的提示涉及上下文、指令和示例等多个组件时,XML标记可以是
> 游戏规则改变者。它们帮助Claude更准确地解析您的提示,从而获得更高质量的输出。
这意味着Repomix的XML输出不仅是一种不同的格式,而且可能是一种更有效的馈送方式
将您的代码库导入AI系统进行分析、代码审查或其他任务。
#### Markdown格式
要生成Markdown格式的输出,请使用 `--style markdown` 选项:
BASH```
1repomix --style markdown
Markdown格式以层次结构的方式构建内容:
MARKDOWN``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19This 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)
这种格式提供了一种干净、可读的结构,既对人类友好,又易于人工智能系统解析。
#### JSON格式
要生成JSON格式的输出,请使用 `--style json` 选项:
BASH```
1repomix --style json
JSON格式将内容构造为具有camelCase属性名的分层JSON对象:
JSON``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16{ “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集成**:网络服务和应用程序的直接消费
- **AI工具兼容性**:机器学习和人工智能系统的结构化格式
- **数据分析**:使用以下工具直接提取特定信息 `jq`
##### 使用JSON输出 `jq`
JSON格式使得以编程方式提取特定信息变得容易:
BASH```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20# 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 选项:
BASH``` 1repomix —style plain
TEXT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31This 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,使用 "-" 对于stdout) |
--style <style> | 输出格式: xml, markdown, json,或 plain (默认值: xml) |
--parsable-style | 转义特殊字符以确保有效的XML/DMarkdown(当输出包含破坏格式的代码时需要) |
--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 diff部分,显示工作树和阶段性更改 |
--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,构建dirs等) |
远程存储库选项
| 选项 | 描述 |
|---|---|
--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-count-encoding <encoding>:计数令牌化器模型:o200k_base(GPT-4o)、cl100k_base(GPT-3.5/4)等。(默认值:o200k_base)
主控程序
--mcp:作为模型上下文协议服务器运行,用于AI工具集成
代理技能生成
| 选项 | 描述 |
|---|---|
--skill-generate [name] | 生成克劳德代理技能格式输出到 .claude/skills/<name>/ 目录(如果省略,则自动生成名称) |
--skill-output <path> | 直接指定技能输出目录路径(跳过位置提示) |
-f, --force | 跳过所有确认提示(例如,技能目录覆盖) |
例子
BASH``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20# 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
### 更新Repomix
要更新全局安装的Repomix,请执行以下操作:
BASH```
1
2
3
4
5
6# 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:
BASH``` 1repomix —remote https://github.com/yamadashy/repomix
你也可以使用GitHub的简写格式:
BASH```
1repomix --remote yamadashy/repomix
您可以指定分支名称、标记或提交哈希:
BASH``` 1 2 3 4# 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
或者使用特定的提交哈希:
BASH```
1
2
3
4# 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.当使用
--config随着--remote需要绝对路径(例如。,--config /home/user/repomix.config.json).
代码压缩
这 --compress 期权利用 树保姆 执行智能代码提取,重点关注基本函数和类签名,同时删除实现细节。这有助于减少令牌数量,同时保留重要的结构信息。
BASH``` 1repomix —compress
例如,这段代码:
TYPESCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19import { 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;
}
将被压缩为:
TYPESCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15import { 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; }
> [!注意]
> 这是一个实验性功能,我们将根据用户反馈和实际使用情况积极改进
### 令牌计数优化
了解代码库的令牌分布对于优化AI交互至关重要。使用 `--token-count-tree` 可视化整个项目中令牌使用情况的选项:
BASH```
1repomix --token-count-tree
这将显示带有令牌计数的代码库的层次视图:
1
2
3
4
5
6
7
8
9🔢 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)
您还可以设置一个最小令牌阈值,以专注于较大的文件:
BASH``` 1repomix —token-count-tree 1000 # Only show files/directories with 1000+ tokens
这有助于您:
- **识别令牌密集型文件** 这可能会超出AI上下文限制
- **优化文件选择** 使用 `--include` 和 `--ignore` 模式
- **规划压缩策略** 针对最大的贡献者
- **平衡内容与上下文** 为AI分析准备代码时
### 拆分大型代码库的输出
当处理大型代码库时,打包输出可能会超过某些AI工具规定的文件大小限制(例如,Google AI Studio的1MB限制)。使用 `--split-output` 自动将输出拆分为多个文件:
BASH```
1repomix --split-output 1mb
这将生成编号文件,如:
repomix-output.1.xmlrepomix-output.2.xmlrepomix-output.3.xml
尺寸可以用单位指定: 500kb, 1mb, 2mb, 1.5mb等等。支持十进制值。
[!注意] 文件按顶级目录分组以保持上下文。单个文件或目录永远不会跨多个输出文件拆分。
MCP服务器集成
Repomix支持 模型上下文协议(MCP),允许AI助手直接与您的代码库交互。当作为MCP服务器运行时,Repomix提供的工具使AI助手能够打包本地或远程存储库进行分析,而无需手动准备文件。
BASH``` 1repomix —mcp
#### 配置MCP服务器
要将Repomix用作带有Claude等AI助手的MCP服务器,您需要配置MCP设置:
**对于VS代码:**
您可以使用以下方法之一在VS Code中安装Repomix MCP服务器:
1. **使用安装徽章:**
[](https://insiders.vscode.dev/redirect/mcp/install?name=repomix&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22repomix%22%2C%22--mcp%22%5D%7D)
[](https://insiders.vscode.dev/redirect/mcp/install?name=repomix&config=%7B%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22repomix%22%2C%22--mcp%22%5D%7D&quality=insiders)
1. **使用命令行:**
BASH```
1code --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'
对于VS代码内部人士:
BASH``` 1code-insiders —add-mcp ’{“name”:“repomix”,“command”:“npx”,“args”:[“-y”,“repomix”,“—mcp”]}’
**对于Cline(VS代码扩展):**
编辑 `cline_mcp_settings.json` 文件:
JSON```
1
2
3
4
5
6
7
8
9
10
11
12{
"mcpServers": {
"repomix": {
"command": "npx",
"args": [
"-y",
"repomix",
"--mcp"
]
}
}
}
对于光标:
在Cursor中,从以下位置添加新的MCP服务器 Cursor Settings > MCP > + Add new global MCP server 其配置类似于Cline。
对于Claude Desktop:
编辑 claude_desktop_config.json 文件的配置与Cline的配置类似。
克劳德代码:
在中配置Repomix作为MCP服务器 克劳德代码,使用以下命令:
BASH``` 1claude mcp add repomix — npx -y repomix —mcp
或者,您可以使用官方的Repomix插件(请参阅 Claude代码插件 下节)。
**使用Docker而不是npx:**
您可以使用Docker作为npx的替代品,将Repomix作为MCP服务器运行:
JSON```
1
2
3
4
5
6
7
8
9
10
11
12
13
14{
"mcpServers": {
"repomix-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/yamadashy/repomix",
"--mcp"
]
}
}
}
配置后,您的AI助手可以直接使用Repomix的功能来分析代码库,而无需手动准备文件,从而使代码分析工作流程更加高效。
可用的MCP工具
当作为MCP服务器运行时,Repomix提供以下工具:
- 包装_降价:将本地代码目录打包到一个合并的XML文件中,用于AI分析
-
参数:
-
directory:要打包的目录的绝对路径 -
compress:(可选,默认值:false)启用Tree sitter压缩以提取基本的代码签名和结构,同时删除实现细节。在保留语义含义的同时,将令牌使用量减少约70%。通常不需要,因为grep_recomix_output允许增量内容检索。仅当您特别需要大型存储库的整个代码库内容时才使用。 -
includePatterns:(可选)使用快速glob模式指定要包含的文件。多个模式可以用逗号分隔(例如,“/*.{js,ts}“,”src/,docs/**“)。只处理匹配的文件。 -
ignorePatterns:(可选)使用快速glob模式指定要排除的其他文件。多个模式可以用逗号分隔(例如,“test”/,*.spec.js”,“node_modules”/,dist/**“)。这些模式补充了.gitignore、.ignore和内置排除。 -
topFilesLength:(可选,默认值:10)要在代码库分析的度量摘要中显示的按大小排列的最大文件数。
- 附件打包输出:附加现有的Repomix打包输出文件以进行AI分析
-
参数:
-
path:包含repomix-output.xml的目录路径或打包存储库xml文件的直接路径 -
topFilesLength:(可选,默认值:10)指标摘要中按大小显示的最大文件数 -
特征:
-
接受包含repomix-output.xml文件的目录或xml文件的直接路径
-
在MCP服务器上注册文件,并返回与pack_codownage工具相同的结构
-
提供对现有打包输出的安全访问,无需重新处理
-
可用于处理以前生成的打包存储库
- 包远程存储:获取、克隆GitHub存储库并将其打包为统一的XML文件以进行AI分析
-
参数:
-
remote:GitHub存储库URL或用户/仓库格式(例如,“yamadashy/repomix”https://github.com/user/repo“,或”https://github.com/user/repo/tree/branch”) -
compress:(可选,默认值:false)启用Tree sitter压缩以提取基本的代码签名和结构,同时删除实现细节。在保留语义含义的同时,将令牌使用量减少约70%。通常不需要,因为grep_recomix_output允许增量内容检索。仅当您特别需要大型存储库的整个代码库内容时才使用。 -
includePatterns:(可选)使用快速glob模式指定要包含的文件。多个模式可以用逗号分隔(例如,“/*.{js,ts}“,”src/,docs/**“)。只处理匹配的文件。 -
ignorePatterns:(可选)使用快速glob模式指定要排除的其他文件。多个模式可以用逗号分隔(例如,“test”/,*.spec.js”,“node_modules”/,dist/**“)。这些模式补充了.gitignore、.ignore和内置排除。 -
topFilesLength:(可选,默认值:10)要在代码库分析的度量摘要中显示的按大小排列的最大文件数。
- read_repomix输出:读取Repomix生成的输出文件的内容。支持使用行范围规范对大文件进行部分读取。
-
参数:
-
outputId:要读取的Repomix输出文件的ID -
startLine:(可选)起始行号(从1开始,包括1)。如果未指定,则从头开始读取。 -
endLine:(可选)结束行号(从1开始,包括1)。如果未指定,则读取到末尾。 -
特征:
-
专为基于web的环境或沙盒应用程序而设计
-
使用ID检索以前生成的输出的内容
-
提供对打包代码库的安全访问,而不需要文件系统访问
-
支持大文件的部分读取
- grep_recomix_output:使用类似grep的功能和JavaScript RegExp语法在Repomix输出文件中搜索模式
-
参数:
-
outputId:要搜索的Repomix输出文件的ID -
pattern:搜索模式(JavaScript RegExp正则表达式语法) -
contextLines:(可选,默认值:0)每次匹配前后显示的上下文行数。如果指定,则由前行/后行覆盖。 -
beforeLines:(可选)每次匹配前显示的上下文行数(如grep-B)。优先于contextLines。 -
afterLines:(可选)每次匹配后显示的上下文行数(如grep-A)。优先于contextLines。 -
ignoreCase:(可选,默认值:false)执行不区分大小写的匹配 -
特征:
-
使用JavaScript RegExp语法进行强大的模式匹配
-
支持上下文行,以便更好地理解匹配
-
允许对前后上下文行进行单独控制
-
区分大小写和不区分大小写的搜索选项
- file_system_read_file:使用绝对路径从本地文件系统读取文件。包括内置的安全验证,用于检测和防止访问包含敏感信息的文件。
-
参数:
-
path:要读取的文件的绝对路径 -
安全功能:
-
使用实现安全验证 分泌
-
阻止访问包含敏感信息(API密钥、密码、机密)的文件
-
验证绝对路径以防止目录遍历攻击
- file_system_read_directory:使用绝对路径列出目录的内容。返回一个格式化的列表,显示带有明确指示符的文件和子目录。
-
参数:
-
path:要列出的目录的绝对路径 -
特征:
-
显示带有清晰指示器的文件和目录(
[FILE]或[DIR]) -
提供安全的目录遍历和适当的错误处理
-
验证路径并确保它们是绝对的
-
有助于探索项目结构和理解代码库组织
Claude代码插件
Repomix提供官方插件 克劳德代码 与AI驱动的开发环境无缝集成。
安装
1.添加Repomix插件市场:
TEXT``` 1/plugin marketplace add yamadashy/repomix
**2.安装插件:**
TEXT```
1
2
3
4
5
6# 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
备注:The repomix-mcp 建议将插件作为基础。这 repomix-commands 插件提供方便的斜线命令,而 repomix-explorer 添加了基于AI的分析功能。虽然你可以独立安装它们,但使用这三种方式可以提供最全面的体验。
或者,使用交互式插件安装程序:
TEXT``` 1/plugin
这将打开一个交互式界面,您可以在其中浏览和安装可用的插件。
#### 可用插件
**1.重新混合mcp** (MCP服务器插件)
通过MCP服务器集成提供AI驱动的代码库分析的基础插件。
**特征:**
- 打包本地和远程存储库
- 搜索打包输出
- 使用内置安全扫描(Secretlint)读取文件
- 自动树保姆压缩(约70%的令牌减少)
**2.重新混合命令** (Slash命令插件)
提供方便的斜线命令,以便在自然语言支持下进行快速操作。
**可用命令:**
- `/repomix-commands:pack-local` -用各种选项打包本地代码库
- `/repomix-commands:pack-remote` -打包并分析远程GitHub存储库
**示例用法:**
TEXT```
1
2
3
4/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.重新混合浏览器 (AI分析代理插件)
AI驱动的存储库分析代理,使用Repomix CLI智能地探索代码库。
特征:
- 自然语言代码库探索与分析
- 智能模式发现和代码结构理解
- 使用grep和目标文件读取进行增量分析
- 大型存储库的自动上下文管理
可用命令:
/repomix-explorer:explore-local-在人工智能的帮助下分析本地代码库/repomix-explorer:explore-remote-借助人工智能分析远程GitHub存储库
示例用法:
TEXT``` 1 2 3 4/repomix-explorer:explore-local ./src Find all authentication-related code /repomix-explorer:explore-remote facebook/react Show me the main component architecture
代理自动执行以下操作:
1. 跑 `npx repomix@latest` 打包存储库
2. 使用Grep和Read工具高效搜索输出
3. 在不消耗过多上下文的情况下提供全面的分析
#### 好处
- **无缝集成**:Claude可以直接分析代码库,无需手动准备
- **自然语言**:使用对话式命令,而不是记住CLI语法
- **始终最新**:自动使用 `npx repomix@latest` 获取最新功能
- **内置安全功能**:自动Secretlint扫描可防止敏感数据泄露
- **令牌优化**:大型代码库的树型压缩
有关更多详细信息,请参阅 `.claude/plugins/` 目录。
### 代理技能生成
Repomix可以生成 [克劳德代理技能](https://docs.anthropic.com/en/docs/claude-code/skills) 格式化输出,创建一个结构化的Skills目录,该目录可用作AI助手的可重用代码库参考。当您想从远程存储库引用实现时,此功能特别强大。
#### 基本用法
BASH```
1
2
3
4
5
6# Generate Skills from local directory
repomix --skill-generate
# Generate with custom Skills name
repomix --skill-generate my-project-reference
# Generate from remote repository
repomix --remote https://github.com/user/repo --skill-generate
运行命令时,Repomix会提示您选择保存技能的位置:
- 个人技能 (
~/.claude/skills/)-适用于您计算机上的所有项目 - 项目技能 (
.claude/skills/)-通过git与您的团队共享
非交互式使用
对于CI管道和自动化脚本,您可以使用以下命令跳过所有交互式提示 --skill-output 和 --force:
BASH``` 1 2 3 4 5 6# 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
#### 生成的结构
技能按以下结构生成:
TEXT```
1
2
3
4
5
6
7.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
包含内容
- 技能.md:包含技能元数据、文件/行/令牌计数、概述和使用说明
- summary.md:解释技能的目的、使用指南,并按文件类型和语言提供统计细分
- 项目结构.md:包含每个文件行数的目录树,便于查找文件
- files.md:所有文件内容都带有语法突出显示的标题,针对grep友好的搜索进行了优化
- 技术支持.md:从依赖文件中自动检测每个包的技术堆栈(
package.json,requirements.txt,Cargo.toml等等)
自动生成的技能名称
如果没有提供名称,Repomix会自动生成一个:
BASH``` 1 2 3repomix 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功能集成
技能生成尊重所有标准的Repomix选项:
BASH```
1
2
3
4
5
6# 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探索者技能(代理技能)
Repomix提供即用型 Repomix浏览器 该技能使AI编码助手能够使用Repomix CLI分析和探索代码库。该技能旨在与各种AI工具配合使用,包括Claude Code、Cursor、Codex、GitHub Copilot等。
快速安装
BASH``` 1npx add-skill yamadashy/repomix —skill repomix-explorer
此命令将技能安装到您的AI助手的技能目录中(例如。, `.claude/skills/`),使其立即可用。
#### 它的作用
安装后,您可以使用自然语言指令分析代码库。
分析远程存储库:
TEXT```
1
2"What's the structure of this repo?
https://github.com/facebook/react"
探索本地代码库:
TEXT``` 1 2”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` 项目根目录中的文件:
BASH```
1repomix --init
这将创建一个 repomix.config.json 使用默认设置的文件。
TypeScript配置
TypeScript配置文件提供了最佳的开发人员体验,具有完整的类型检查和IDE支持。
安装:
使用TypeScript或JavaScript配置 defineConfig,您需要将Repomix作为开发依赖项安装:
BASH``` 1npm install -D repomix
**例子:**
TYPESCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12// 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自动补全和智能感知
- ✅ 使用动态值(时间戳、环境变量等)
动态值示例:
TYPESCRIPT```
1
2
3
4
5
6
7
8
9
10// 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` |
| `output.filePath` | 输出文件的名称 | `"repomix-output.xml"` |
| `output.style` | 输出的风格(`xml`, `markdown`, `json`, `plain`) | `"xml"` |
| `output.parsableStyle` | 是否根据所选样式模式转义输出。请注意,这可能会增加令牌计数。 | `false` |
| `output.compress` | 是否执行智能代码提取以减少令牌计数 | `false` |
| `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数据字符串(例如图像)以减少令牌计数 | `false` |
| `output.copyToClipboard` | 除了保存文件外,是否将输出复制到系统剪贴板 | `false` |
| `output.splitOutput` | 按每个部分的最大大小将输出拆分为多个编号的文件(例如。, `1000000` 约1MB)。将每个文件保持在限制范围内,避免跨部分拆分文件 | 未设置 |
| `output.topFilesLength` | 要在摘要中显示的顶级文件数。如果设置为0,则不会显示摘要 | `5` |
| `output.tokenCountTree` | 是否显示带有令牌计数摘要的文件树。可以是布尔值或数字(最小令牌计数阈值) | `false` |
| `output.includeEmptyDirectories` | 是否在存储库结构中包含空目录 | `false` |
| `output.includeFullDirectoryStructure` | 使用时 `include` 模式,是否显示完整的目录树(尊重忽略模式),同时仍然只处理包含的文件。为AI分析提供完整的存储库上下文 | `false` |
| `output.git.sortByChanges` | 是否按git更改计数对文件进行排序(更改较多的文件显示在底部) | `true` |
| `output.git.sortByChangesMaxCommits` | 用于分析git更改的最大提交数 | `100` |
| `output.git.includeDiffs` | 是否在输出中包含git diffs(分别包括工作树和阶段性更改) | `false` |
| `output.git.includeLogs` | 是否在输出中包含git日志(包括包含日期、消息和文件路径的提交历史) | `false` |
| `output.git.includeLogsCount` | 要包含的git日志提交数 | `50` |
| `include` | 要包含的文件模式(使用 [球状图案](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax)) | `[]` |
| `ignore.useGitignore` | 是否使用项目中的模式 `.gitignore` 文件 | `true` |
| `ignore.useDotIgnore` | 是否使用项目中的模式 `.ignore` 文件 | `true` |
| `ignore.useDefaultPatterns` | 是否使用默认忽略模式 | `true` |
| `ignore.customPatterns` | 要忽略的其他模式(使用 [球状图案](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax)) | `[]` |
| `security.enableSecurityCheck` | 是否对文件进行安全检查 | `true` |
| `tokenCount.encoding` | 用于OpenAI兼容令牌化的令牌计数编码(例如。, `o200k_base` 对于GPT-4o, `cl100k_base` GPT-4/3.5)。由…驱动 [gpt标记器](https://github.com/nicolo-ribaudo/gpt-tokenizer). | `"o200k_base"` |
配置文件支持 [JSON5](https://json5.org/) 语法,它允许:
- 注释(单行和多行)
- 对象和数组中的尾随逗号
- 未引用的房产名称
- 更宽松的字符串语法
### 模式验证
您可以通过添加以下内容为配置文件启用架构验证 `$schema` 财产:
JSON```
1
2
3
4
5
6
7{
"$schema": "https://repomix.com/schemas/latest/schema.json",
"output": {
"filePath": "repomix-output.xml",
"style": "xml"
}
}
这在支持JSON模式的编辑器中提供了自动完成和验证。
配置示例
配置示例:
JSON5``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48{ “$schema”: “https://repomix.com/schemas/latest/schema.json”, “input”: { “maxFileSize”: 50000000 }, “output”: { “filePath”: “repomix-output.xml”, “style”: “xml”, “parsableStyle”: false, “compress”: false, “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 “showLineNumbers”: false, “truncateBase64”: false, “copyToClipboard”: false, “splitOutput”: null, // or a number like 1000000 for ~1MB per file “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” } }
### 全局配置
要创建全局配置文件,请执行以下操作:
BASH```
1repomix --init --global
全局配置文件将在以下位置创建:
- 窗户:
%LOCALAPPDATA%\Repomix\repomix.config.json - macOS/Linux:
$XDG_CONFIG_HOME/repomix/repomix.config.json或~/.config/repomix/repomix.config.json
注意:本地配置(如果存在)优先于全局配置。
包含和忽略
包括图案
Repomix现在支持指定要包含的文件 使用 球状图案。这允许更多 灵活而强大的文件选择:
- 使用
**/*.js包含任何目录中的所有JavaScript文件 - 使用
src/**/*将所有文件包含在src目录及其子目录 - 组合多种模式,如
["src/**/*.js", "**/*.md"]将JavaScript文件包含在src所有Markdown 文件
忽略模式
Repomix提供了多种方法来设置忽略模式,以便在打包过程中排除特定的文件或目录 过程:
- 微笑。:默认情况下,项目中列出的模式
.gitignore文件和.git/info/exclude使用。这种行为可以通过以下方式控制ignore.useGitignore设置或--no-gitignorecli选项。 - 忽略:您可以使用
.ignore项目根目录中的文件,格式与.gitignore此文件受到ripgrep和silver search等工具的尊重,从而减少了维护多个忽略文件的需要。这种行为可以通过以下方式控制ignore.useDotIgnore设置或--no-dot-ignorecli选项。 - 默认图案:Repomix包括通常被排除的文件和目录的默认列表(例如,
.git、二进制文件)。此功能可以通过以下方式控制
ignore.useDefaultPatterns设置或--no-default-patternscli选项。请 看见 默认的nore.ts 了解更多详情。 - .repmixignore:您可以创建
.repomixignore项目根目录中的文件,用于定义Repomix特定的忽略 模式。此文件的格式与.gitignore. - 定制图案:可以使用以下命令指定其他忽略模式
ignore.customPatterns选项在 配置文件。您可以用覆盖此设置-i, --ignore命令行选项。
优先级顺序(从高到低):
- 定制图案(
ignore.customPatterns) - 忽略文件(
.repomixignore,.ignore,.gitignore,以及.git/info/exclude):
- 在嵌套目录中时,深层目录中的文件具有更高的优先级
- 当这些文件位于同一目录中时,它们不会以特定的顺序合并
- 默认模式(如果
ignore.useDefaultPatterns这是真的--no-default-patterns未使用)
这种方法允许根据项目的需要进行灵活的文件排除配置。它有助于优化尺寸 通过确保排除安全敏感文件和大型二进制文件来生成包文件,同时 防止机密信息泄露。
注意:默认情况下,二进制文件不包含在打包输出中,但它们的路径列在“存储库”中 输出文件的“结构”部分。这提供了存储库结构的完整概述,同时保留了 打包文件高效且基于文本。
客户指令
这 output.instructionFilePath 选项允许您指定一个包含详细说明的单独文件,或
关于你项目的背景。这使得人工智能系统能够理解项目的具体背景和要求,
可能导致更相关和量身定制的分析或建议。
以下是一个如何使用此功能的示例:
- 创建一个名为的文件
repomix-instruction.md在项目根目录中:
MARKDOWN``` 1 2 3 4 5 6 7 8# 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` 选项:
JSON5```
1
2
3
4
5
6{
"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包括一个安全检查功能,该功能使用 分泌 检测 文件中的潜在敏感信息。此功能可帮助您在共享之前识别可能的安全风险 您打包的存储库。
打包过程完成后,安全检查结果将显示在CLI输出中。如有可疑 如果检测到文件,您将看到这些文件的列表以及警告消息。
输出示例:
1
2
3
4
5
6🔍 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 在您的配置文件中:
JSON``` 1 2 3 4 5{ “security”: { “enableSecurityCheck”: false } }
或使用 `--no-security-check` 命令行选项:
BASH```
1repomix --no-security-check
[!注意] 禁用安全检查可能会暴露敏感信息。谨慎使用此选项,仅在必要时使用,例如 就像处理包含示例凭据的测试文件或文档时一样。
🤖 将Repomix与GitHub操作结合使用
您还可以在GitHub Actions工作流中使用Repomix。这对于自动化打包代码库以进行AI分析的过程非常有用。
基本用法:
YAML``` 1 2 3 4 5- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomix@main with: output: repomix-output.xml style: xml
使用 `--style` 生成不同格式的输出:
YAML```
1
2
3
4
5- name: Pack repository with Repomix
uses: yamadashy/repomix/.github/actions/repomix@main
with:
output: repomix-output.md
style: markdown
YAML``` 1 2 3 4 5- name: Pack repository with Repomix (JSON format) uses: yamadashy/repomix/.github/actions/repomix@main with: output: repomix-output.json style: json
使用压缩打包特定目录:
YAML```
1
2
3
4
5
6
7
8- 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
将输出文件作为工件上传:
YAML``` 1 2 3 4 5 6 7 8 9 10 11- 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@v4 with: name: repomix-output path: repomix-output.txt
完整的工作流程示例:
YAML```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23name: 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@v4
- 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@v4
with:
name: repomix-output.xml
path: repomix-output.xml
retention-days: 30
查看完整的工作流示例 这里.
动作输入
| 名称 | 描述 | 默认值 |
|---|---|---|
directories | 以空格分隔的要处理的目录列表(例如。, src tests docs) | . |
include | 逗号分隔的球形图案,以包括文件(例如。, **/*.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 |
行动输出
| 名称 | 描述 |
|---|---|
output_file | 生成的输出文件的路径。可以在后续步骤中用于工件上传、LLM处理或其他操作。该文件包含基于指定选项的代码库的格式化表示。 |
📚 将Repomix用作库
除了将Repomix用作CLI工具外,您还可以将其用作Node.js应用程序中的库。
安装
BASH``` 1npm install repomix
### 基本用法
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12import { 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;
}
进程远程存储库
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10import { 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:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14import { 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)
}));
}
有关更多示例,请查看以下位置的源代码 网站/服务器/src/remoteRepo.ts 这演示了repomix.com如何使用该库。
捆绑
当使用Rolldown或esbuild等工具捆绑repomix时,一些依赖关系必须保持在外部,并且需要复制WASM文件:
外部依赖关系(无法捆绑):
tinypool-使用文件路径生成工作线程
要复制的WASM文件:
web-tree-sitter.wasm→ 与捆绑的JS目录相同(代码压缩功能所需)- 树型语言文件→ 指定的目录
REPOMIX_WASM_DIR环境变量
有关工作示例,请参见 网站/服务器/脚本/bundle.mjs.
🌍 社区项目
探索Repomix社区打造的精彩项目!
- Repomix跑步者 -VSCode扩展,用于将文件捆绑到单个输出中进行AI处理
- Repomix桌面 -使用Python和CustomTkinter构建的Repomix GUI桌面应用程序
- Python Repomix -基于AST压缩的Python实现
- 规则 -使用Claude AI将GitHub仓库转换为自定义的Cursor AI规则
- 代码库MCP -使用Repomix进行AI驱动的代码库分析的MCP服务器
- vibe工具 -用于AI代理的CLI工具集,具有web搜索、仓库分析和浏览器自动化功能
如需了解更多详情,请访问我们的 社区项目页面.
🤝 贡献
我们欢迎社区的贡献!要开始,请参阅我们的 贡献指南.
贡献者
🔒 隐私政策
查看我们的 隐私政策.
📜 许可证
该项目根据 MIT许可证.
Back To Top
