repomix
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRepomix - Codebase Packing for AI
Repomix - 面向AI的代码库打包工具
Pack your entire repository into a single, AI-friendly file optimized for LLMs like Claude, ChatGPT, Gemini, and more.
将你的整个代码库打包为单个适合AI处理的文件,优化后可用于Claude、ChatGPT、Gemini等各类大语言模型(LLM)。
When to Use This Skill
适用场景
- Feeding codebase to AI for analysis or refactoring
- Generating comprehensive code reviews
- Creating documentation from code
- Preparing context for AI-assisted development
- Analyzing remote repositories without cloning
- Token counting for LLM context limits
- 将代码库提供给AI进行分析或重构
- 生成全面的代码审查报告
- 基于代码创建文档
- 为AI辅助开发准备上下文
- 无需克隆即可分析远程代码库
- 计算LLM上下文限制的令牌数量
Quick Start
快速开始
bash
undefinedbash
undefinedPack current directory (no install required)
打包当前目录(无需安装)
npx repomix@latest
npx repomix@latest
Pack specific directory
打包指定目录
npx repomix path/to/directory
npx repomix path/to/directory
Pack with compression (~70% token reduction)
启用压缩打包(约减少70%令牌数量)
npx repomix --compress
npx repomix --compress
Copy output to clipboard
将输出结果复制到剪贴板
npx repomix --copy
**Default output:** `./repomix-output.xml` in current directorynpx repomix --copy
**默认输出**:当前目录下的 `./repomix-output.xml` 文件Examples
使用示例
Example: Prepare codebase for Claude review
User: "Pack my src folder for Claude to review the architecture"
→ npx repomix --include "src/**/*" --style xml --copy
→ Output copied to clipboard, ready to paste into ClaudeExample: Analyze remote repo without cloning
User: "I want to understand how shadcn/ui implements its button"
→ npx repomix --remote shadcn-ui/ui --include "**/button/**/*" --compress
→ Generates focused output of button componentExample: Prepare PR diff for review
User: "Pack only the files I changed for a code review"
→ git diff --name-only main | npx repomix --stdin --compress
→ Packs only modified files with compressionExample: Check token usage before sending to AI
User: "Is my codebase too large for GPT-4?"
→ npx repomix --token-count-tree
→ Shows token breakdown per file/directoryExample: Generate skills reference from library
User: "Create a Claude skill from the zod repository"
→ npx repomix --remote colinhacks/zod --skill-generate zod-reference
→ Generates AI-optimized reference documentation示例:为Claude审查准备代码库
用户:"打包我的src文件夹,供Claude审查架构"
→ npx repomix --include "src/**/*" --style xml --copy
→ 输出结果已复制到剪贴板,可直接粘贴至Claude示例:无需克隆即可分析远程代码库
用户:"我想了解shadcn/ui是如何实现按钮组件的"
→ npx repomix --remote shadcn-ui/ui --include "**/button/**/*" --compress
→ 生成聚焦于按钮组件的输出结果示例:为PR审查准备代码
用户:"仅打包我修改过的文件用于代码审查"
→ git diff --name-only main | npx repomix --stdin --compress
→ 仅打包修改过的文件并启用压缩示例:发送至AI前检查令牌使用量
用户:"我的代码库对GPT-4来说太大了吗?"
→ npx repomix --token-count-tree
→ 显示每个文件/目录的令牌数量明细示例:从代码库生成技能参考文档
用户:"从zod代码库生成Claude技能文档"
→ npx repomix --remote colinhacks/zod --skill-generate zod-reference
→ 生成优化后适合AI使用的参考文档Output Formats
输出格式
bash
undefinedbash
undefinedXML (default) - best for Claude
XML(默认格式)- 最适合Claude
npx repomix --style xml
npx repomix --style xml
Markdown - human readable
Markdown - 便于人类阅读
npx repomix --style markdown
npx repomix --style markdown
JSON - programmatic processing
JSON - 便于程序化处理
npx repomix --style json
npx repomix --style json
Plain text
纯文本
npx repomix --style plain
undefinednpx repomix --style plain
undefinedToken Optimization
令牌优化
LLM Context Limits Reference
LLM上下文限制参考
| Model | Context Window | Typical Repo Fit |
|---|---|---|
| Claude 3.5/Opus | 200K tokens | Large monorepos |
| GPT-4 Turbo/4o | 128K tokens | Medium projects |
| Gemini 1.5 Pro | 1M tokens | Very large codebases |
| Gemini 1.5 Flash | 1M tokens | Very large codebases |
| 模型 | 上下文窗口 | 适配代码库规模 |
|---|---|---|
| Claude 3.5/Opus | 200K 令牌 | 大型单体仓库 |
| GPT-4 Turbo/4o | 128K 令牌 | 中型项目 |
| Gemini 1.5 Pro | 1M 令牌 | 超大型代码库 |
| Gemini 1.5 Flash | 1M 令牌 | 超大型代码库 |
Token Analysis
令牌分析
bash
undefinedbash
undefinedShow token count tree
显示令牌数量树形结构
npx repomix --token-count-tree
npx repomix --token-count-tree
Filter by minimum tokens (show files with 1000+ tokens)
按最小令牌数过滤(显示令牌数≥1000的文件)
npx repomix --token-count-tree 1000
npx repomix --token-count-tree 1000
Split output for large codebases
为大型代码库拆分输出
npx repomix --split-output 1mb
undefinednpx repomix --split-output 1mb
undefinedFile Selection
文件选择
Include Patterns
包含规则
bash
undefinedbash
undefinedInclude only TypeScript files
仅包含TypeScript文件
npx repomix --include "**/*.ts"
npx repomix --include "**/*.ts"
Include multiple patterns
包含多个规则
npx repomix --include "src//*.ts,/*.md"
npx repomix --include "src//*.ts,/*.md"
Include specific directories
包含指定目录
npx repomix --include "src//*,tests//*"
undefinednpx repomix --include "src//*,tests//*"
undefinedIgnore Patterns
忽略规则
bash
undefinedbash
undefinedIgnore test files
忽略测试文件
npx repomix --ignore "**/*.test.ts"
npx repomix --ignore "**/*.test.ts"
Ignore multiple patterns
忽略多个规则
npx repomix --ignore "**/*.log,tmp/,dist/"
npx repomix --ignore "**/*.log,tmp/,dist/"
Combine include and ignore
组合包含与忽略规则
npx repomix --include "src//*.ts" --ignore "/*.test.ts"
undefinednpx repomix --include "src//*.ts" --ignore "/*.test.ts"
undefinedStdin Input
标准输入(Stdin)
bash
undefinedbash
undefinedFrom find command
从find命令获取文件列表
find src -name "*.ts" -type f | npx repomix --stdin
find src -name "*.ts" -type f | npx repomix --stdin
From git tracked files
从Git追踪文件获取
git ls-files "*.ts" | npx repomix --stdin
git ls-files "*.ts" | npx repomix --stdin
Interactive selection with fzf
使用fzf交互式选择
find . -name "*.ts" -type f | fzf -m | npx repomix --stdin
find . -name "*.ts" -type f | fzf -m | npx repomix --stdin
From ripgrep
从ripgrep获取
rg --files --type ts | npx repomix --stdin
undefinedrg --files --type ts | npx repomix --stdin
undefinedCommon Workflows
常见工作流
PR Review Preparation
PR审查准备
bash
undefinedbash
undefinedPack only changed files for review
仅打包修改文件用于审查
git diff --name-only main | npx repomix --stdin --compress
git diff --name-only main | npx repomix --stdin --compress
Pack with diff context included
包含差异上下文的打包
npx repomix --include-diffs --compress
undefinednpx repomix --include-diffs --compress
undefinedArchitecture Analysis
架构分析
bash
undefinedbash
undefinedPack structure without implementation details
仅打包结构信息,忽略实现细节
npx repomix --compress --include "src//*" --ignore "/.test."
npx repomix --compress --include "src//*" --ignore "/.test."
Focus on specific layer
聚焦特定层级
npx repomix --include "src/api//*,src/services//*" --compress
undefinednpx repomix --include "src/api//*,src/services//*" --compress
undefinedDocumentation Generation
文档生成
bash
undefinedbash
undefinedPack with full context for docs
打包完整上下文用于生成文档
npx repomix --include "src//*,/*.md" --style markdown
npx repomix --include "src//*,/*.md" --style markdown
Include git history for changelog
包含Git历史用于生成变更日志
npx repomix --include-logs --include-logs-count 50
undefinednpx repomix --include-logs --include-logs-count 50
undefinedDependency Analysis
依赖分析
bash
undefinedbash
undefinedPack only config and dependency files
仅打包配置与依赖文件
npx repomix --include "package.json,tsconfig.json,**/.config."
undefinednpx repomix --include "package.json,tsconfig.json,**/.config."
undefinedRemote Repositories
远程代码库
bash
undefinedbash
undefinedPack remote repository
打包远程代码库
npx repomix --remote https://github.com/user/repo
npx repomix --remote https://github.com/user/repo
GitHub shorthand
GitHub简写格式
npx repomix --remote user/repo
npx repomix --remote user/repo
Specific branch
指定分支
npx repomix --remote user/repo --remote-branch main
npx repomix --remote user/repo --remote-branch main
Specific commit
指定提交记录
npx repomix --remote user/repo --remote-branch 935b695
npx repomix --remote user/repo --remote-branch 935b695
Branch URL format
分支URL格式
npx repomix --remote https://github.com/user/repo/tree/feature-branch
undefinednpx repomix --remote https://github.com/user/repo/tree/feature-branch
undefinedCode Compression
代码压缩
Tree-sitter powered compression extracts signatures while removing implementation details.
基于Tree-sitter的压缩技术会提取代码签名,同时移除实现细节。
Supported Languages
支持的语言
Tree-sitter compression works with: JavaScript, TypeScript, Python, Ruby, Go, Rust, Java, C, C++, C#, PHP, Swift, Kotlin, and more.
Tree-sitter压缩支持以下语言:JavaScript、TypeScript、Python、Ruby、Go、Rust、Java、C、C++、C#、PHP、Swift、Kotlin等。
Usage
使用方式
bash
npx repomix --compressbash
npx repomix --compressCombine with remote
结合远程代码库使用
npx repomix --remote user/repo --compress
**Before compression:**
```typescript
const calculateTotal = (items: Item[]) => {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
};After compression:
typescript
const calculateTotal = (items: Item[]) => { /* ... */ };npx repomix --remote user/repo --compress
**压缩前:**
```typescript
const calculateTotal = (items: Item[]) => {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
};压缩后:
typescript
const calculateTotal = (items: Item[]) => { /* ... */ };Git Integration
Git集成
bash
undefinedbash
undefinedInclude git logs (last 50 commits)
包含Git提交日志(最近50条)
npx repomix --include-logs
npx repomix --include-logs
Specify commit count
指定提交日志数量
npx repomix --include-logs --include-logs-count 20
npx repomix --include-logs --include-logs-count 20
Include git diffs
包含Git差异
npx repomix --include-diffs
npx repomix --include-diffs
Combine logs and diffs
同时包含日志与差异
npx repomix --include-logs --include-diffs
undefinednpx repomix --include-logs --include-diffs
undefinedConfiguration
配置
Initialize Config
初始化配置
bash
undefinedbash
undefinedCreate repomix.config.json
创建repomix.config.json配置文件
npx repomix --init
npx repomix --init
Global config
全局配置
npx repomix --init --global
undefinednpx repomix --init --global
undefinedConfiguration File
配置文件示例
json
{
"$schema": "https://repomix.com/schemas/latest/schema.json",
"output": {
"filePath": "repomix-output.xml",
"style": "xml",
"compress": false,
"removeComments": false,
"showLineNumbers": false,
"copyToClipboard": false
},
"include": ["src/**/*", "**/*.md"],
"ignore": {
"useGitignore": true,
"useDefaultPatterns": true,
"customPatterns": ["**/*.test.ts", "dist/"]
},
"security": {
"enableSecurityCheck": true
}
}json
{
"$schema": "https://repomix.com/schemas/latest/schema.json",
"output": {
"filePath": "repomix-output.xml",
"style": "xml",
"compress": false,
"removeComments": false,
"showLineNumbers": false,
"copyToClipboard": false
},
"include": ["src/**/*", "**/*.md"],
"ignore": {
"useGitignore": true,
"useDefaultPatterns": true,
"customPatterns": ["**/*.test.ts", "dist/"]
},
"security": {
"enableSecurityCheck": true
}
}Docker Usage
Docker使用方式
bash
undefinedbash
undefinedPack current directory
打包当前目录
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix
Pack specific directory
打包指定目录
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory
Remote repository
打包远程代码库
docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote user/repo
undefineddocker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote user/repo
undefinedMCP Server Integration
MCP服务器集成
Run as Model Context Protocol server for AI assistants:
bash
npx repomix --mcp作为模型上下文协议(Model Context Protocol, MCP)服务器运行,供AI助手使用:
bash
npx repomix --mcpConfigure for Claude Code
配置Claude Code
bash
claude mcp add repomix -- npx -y repomix --mcpbash
claude mcp add repomix -- npx -y repomix --mcpAvailable MCP Tools
可用MCP工具
When running as MCP server, provides:
| Tool | Description |
|---|---|
| Pack local directory into AI-friendly format |
| Pack GitHub repository without cloning |
| Read contents of generated output file |
| Get directory tree structure |
作为MCP服务器运行时,提供以下工具:
| 工具 | 描述 |
|---|---|
| 将本地目录打包为适合AI的格式 |
| 无需克隆即可打包GitHub代码库 |
| 读取生成的输出文件内容 |
| 获取目录树形结构 |
Claude Agent Skills Generation
Claude Agent技能生成
Generate skills format output for Claude:
bash
undefined生成适合Claude使用的技能格式输出:
bash
undefinedGenerate skills from local directory
从本地目录生成技能文档
npx repomix --skill-generate
npx repomix --skill-generate
Generate with custom name
使用自定义名称生成
npx repomix --skill-generate my-project-reference
npx repomix --skill-generate my-project-reference
From remote repository
从远程代码库生成
npx repomix --remote user/repo --skill-generate
undefinednpx repomix --remote user/repo --skill-generate
undefinedCLI Options Reference
CLI选项参考
| Option | Description |
|---|---|
| Output file path |
| Output format: xml, markdown, json, plain |
| Enable Tree-sitter compression |
| Include files matching glob patterns |
| Exclude files matching patterns |
| Process remote repository |
| Branch, tag, or commit for remote |
| Read file paths from stdin |
| Copy output to clipboard |
| Show token counts per file |
| Split output by size (e.g., 1mb) |
| Include git commit history |
| Include git diffs |
| Skip sensitive data detection |
| Run as MCP server |
| Generate Claude skills format |
| Create configuration file |
| Show all available options |
| 选项 | 描述 |
|---|---|
| 输出文件路径 |
| 输出格式:xml、markdown、json、plain |
| 启用Tree-sitter压缩 |
| 包含匹配通配符规则的文件 |
| 排除匹配规则的文件 |
| 处理远程代码库 |
| 远程代码库的分支、标签或提交记录 |
| 从标准输入读取文件路径 |
| 将输出复制到剪贴板 |
| 显示每个文件的令牌数量 |
| 按大小拆分输出(例如:1mb) |
| 包含Git提交历史 |
| 包含Git差异 |
| 跳过敏感数据检测 |
| 以MCP服务器模式运行 |
| 生成Claude技能格式输出 |
| 创建配置文件 |
| 显示所有可用选项 |
Troubleshooting
故障排除
| Issue | Solution |
|---|---|
| Output too large for LLM | Use |
| Missing expected files | Check |
| Secrets detected (blocking) | Review flagged files; use |
| Memory issues on large repos | Use |
| Remote repo access denied | Check URL format; ensure repo is public or use SSH |
| Compression not working | Verify language is supported by Tree-sitter |
| Output not in clipboard | Ensure clipboard access; try |
| 问题 | 解决方案 |
|---|---|
| 输出结果超出LLM上下文限制 | 使用 |
| 缺少预期文件 | 检查 |
| 检测到敏感信息(被阻止) | 检查标记的文件;若为误报,可使用 |
| 处理大型代码库时出现内存问题 | 使用 |
| 远程代码库访问被拒绝 | 检查URL格式;确保代码库为公开,或使用SSH认证 |
| 压缩功能无效 | 确认语言是否受Tree-sitter支持 |
| 输出未复制到剪贴板 | 确保剪贴板权限正常;macOS可尝试 |
Ignore Files
忽略文件优先级
Repomix respects multiple ignore sources (priority order):
- in config
ignore.customPatterns - (Repomix-specific)
.repomixignore - (ripgrep compatible)
.ignore .gitignore- Default patterns (node_modules, .git, etc.)
Repomix会遵循多种忽略规则,优先级从高到低为:
- 配置文件中的
ignore.customPatterns - (Repomix专属忽略文件)
.repomixignore - (兼容ripgrep格式)
.ignore .gitignore- 默认忽略规则(如node_modules、.git等)
Security
安全特性
Repomix includes Secretlint for detecting sensitive information:
bash
undefinedRepomix集成了Secretlint工具用于检测敏感信息:
bash
undefinedSecurity check enabled by default
默认启用安全检查
npx repomix
npx repomix
Disable security check (use with caution)
禁用安全检查(谨慎使用)
npx repomix --no-security-check
**Detected secret types:** API keys, tokens, passwords, private keys, AWS credentials, database connection strings, and more.npx repomix --no-security-check
**检测到的敏感信息类型**:API密钥、令牌、密码、私钥、AWS凭证、数据库连接字符串等。Best Practices
最佳实践
- Use compression for large codebases to reduce token count (~70% reduction)
- Filter with --include to focus on relevant files
- Use --token-count-tree to identify large files before packing
- Split output when hitting AI context limits
- Include git logs for evolution context when needed
- Use XML style for Claude (optimized for XML tags)
- Use Markdown for human-readable output or other LLMs
- Check token counts against your target LLM's context window
- Review security warnings before sharing packed output
- 启用压缩:处理大型代码库时使用参数,可减少约70%的令牌数量
--compress - 过滤文件:使用参数聚焦相关文件,避免冗余内容
--include - 预检查令牌数量:使用参数识别大型文件后再打包
--token-count-tree - 拆分输出:当超出AI上下文限制时,使用参数拆分结果
--split-output - 按需包含Git日志:需要代码演进上下文时,添加参数
--include-logs - Claude适配:使用XML格式输出,适配Claude的XML标签优化处理
- 人类阅读适配:使用Markdown格式输出,便于人类阅读或其他LLM使用
- 匹配上下文窗口:根据目标LLM的上下文窗口检查令牌数量
- 安全审查:分享打包结果前,务必检查安全警告
Requirements
环境要求
- Node.js 18.0.0 or higher
- npm or npx available in PATH
- Node.js 18.0.0或更高版本
- 系统PATH中包含npm或npx
Resources
相关资源
- Website: https://repomix.com
- GitHub: https://github.com/yamadashy/repomix
- Chrome Extension: Repomix - Chrome Web Store
- VSCode Extension: Repomix Runner
- 官网:https://repomix.com
- GitHub仓库:https://github.com/yamadashy/repomix
- Chrome扩展:Repomix - Chrome Web Store
- VSCode扩展:Repomix Runner