repomix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Repomix Skill

Repomix 技能

Repomix is a powerful tool that packs entire repositories into single, AI-friendly files. Perfect for when you need to feed codebases to Large Language Models (LLMs) or other AI tools like Claude, ChatGPT, and Gemini.
Repomix 是一款强大的工具,可将整个代码仓库打包为单个适配AI的文件。非常适合需要将代码库提交给大语言模型(LLM)或Claude、ChatGPT、Gemini等其他AI工具的场景。

When to Use This Skill

适用场景

Use this skill when:
  • User needs to package a codebase for AI analysis
  • Preparing repository context for LLM consumption
  • Generating codebase snapshots for documentation
  • Analyzing third-party libraries or repositories
  • Creating AI-friendly representations of code projects
  • Investigating bugs across large codebases
  • Performing security audits on repositories
  • Generating context for implementation planning
在以下场景使用本技能:
  • 用户需要为AI分析打包代码库
  • 为LLM准备仓库上下文
  • 生成代码库快照用于文档编制
  • 分析第三方库或代码仓库
  • 创建代码项目的AI友好型表示
  • 排查大型代码库中的Bug
  • 对代码仓库执行安全审计
  • 为实现规划生成上下文

Core Capabilities

核心功能

1. Repository Packaging

1. 代码仓库打包

Repomix packages entire repositories into single files with:
  • AI-optimized formatting with clear separators
  • Multiple output formats (XML, Markdown, JSON, Plain text)
  • Git-aware processing (respects .gitignore)
  • Token counting for LLM context management
  • Security checks for sensitive information
Repomix 可将整个代码仓库打包为单个文件,具备以下特性:
  • 采用AI优化格式,带有清晰分隔符
  • 支持多种输出格式(XML、Markdown、JSON、纯文本)
  • 感知Git的处理逻辑(遵循.gitignore规则)
  • 用于LLM上下文管理的Token计数
  • 敏感信息安全检查

2. Remote Repository Support

2. 远程仓库支持

Can process remote repositories without cloning:
  • Shorthand:
    npx repomix --remote yamadashy/repomix
  • Full URL:
    npx repomix --remote https://github.com/owner/repo
  • Specific commits:
    npx repomix --remote https://github.com/owner/repo/commit/hash
无需克隆即可处理远程仓库:
  • 简写格式:
    npx repomix --remote yamadashy/repomix
  • 完整URL:
    npx repomix --remote https://github.com/owner/repo
  • 指定提交版本:
    npx repomix --remote https://github.com/owner/repo/commit/hash

3. Comment Removal

3. 注释移除

Strips comments from supported languages when needed:
  • Supported: HTML, CSS, JavaScript, TypeScript, Vue, Svelte, Python, PHP, Ruby, C, C#, Java, Go, Rust, Swift, Kotlin, Dart, Shell, YAML
  • Enable with:
    --remove-comments
    or config file
可按需移除支持语言的注释:
  • 支持语言:HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell、YAML
  • 启用方式:
    --remove-comments
    参数或配置文件

Installation

安装

Check if installed first:
bash
repomix --version
Install using preferred method:
bash
undefined
先检查是否已安装:
bash
repomix --version
通过以下方式安装:
bash
undefined

npm

npm

npm install -g repomix
npm install -g repomix

yarn

yarn

yarn global add repomix
yarn global add repomix

bun

bun

bun add -g repomix
bun add -g repomix

Homebrew (macOS/Linux)

Homebrew(macOS/Linux)

brew install repomix
undefined
brew install repomix
undefined

Basic Usage

基础用法

Package Current Directory

打包当前目录

bash
undefined
bash
undefined

Basic packaging (generates repomix-output.xml)

基础打包(生成repomix-output.xml)

repomix
repomix

Specify output format

指定输出格式

repomix --style markdown repomix --style json repomix --style plain
repomix --style markdown repomix --style json repomix --style plain

Custom output path

自定义输出路径

repomix -o custom-output.xml
undefined
repomix -o custom-output.xml
undefined

Package Specific Directory

打包指定目录

bash
repomix /path/to/directory
bash
repomix /path/to/directory

Package Remote Repository

打包远程仓库

bash
undefined
bash
undefined

Shorthand format

简写格式

npx repomix --remote owner/repo
npx repomix --remote owner/repo

Full URL

完整URL

npx repomix --remote https://github.com/owner/repo
npx repomix --remote https://github.com/owner/repo

Specific commit

指定提交版本

undefined
undefined

Command Line Options

命令行选项

File Selection

文件选择

bash
undefined
bash
undefined

Include specific patterns

包含特定模式的文件

repomix --include "src/**/.ts,.md"
repomix --include "src/**/.ts,.md"

Ignore additional patterns

忽略额外模式的文件

repomix -i "tests/**,*.test.js"
repomix -i "tests/**,*.test.js"

Disable .gitignore rules

禁用.gitignore规则

repomix --no-gitignore
repomix --no-gitignore

Disable default ignore patterns

禁用默认忽略模式

repomix --no-default-patterns
undefined
repomix --no-default-patterns
undefined

Output Configuration

输出配置

bash
undefined
bash
undefined

Output format

输出格式

repomix --style markdown # or xml, json, plain
repomix --style markdown # 或 xml, json, plain

Output file path

输出文件路径

repomix -o output.md
repomix -o output.md

Remove comments

移除注释

repomix --remove-comments
repomix --remove-comments

Show line numbers

隐藏行号

repomix --no-line-numbers # disable line numbers
undefined
repomix --no-line-numbers # 禁用行号显示
undefined

Security & Analysis

安全与分析

bash
undefined
bash
undefined

Run security checks

运行安全检查

repomix --no-security-check # disable security scanning
repomix --no-security-check # 禁用安全扫描

Copy to clipboard

复制到剪贴板

repomix --copy # copy output to clipboard
repomix --copy # 将输出复制到剪贴板

Verbose output

详细输出

repomix --verbose
undefined
repomix --verbose
undefined

Configuration

配置

bash
undefined
bash
undefined

Use custom config file

使用自定义配置文件

repomix -c custom-config.json
repomix -c custom-config.json

Initialize new config

初始化新配置

repomix --init # creates repomix.config.json
undefined
repomix --init # 创建repomix.config.json
undefined

Configuration File

配置文件

Create
repomix.config.json
in project root:
json
{
  "output": {
    "filePath": "repomix-output.xml",
    "style": "xml",
    "removeComments": false,
    "showLineNumbers": true,
    "copyToClipboard": false
  },
  "include": ["**/*"],
  "ignore": {
    "useGitignore": true,
    "useDefaultPatterns": true,
    "customPatterns": [
      "additional-folder",
      "**/*.log",
      "**/tmp/**"
    ]
  },
  "security": {
    "enableSecurityCheck": true
  }
}
在项目根目录创建
repomix.config.json
json
{
  "output": {
    "filePath": "repomix-output.xml",
    "style": "xml",
    "removeComments": false,
    "showLineNumbers": true,
    "copyToClipboard": false
  },
  "include": ["**/*"],
  "ignore": {
    "useGitignore": true,
    "useDefaultPatterns": true,
    "customPatterns": [
      "additional-folder",
      "**/*.log",
      "**/tmp/**"
    ]
  },
  "security": {
    "enableSecurityCheck": true
  }
}

Ignore Patterns

忽略模式

.repomixignore File

.repomixignore 文件

Create
.repomixignore
for Repomix-specific ignore patterns (same format as .gitignore):
undefined
创建
.repomixignore
文件定义Repomix专属忽略模式(格式与.gitignore相同):
undefined

Build artifacts

构建产物

dist/ build/ *.min.js
dist/ build/ *.min.js

Test files

测试文件

**/.test.ts **/.spec.ts coverage/
**/.test.ts **/.spec.ts coverage/

Large files

大文件

*.mp4 *.zip
*.mp4 *.zip

Sensitive files

敏感文件

.env* secrets/
undefined
.env* secrets/
undefined

Precedence Order

优先级顺序

  1. CLI ignore patterns (
    -i
    flag)
  2. .repomixignore
    file
  3. Custom patterns in config file
  4. .gitignore
    file (if enabled)
  5. Default patterns (if enabled)
  1. 命令行忽略模式(
    -i
    参数)
  2. .repomixignore
    文件
  3. 配置文件中的自定义模式
  4. .gitignore
    文件(若启用)
  5. 默认忽略模式(若启用)

Output Formats

输出格式

XML Format (Default)

XML格式(默认)

Best for structured AI consumption:
bash
repomix --style xml
最适合结构化AI处理:
bash
repomix --style xml

Markdown Format

Markdown格式

Human-readable with syntax highlighting:
bash
repomix --style markdown
人类可读,支持语法高亮:
bash
repomix --style markdown

JSON Format

JSON格式

For programmatic processing:
bash
repomix --style json
适合程序化处理:
bash
repomix --style json

Plain Text

纯文本

Simple concatenation:
bash
repomix --style plain
简单拼接格式:
bash
repomix --style plain

Use Cases & Examples

用例与示例

1. Code Review Preparation

1. 代码审查准备

bash
undefined
bash
undefined

Package feature branch for AI review

打包功能分支用于AI审查

repomix --include "src/**/*.ts" --remove-comments -o feature-review.md --style markdown
undefined
repomix --include "src/**/*.ts" --remove-comments -o feature-review.md --style markdown
undefined

2. Security Audit

2. 安全审计

bash
undefined
bash
undefined

Package third-party library for analysis

打包第三方库用于分析

npx repomix --remote vendor/library --style xml -o audit.xml
undefined
npx repomix --remote vendor/library --style xml -o audit.xml
undefined

3. Documentation Generation

3. 文档生成

bash
undefined
bash
undefined

Package with docs and code

打包文档与代码

repomix --include "src/,docs/,*.md" --style markdown -o context.md
undefined
repomix --include "src/,docs/,*.md" --style markdown -o context.md
undefined

4. Bug Investigation

4. Bug排查

bash
undefined
bash
undefined

Package specific modules

打包特定模块

repomix --include "src/auth/,src/api/" -o debug-context.xml
undefined
repomix --include "src/auth/,src/api/" -o debug-context.xml
undefined

5. Implementation Planning

5. 实现规划

bash
undefined
bash
undefined

Full codebase context for planning

生成完整代码库上下文用于规划

repomix --remove-comments --copy
undefined
repomix --remove-comments --copy
undefined

Token Management

Token管理

Repomix automatically counts tokens for:
  • Individual files
  • Total repository
  • Per-format output
Use token counts to manage LLM context limits:
  • Claude: ~200K tokens
  • GPT-4: ~128K tokens
  • GPT-3.5: ~16K tokens
Repomix 自动为以下内容计数Token:
  • 单个文件
  • 整个仓库
  • 各格式输出内容
利用Token计数管理LLM上下文限制:
  • Claude:约200K Token
  • GPT-4:约128K Token
  • GPT-3.5:约16K Token

Security Considerations

安全注意事项

Sensitive Data Detection

敏感数据检测

Repomix uses Secretlint to detect:
  • API keys and tokens
  • Passwords and credentials
  • Private keys
  • AWS secrets
  • Database connection strings
Disable if needed:
bash
repomix --no-security-check
Repomix 使用Secretlint检测以下内容:
  • API密钥与令牌
  • 密码与凭证
  • 私钥
  • AWS密钥
  • 数据库连接字符串
按需禁用:
bash
repomix --no-security-check

Best Practices

最佳实践

  1. Always review output before sharing
  2. Use
    .repomixignore
    for sensitive files
  3. Enable security checks for unknown codebases
  4. Avoid packaging
    .env
    files
  5. Check for hardcoded credentials
  1. 分享前务必检查输出内容
  2. 使用
    .repomixignore
    忽略敏感文件
  3. 对未知代码库启用安全检查
  4. 避免打包
    .env
    文件
  5. 检查是否存在硬编码凭证

Performance Optimization

性能优化

Large Repositories

大型仓库

Repomix uses worker threads for parallel processing:
  • Efficiently handles large codebases
  • Example: facebook/react processed 29x faster (123s → 4s)
Repomix 使用工作线程并行处理:
  • 高效处理大型代码库
  • 示例:facebook/react 处理速度提升29倍(123秒 → 4秒)

Optimization Tips

优化技巧

bash
undefined
bash
undefined

Exclude unnecessary files

排除不必要的文件

repomix -i "node_modules/,dist/,*.min.js"
repomix -i "node_modules/,dist/,*.min.js"

Process specific directories only

仅处理指定目录

repomix --include "src/**/*.ts"
repomix --include "src/**/*.ts"

Disable line numbers for smaller output

禁用行号以减小输出体积

repomix --no-line-numbers
undefined
repomix --no-line-numbers
undefined

Workflow Integration

工作流集成

With Claude Code

与Claude Code集成

bash
undefined
bash
undefined

Package and analyze in one workflow

一键打包并分析

repomix --style markdown --copy
repomix --style markdown --copy

Then paste into Claude for analysis

然后粘贴到Claude中进行分析

undefined
undefined

With CI/CD

与CI/CD集成

bash
undefined
bash
undefined

Generate codebase snapshot for releases

为版本发布生成代码库快照

repomix --style markdown -o release-snapshot.md
undefined
repomix --style markdown -o release-snapshot.md
undefined

With Git Hooks

与Git钩子集成

bash
undefined
bash
undefined

Pre-commit hook to generate context

预提交钩子生成上下文

repomix --include "src/**" -o .context/latest.xml
undefined
repomix --include "src/**" -o .context/latest.xml
undefined

Common Patterns

常见模式

Full Repository Package

完整仓库打包

bash
repomix --remove-comments --style markdown -o full-repo.md
bash
repomix --remove-comments --style markdown -o full-repo.md

Source Code Only

仅源代码

bash
repomix --include "src/**/*.{ts,tsx,js,jsx}" -i "**/*.test.*"
bash
repomix --include "src/**/*.{ts,tsx,js,jsx}" -i "**/*.test.*"

Documentation Bundle

文档打包

bash
repomix --include "**/*.md,docs/**" --style markdown
bash
repomix --include "**/*.md,docs/**" --style markdown

TypeScript Project

TypeScript项目

bash
repomix --include "**/*.ts,**/*.tsx" --remove-comments --no-line-numbers
bash
repomix --include "**/*.ts,**/*.tsx" --remove-comments --no-line-numbers

Remote Analysis

远程分析

bash
npx repomix --remote owner/repo --style xml -o analysis.xml
bash
npx repomix --remote owner/repo --style xml -o analysis.xml

Troubleshooting

故障排除

Issue: Output Too Large

问题:输出体积过大

bash
undefined
bash
undefined

Exclude unnecessary files

排除不必要的文件

repomix -i "node_modules/,dist/,coverage/**"
repomix -i "node_modules/,dist/,coverage/**"

Process specific directories

仅处理指定目录

repomix --include "src/**"
undefined
repomix --include "src/**"
undefined

Issue: Missing Files

问题:文件缺失

bash
undefined
bash
undefined

Disable .gitignore rules

禁用.gitignore规则

repomix --no-gitignore
repomix --no-gitignore

Check ignore patterns

检查忽略模式

cat .repomixignore
undefined
cat .repomixignore
undefined

Issue: Sensitive Data Warnings

问题:敏感数据警告

bash
undefined
bash
undefined

Review flagged files

检查标记的文件

Add to .repomixignore

添加到.repomixignore

Or disable checks: --no-security-check

或禁用检查:--no-security-check

undefined
undefined

Implementation Workflow

实现工作流

When user requests repository packaging:
  1. Assess Requirements
    • Identify target repository (local/remote)
    • Determine output format needed
    • Check for sensitive data concerns
  2. Configure Filters
    • Set include patterns for relevant files
    • Add ignore patterns for unnecessary files
    • Enable/disable comment removal
  3. Execute Packaging
    • Run repomix with appropriate options
    • Monitor token counts
    • Verify security checks
  4. Validate Output
    • Review generated file
    • Confirm no sensitive data
    • Check token limits for target LLM
  5. Deliver Context
    • Provide packaged file to user
    • Include token count summary
    • Note any warnings or issues
当用户请求仓库打包时:
  1. 评估需求
    • 确定目标仓库(本地/远程)
    • 确认所需输出格式
    • 检查敏感数据风险
  2. 配置过滤规则
    • 设置需包含的文件模式
    • 添加需忽略的文件模式
    • 启用/禁用注释移除
  3. 执行打包
    • 使用合适参数运行repomix
    • 监控Token计数
    • 验证安全检查结果
  4. 验证输出
    • 检查生成的文件
    • 确认无敏感数据
    • 检查是否符合目标LLM的Token限制
  5. 交付上下文
    • 向用户提供打包文件
    • 包含Token计数摘要
    • 标注警告或问题

Best Practices

最佳实践

  1. Start with defaults: Run basic
    repomix
    first, then refine
  2. Use .repomixignore: Better than CLI flags for complex patterns
  3. Enable security checks: Especially for third-party code
  4. Choose right format: XML for AI, Markdown for humans
  5. Monitor token counts: Stay within LLM limits
  6. Remove comments: When focusing on logic over documentation
  7. Version output: Include in .gitignore, regenerate as needed
  8. Test patterns: Verify include/exclude work as expected
  1. 从默认配置开始:先运行基础
    repomix
    命令,再逐步优化
  2. 使用.repomixignore:复杂模式优先用文件而非命令行参数
  3. 启用安全检查:尤其是处理第三方代码时
  4. 选择合适格式:XML适合AI,Markdown适合人类阅读
  5. 监控Token计数:确保在LLM限制范围内
  6. 移除注释:专注代码逻辑而非文档时启用
  7. 版本化输出:将输出文件加入.gitignore,按需重新生成
  8. 测试规则:验证包含/排除模式是否符合预期

Related Tools

相关工具

  • Context7: For up-to-date library documentation
  • Git: For repository history analysis
  • Secretlint: For security scanning
  • Token counters: For LLM context management
  • Context7:用于获取最新库文档
  • Git:用于仓库历史分析
  • Secretlint:用于安全扫描
  • Token计数器:用于LLM上下文管理

Additional Resources

额外资源