repomix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Repomix - 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
undefined
bash
undefined

Pack 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 directory
npx 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 Claude
Example: 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 component
Example: 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 compression
Example: 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/directory
Example: 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
undefined
bash
undefined

XML (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
undefined
npx repomix --style plain
undefined

Token Optimization

令牌优化

LLM Context Limits Reference

LLM上下文限制参考

ModelContext WindowTypical Repo Fit
Claude 3.5/Opus200K tokensLarge monorepos
GPT-4 Turbo/4o128K tokensMedium projects
Gemini 1.5 Pro1M tokensVery large codebases
Gemini 1.5 Flash1M tokensVery large codebases
模型上下文窗口适配代码库规模
Claude 3.5/Opus200K 令牌大型单体仓库
GPT-4 Turbo/4o128K 令牌中型项目
Gemini 1.5 Pro1M 令牌超大型代码库
Gemini 1.5 Flash1M 令牌超大型代码库

Token Analysis

令牌分析

bash
undefined
bash
undefined

Show 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
undefined
npx repomix --split-output 1mb
undefined

File Selection

文件选择

Include Patterns

包含规则

bash
undefined
bash
undefined

Include 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//*"
undefined
npx repomix --include "src//*,tests//*"
undefined

Ignore Patterns

忽略规则

bash
undefined
bash
undefined

Ignore 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"
undefined
npx repomix --include "src//*.ts" --ignore "/*.test.ts"
undefined

Stdin Input

标准输入(Stdin)

bash
undefined
bash
undefined

From 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
undefined
rg --files --type ts | npx repomix --stdin
undefined

Common Workflows

常见工作流

PR Review Preparation

PR审查准备

bash
undefined
bash
undefined

Pack 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
undefined
npx repomix --include-diffs --compress
undefined

Architecture Analysis

架构分析

bash
undefined
bash
undefined

Pack 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
undefined
npx repomix --include "src/api//*,src/services//*" --compress
undefined

Documentation Generation

文档生成

bash
undefined
bash
undefined

Pack 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
undefined
npx repomix --include-logs --include-logs-count 50
undefined

Dependency Analysis

依赖分析

bash
undefined
bash
undefined

Pack only config and dependency files

仅打包配置与依赖文件

npx repomix --include "package.json,tsconfig.json,**/.config."
undefined
npx repomix --include "package.json,tsconfig.json,**/.config."
undefined

Remote Repositories

远程代码库

bash
undefined
bash
undefined

Pack 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格式

Code 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 --compress
bash
npx repomix --compress

Combine 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
undefined
bash
undefined

Include 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
undefined
npx repomix --include-logs --include-diffs
undefined

Configuration

配置

Initialize Config

初始化配置

bash
undefined
bash
undefined

Create repomix.config.json

创建repomix.config.json配置文件

npx repomix --init
npx repomix --init

Global config

全局配置

npx repomix --init --global
undefined
npx repomix --init --global
undefined

Configuration 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
undefined
bash
undefined

Pack 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
undefined
docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote user/repo
undefined

MCP Server Integration

MCP服务器集成

Run as Model Context Protocol server for AI assistants:
bash
npx repomix --mcp
作为模型上下文协议(Model Context Protocol, MCP)服务器运行,供AI助手使用:
bash
npx repomix --mcp

Configure for Claude Code

配置Claude Code

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

Available MCP Tools

可用MCP工具

When running as MCP server, provides:
ToolDescription
pack_codebase
Pack local directory into AI-friendly format
pack_remote_repository
Pack GitHub repository without cloning
read_repomix_output
Read contents of generated output file
file_system_tree
Get directory tree structure
作为MCP服务器运行时,提供以下工具:
工具描述
pack_codebase
将本地目录打包为适合AI的格式
pack_remote_repository
无需克隆即可打包GitHub代码库
read_repomix_output
读取生成的输出文件内容
file_system_tree
获取目录树形结构

Claude Agent Skills Generation

Claude Agent技能生成

Generate skills format output for Claude:
bash
undefined
生成适合Claude使用的技能格式输出:
bash
undefined

Generate 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
undefined
npx repomix --remote user/repo --skill-generate
undefined

CLI Options Reference

CLI选项参考

OptionDescription
-o, --output <file>
Output file path
--style <style>
Output format: xml, markdown, json, plain
--compress
Enable Tree-sitter compression
--include <patterns>
Include files matching glob patterns
-i, --ignore <patterns>
Exclude files matching patterns
--remote <url>
Process remote repository
--remote-branch <name>
Branch, tag, or commit for remote
--stdin
Read file paths from stdin
--copy
Copy output to clipboard
--token-count-tree
Show token counts per file
--split-output <size>
Split output by size (e.g., 1mb)
--include-logs
Include git commit history
--include-diffs
Include git diffs
--no-security-check
Skip sensitive data detection
--mcp
Run as MCP server
--skill-generate
Generate Claude skills format
--init
Create configuration file
--help
Show all available options
选项描述
-o, --output <file>
输出文件路径
--style <style>
输出格式:xml、markdown、json、plain
--compress
启用Tree-sitter压缩
--include <patterns>
包含匹配通配符规则的文件
-i, --ignore <patterns>
排除匹配规则的文件
--remote <url>
处理远程代码库
--remote-branch <name>
远程代码库的分支、标签或提交记录
--stdin
从标准输入读取文件路径
--copy
将输出复制到剪贴板
--token-count-tree
显示每个文件的令牌数量
--split-output <size>
按大小拆分输出(例如:1mb)
--include-logs
包含Git提交历史
--include-diffs
包含Git差异
--no-security-check
跳过敏感数据检测
--mcp
以MCP服务器模式运行
--skill-generate
生成Claude技能格式输出
--init
创建配置文件
--help
显示所有可用选项

Troubleshooting

故障排除

IssueSolution
Output too large for LLMUse
--compress
or filter with
--include
Missing expected filesCheck
.repomixignore
,
.gitignore
, and ignore patterns
Secrets detected (blocking)Review flagged files; use
--no-security-check
if false positive
Memory issues on large reposUse
--split-output 1mb
to chunk output
Remote repo access deniedCheck URL format; ensure repo is public or use SSH
Compression not workingVerify language is supported by Tree-sitter
Output not in clipboardEnsure clipboard access; try
--output - | pbcopy
on macOS
问题解决方案
输出结果超出LLM上下文限制使用
--compress
参数,或通过
--include
过滤文件
缺少预期文件检查
.repomixignore
.gitignore
及忽略规则
检测到敏感信息(被阻止)检查标记的文件;若为误报,可使用
--no-security-check
参数
处理大型代码库时出现内存问题使用
--split-output 1mb
参数拆分输出
远程代码库访问被拒绝检查URL格式;确保代码库为公开,或使用SSH认证
压缩功能无效确认语言是否受Tree-sitter支持
输出未复制到剪贴板确保剪贴板权限正常;macOS可尝试
--output - | pbcopy

Ignore Files

忽略文件优先级

Repomix respects multiple ignore sources (priority order):
  1. ignore.customPatterns
    in config
  2. .repomixignore
    (Repomix-specific)
  3. .ignore
    (ripgrep compatible)
  4. .gitignore
  5. Default patterns (node_modules, .git, etc.)
Repomix会遵循多种忽略规则,优先级从高到低为:
  1. 配置文件中的
    ignore.customPatterns
  2. .repomixignore
    (Repomix专属忽略文件)
  3. .ignore
    (兼容ripgrep格式)
  4. .gitignore
  5. 默认忽略规则(如node_modules、.git等)

Security

安全特性

Repomix includes Secretlint for detecting sensitive information:
bash
undefined
Repomix集成了Secretlint工具用于检测敏感信息:
bash
undefined

Security 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

最佳实践

  1. Use compression for large codebases to reduce token count (~70% reduction)
  2. Filter with --include to focus on relevant files
  3. Use --token-count-tree to identify large files before packing
  4. Split output when hitting AI context limits
  5. Include git logs for evolution context when needed
  6. Use XML style for Claude (optimized for XML tags)
  7. Use Markdown for human-readable output or other LLMs
  8. Check token counts against your target LLM's context window
  9. Review security warnings before sharing packed output
  1. 启用压缩:处理大型代码库时使用
    --compress
    参数,可减少约70%的令牌数量
  2. 过滤文件:使用
    --include
    参数聚焦相关文件,避免冗余内容
  3. 预检查令牌数量:使用
    --token-count-tree
    参数识别大型文件后再打包
  4. 拆分输出:当超出AI上下文限制时,使用
    --split-output
    参数拆分结果
  5. 按需包含Git日志:需要代码演进上下文时,添加
    --include-logs
    参数
  6. Claude适配:使用XML格式输出,适配Claude的XML标签优化处理
  7. 人类阅读适配:使用Markdown格式输出,便于人类阅读或其他LLM使用
  8. 匹配上下文窗口:根据目标LLM的上下文窗口检查令牌数量
  9. 安全审查:分享打包结果前,务必检查安全警告

Requirements

环境要求

  • Node.js 18.0.0 or higher
  • npm or npx available in PATH
  • Node.js 18.0.0或更高版本
  • 系统PATH中包含npm或npx

Resources

相关资源