关于 repomix
repomix 是面向 Agent 的仓库打包技能,可将本地或远程仓库整理为供大模型分析的上下文文件。它支持筛选文件、统计 Token,并提供敏感信息检查。
主要功能
- 01打包本地和远程仓库
- 02导出 XML、Markdown、JSON 或纯文本
- 03通过包含与忽略规则筛选文件
- 04统计 Token 并扫描敏感信息
- 05移除受支持语言中的注释
适用场景
- 01为 AI 审查或规划准备代码库
- 02调查特定模块中的错误
- 03生成用于文档的仓库快照
- 04审计第三方仓库
MCP 相关
README 提到可通过 MCP 服务集成 AI 助手。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ samhvw8/ dotfiles --skill repomix安装后在 Claude Code 中输入/repomix确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/configuration.mdusage-patterns.mdscripts/dot_coverageREADME.mdrepomix_batch.pyrepos.example.jsonrequirements.txtscripts/tests/test_repomix_batch.py详细介绍
Repomix 技能
Repomix 是一款强大的工具,可将整个代码库打包成单个适合 AI 使用的文件。非常适合将代码库提供给大语言模型(LLM)或 Claude、ChatGPT 和 Gemini 等其他 AI 工具。
何时使用此技能
在以下情况下使用此技能:
- 用户需要为 AI 分析打包代码库
- 为大模型准备代码库上下文
- 生成用于文档编写的代码库快照
- 分析第三方库或代码库
- 创建适合 AI 使用的代码项目表示
- 调查大型代码库中的错误
- 对代码库进行安全审计
- 为实现规划生成上下文
核心功能
1. 代码库打包
Repomix 可将整个代码库打包成单个文件,支持:
- 采用清晰分隔符的 AI 优化格式
- 多种输出格式(XML、Markdown、JSON、纯文本)
- 识别 Git 的处理方式(遵循 .gitignore)
- 统计 Token 数量,便于管理大模型上下文
- 检查敏感信息
2. 远程代码库支持
无需克隆即可处理远程代码库:
- 简写形式:
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. 移除注释
需要时,可从支持的语言中移除注释:
- 支持:HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell、YAML
- 使用
--remove-comments或配置文件启用
安装
首先检查是否已安装:
repomix --version
使用首选方法安装:
# npm
npm install -g repomix
# yarn
yarn global add repomix
# bun
bun add -g repomix
# Homebrew (macOS/Linux)
brew install repomix
基本用法
打包当前目录
# Basic packaging (generates repomix-output.xml)
repomix
# Specify output format
repomix --style markdown
repomix --style json
repomix --style plain
# Custom output path
repomix -o custom-output.xml
打包指定目录
repomix /path/to/directory
打包远程代码库
# Shorthand format
npx repomix --remote owner/repo
# Full URL
npx repomix --remote https://github.com/owner/repo
# Specific commit
npx repomix --remote https://github.com/owner/repo/commit/abc123
命令行选项
文件选择
# Include specific patterns
repomix --include "src/**/*.ts,*.md"
# Ignore additional patterns
repomix -i "tests/**,*.test.js"
# Disable .gitignore rules
repomix --no-gitignore
# Disable default ignore patterns
repomix --no-default-patterns
输出配置
# Output format
repomix --style markdown # or xml, json, plain
# Output file path
repomix -o output.md
# Remove comments
repomix --remove-comments
# Show line numbers
repomix --no-line-numbers # disable line numbers
安全与分析
# Run security checks
repomix --no-security-check # disable security scanning
# Copy to clipboard
repomix --copy # copy output to clipboard
# Verbose output
repomix --verbose
配置
# Use custom config file
repomix -c custom-config.json
# Initialize new config
repomix --init # creates repomix.config.json
配置文件
在项目根目录中创建 repomix.config.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
}
}
忽略模式
.repomixignore 文件
创建 .repomixignore,配置 Repomix 专用忽略模式(格式与 .gitignore 相同):
# Build artifacts
dist/
build/
*.min.js
# Test files
**/*.test.ts
**/*.spec.ts
coverage/
# Large files
*.mp4
*.zip
# Sensitive files
.env*
secrets/
优先级顺序
- CLI 忽略模式(
-i标志) .repomixignore文件- 配置文件中的自定义模式
.gitignore文件(如果启用)- 默认模式(如果启用)
输出格式
XML 格式(默认)
最适合以结构化形式供 AI 使用:
repomix --style xml
Markdown 格式
便于阅读,并支持语法高亮:
repomix --style markdown
JSON 格式
用于程序化处理:
repomix --style json
纯文本
简单拼接:
repomix --style plain
使用场景与示例
1. 代码审查准备
# Package feature branch for AI review
repomix --include "src/**/*.ts" --remove-comments -o feature-review.md --style markdown
2. 安全审计
# Package third-party library for analysis
npx repomix --remote vendor/library --style xml -o audit.xml
3. 生成文档
# Package with docs and code
repomix --include "src/**,docs/**,*.md" --style markdown -o context.md
4. 错误调查
# Package specific modules
repomix --include "src/auth/**,src/api/**" -o debug-context.xml
5. 实现规划
# Full codebase context for planning
repomix --remove-comments --copy
Token 管理
Repomix 会自动统计以下内容的 Token 数量:
- 单个文件
- 整个代码库
- 各种格式的输出
使用 Token 数量管理大模型上下文限制:
- Claude:约 200K 个 Token
- GPT-4:约 128K 个 Token
- GPT-3.5:约 16K 个 Token
安全注意事项
敏感数据检测
Repomix 使用 Secretlint 检测:
- API 密钥和 Token
- 密码和凭据
- 私钥
- AWS 密钥
- 数据库连接字符串
如有需要,可禁用:
repomix --no-security-check
最佳实践
- 分享前务必检查输出
- 使用
.repomixignore忽略敏感文件 - 对未知代码库启用安全检查
- 避免打包
.env文件 - 检查是否存在硬编码凭据
性能优化
大型代码库
Repomix 使用工作线程进行并行处理:
- 高效处理大型代码库
- 示例:处理 facebook/react 的速度快了 29 倍(123s → 4s)
优化提示
# Exclude unnecessary files
repomix -i "node_modules/**,dist/**,*.min.js"
# Process specific directories only
repomix --include "src/**/*.ts"
# Disable line numbers for smaller output
repomix --no-line-numbers
工作流集成
与 Claude Code 配合使用
# Package and analyze in one workflow
repomix --style markdown --copy
# Then paste into Claude for analysis
与 CI/CD 配合使用
# Generate codebase snapshot for releases
repomix --style markdown -o release-snapshot.md
与 Git Hooks 配合使用
# Pre-commit hook to generate context
repomix --include "src/**" -o .context/latest.xml
常见模式
完整代码库打包
repomix --remove-comments --style markdown -o full-repo.md
仅源代码
repomix --include "src/**/*.{ts,tsx,js,jsx}" -i "**/*.test.*"
文档包
repomix --include "**/*.md,docs/**" --style markdown
TypeScript 项目
repomix --include "**/*.ts,**/*.tsx" --remove-comments --no-line-numbers
远程分析
npx repomix --remote owner/repo --style xml -o analysis.xml
故障排除
问题:输出过大
# Exclude unnecessary files
repomix -i "node_modules/**,dist/**,coverage/**"
# Process specific directories
repomix --include "src/**"
问题:缺少文件
# Disable .gitignore rules
repomix --no-gitignore
# Check ignore patterns
cat .repomixignore
问题:敏感数据警告
# Review flagged files
# Add to .repomixignore
# Or disable checks: --no-security-check
实施工作流
用户请求打包代码仓库时:
-
评估需求
- 确定目标代码仓库(本地/远程)
- 确定所需的输出格式
- 检查敏感数据相关问题
-
配置筛选器
- 为相关文件设置包含模式
- 为不需要的文件添加忽略模式
- 启用/禁用注释移除
-
执行打包
- 使用适当的选项运行 repomix
- 监控令牌数
- 验证安全检查
-
验证输出
- 检查生成的文件
- 确认不含敏感数据
- 检查是否符合目标大模型的令牌限制
-
交付上下文
- 向用户提供打包后的文件
- 附上令牌数摘要
- 说明任何警告或问题
最佳实践
- 从默认设置开始:先运行基本的
repomix,再进行调整 - 使用 .repomixignore:对于复杂模式,它比 CLI 标志更合适
- 启用安全检查:尤其是针对第三方代码
- 选择合适的格式:面向 AI 使用 XML,面向人类使用 Markdown
- 监控令牌数:确保不超过大模型的限制
- 移除注释:当重点在于逻辑而非文档时
- 对输出进行版本管理:将其加入 .gitignore,并根据需要重新生成
- 测试模式:验证包含/排除规则是否按预期工作
相关工具
- Context7:获取最新的库文档
- Git:分析代码仓库历史
- Secretlint:进行安全扫描
- 令牌计数器:管理大模型上下文
更多资源
- GitHub:https://github.com/yamadashy/repomix
- 文档:https://repomix.com/guide/
- MCP Server:可用于与 AI 助手集成
- Claude Code Plugin:提供官方集成
评论
支持 Markdown