需要讨论吗?加入我们的 Discord!
分享您的经验和技巧
了解新功能的最新动态
获取配置和使用方面的帮助
📦 Repomix 是一款强大的工具,可以将你的整个仓库打包到一个对 AI 友好的文件中。它非常适合你需要将代码库输入大型语言模型(LLM)或其他 AI 工具,如 Claude、ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等。
请考虑赞助我。
🏆 开源奖项提名
我们感到荣幸!Repomix 已被提名为 JSNation 开源奖 2025 的 由 AI 提供支持 类别。
没有你们所有人使用和支持Repomix,这一切都不可能实现。谢谢大家!
🎉 新内容:Repomix网站和Discord社区!
- 在浏览器中尝试使用 Repomix,访问 repomix.com
- 加入我们的 Discord 服务器 获取支持和讨论
我们期待在那里见到你!
🌟 特色
- AI优化:以AI易于理解和处理的方式格式化你的代码库。
- 令牌计数:为每个文件及整个仓库提供令牌计数,对LLM上下文限制非常有用。
- 简单易用:你只需一个命令就能打包整个仓库。
- 可自定义:轻松配置包含或排除的内容。
- Git 感知:自动遵守你的
.gitignore、.ignore和.repomixignore文件。 - 安全为先:整合了 Secretlint 来检测匹配已知凭证格式的文件,并将其排除在输出之外。
- 代码压缩:
--compress选项使用 Tree-sitter 提取关键代码元素,在保留结构的同时减少令牌数量。
🚀 快速开始
使用 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.
当你提出具体变更时,AI可能能够相应生成代码。借助Claude's Artifacts等功能,你可能输出多个文件,从而生成多个相互依赖的代码片段。
祝你编程愉快!🚀
使用本网站 🌐
想快速试一试吗?访问官方网站 repomix.com。只需输入你的仓库名称,填写任何可选信息,然后点击 Pack 按钮即可查看生成的输出。
可选方案
该网站提供多项便捷功能:
- 可自定义输出格式(XML、Markdown 或纯文本)
- 即时令牌计数估计
- 更多!
使用浏览器扩展 🧩
直接从任何 GitHub 仓库获取 Repomix 的即时访问!我们的 Chrome 扩展为 GitHub 仓库页面添加了一个方便的“Repomix”按钮。
安装
- Chrome 扩展程序: Repomix - Chrome 网上应用店
- Firefox 插件:Repomix - Firefox 插件
特色
- 一键访问任何 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
从文件列表打包文件(通过标准输入管道):
# 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 等。
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/ 命令行/
cliOutput.ts
index.ts
(...remaining directories)
# Repository Files
## File: src/index.js
// 文件内容在这里
(...remaining files)
# Instruction
(Custom instructions from `output.instructionFilePath`)
这种格式提供了一个干净、可读的结构,既适合人类阅读,又易于被人工智能系统解析。
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 工具兼容性:为机器学习和人工智能系统提供结构化格式
- 数据分析:使用如
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 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、构建目录等) |
远程仓库选项
| 选项 | 描述 |
|---|---|
--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)--token-budget <number>:当打包输出超过 N 个令牌时,以非零退出代码失败。在 CI 流水线和代理工作流程中作为防护措施使用,以保持输出在目标模型的上下文窗口内。输出仍会生成;仅退出代码表示溢出。
MCP
--mcp:作为模型上下文协议服务器运行,以便 AI 工具集成--sandbox [dir]:(配合--mcp使用)将 MCP 服务器的文件工具限制在工作区目录(默认为工作目录;例如--sandbox path/to/project)——每个路径相对于该根目录,拒绝绝对/主机路径,并禁用远程打包、技能生成及附加外部输出。
代理技能生成
| 选项 | 描述 |
|---|---|
--skill-generate [name] |
生成 Claude Agent 技能格式的输出到 .claude/skills/<name>/ 目录(如果省略则自动生成名称) |
--skill-project-name <name> |
覆盖生成技能描述中使用的项目名称 |
--skill-output <path> |
直接指定技能输出目录路径(跳过位置提示) |
-f, --force |
跳过所有确认提示(技能目录覆盖、远程配置信任) |
观察模式
-
-w, --watch:监视文件更改并自动重新打包。对快速更改进行去抖(300毫秒),并在每次重建时记录时间戳。使用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
[!注意]
出于安全考虑,配置文件 (`rREADME 内容已截断, 请前往 GitHub 查看完整内容。