其他
需要把本地或远程代码仓库打包成单个 AI/LLM…
当需要为 LLM 分析、代码审查、安全审计、文档生成、第三方库评估或跨大仓库排查 bug 准备代码库上下文时,将仓库打包成 XML/Markdown/JSON/纯文本单文件并控制 token 与敏感信息。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 35/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 39/100 ×0.15
适用场景
需要把本地或远程代码仓库打包成单个 AI特定
解决思路
- 检查是否已安装:`repomix --version`。
- 如未安装,用 npm 全局安装:`npm install -g repomix`。
- 如未安装,在 macOS/Linux 用 Homebrew 安装:`brew install repomix`。
- 打包当前目录,默认生成 `repomix-output.xml`:`repomix`。
- 指定输出格式为 Markdown:`repomix --style markdown`。
- 指定输出格式为 JSON:`repomix --style json`。
- 打包远程仓库(简写):`npx repomix --remote owner/repo`。
- 用过滤器自定义输出并移除注释:`repomix --include "src/**/*.ts" --remove-comments -o output.md`。
- 执行仓库打包时,使用 AI 优化格式和清晰分隔符;可选择 XML、Markdown、JSON、纯文本输出;处理时遵循 `.gitignore`;统计 token;执行安全检查。
- 打包远程仓库(简写示例):`npx repomix --remote yamadashy/repomix`。
- 打包远程仓库(完整 URL):`npx repomix --remote https://github.com/owner/repo`。
- 打包远程仓库的指定 commit:`npx repomix --remote https://github.com/owner/repo/commit/hash`。
- 移除支持语言的注释(HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell、YAML):`repomix --remove-comments`。
- 代码审查准备:`repomix --include "src/**/*.ts" --remove-comments -o review.md --style markdown`。
- 安全审计:`npx repomix --remote vendor/library --style xml -o audit.xml`。
- 文档生成:`repomix --include "src/**,docs/**,*.md" --style markdown -o context.md`。
- Bug 调查:`repomix --include "src/auth/**,src/api/**" -o debug-context.xml`。
- 实施规划:`repomix --remove-comments --copy`。
- 文件选择:包含特定模式:`repomix --include "src/**/*.ts,*.md"`。
- 文件选择:忽略额外模式:`repomix -i "tests/**,*.test.js"`。
- 文件选择:禁用 `.gitignore` 规则:`repomix --no-gitignore`。
- 输出选项:输出格式可设为 `markdown`、`xml`、`json` 或 `plain`:`repomix --style markdown`。
- 输出选项:指定输出文件路径:`repomix -o output.md`。
- 输出选项:移除注释:`repomix --remove-comments`。
- 输出选项:复制到剪贴板:`repomix --copy`。
- 配置:使用自定义配置文件:`repomix -c custom-config.json`。
- 配置:初始化新配置,创建 `repomix.config.json`:`repomix --init`。
- Token 管理:Repomix 自动统计单个文件、整个仓库、每种格式输出的 token;对照典型 LLM 上下文限制:Claude Sonnet 4.5 约 200K tokens,GPT-4 约 128K tokens,GPT-3.5 约 16K tokens。
- 安全检查:Repomix 使用 Secretlint 检测敏感数据,包括 API keys、passwords、credentials、private keys、AWS secrets。
- 安全最佳实践:分享前始终审查输出。
- 安全最佳实践:使用 `.repomixignore` 排除敏感文件。
- 安全最佳实践:对未知代码库启用安全检查。
- 安全最佳实践:避免打包 `.env` 文件。
- 安全最佳实践:检查硬编码凭据。
- 如需禁用安全检查:`repomix --no-security-check`。
- 实施工作流-评估需求:确定目标仓库是本地还是远程;确定所需输出格式;检查敏感数据问题。
- 实施工作流-配置过滤器:设置 include 模式包含相关文件;添加 ignore 模式排除不必要文件;启用或禁用注释移除。
- 实施工作流-执行打包:用合适选项运行 repomix;监控 token 数量;验证安全检查。
- 实施工作流-验证输出:审查生成文件;确认无敏感数据;检查目标 LLM 的 token 限制。
- 实施工作流-交付上下文:把打包文件提供给用户;附上 token 统计摘要;说明任何警告或问题。
- 需要详细配置时,参阅 `./references/configuration.md`:配置文件、include/exclude 模式、输出格式、高级选项。
- 需要用法模式时,参阅 `./references/usage-patterns.md`:AI 分析工作流、安全审计准备、文档生成、库评估。
- 其他资源:GitHub `https://github.com/yamadashy/repomix`;文档 `https://repomix.com/guide/`;MCP Server 可用于 AI assistant 集成。
适用边界 · 注意事项
- 仓库包含未清理的敏感信息(API keys、密码、凭据、私钥、AWS secrets)时,不要分享或交付打包输出。
- 目标 LLM 的上下文 token 限制小于打包结果 token 数时,不要直接整仓打包,应先过滤或拆分。
- 只需查看少量文件或简单修改时,不必使用 Repomix 打包整个仓库。