
Repomix将整个代码库打包成 AI 友好的单一文件并与 Claude、ChatGPT、Gemini 等模型协同工作【免费下载链接】repomix Repomix is a powerful tool that packs your entire repository into a single, AI-friendly file. Perfect for when you need to feed your codebase to Large Language Models (LLMs) or other AI tools like Claude, ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok, and more.项目地址: https://gitcode.com/GitHub_Trending/rep/repomixRepomix 是一款将本地或远程仓库整体打包为 XML、Markdown、JSON 或纯文本单一文件的命令行工具输出结果专门面向大语言模型LLM与 AI 工具优化。本文以 西班牙语版首页文档 为主体结合仓库内 CLI 实现、配置模式、输出样式模板 等源码完整讲解 Repomix 的安装、命令行使用、输出格式、持久化配置、Docker 用法与高级能力帮助你在一分钟内把任意代码库喂给 AI 助手完成代码评审、重构、安全审计与文档生成。¿Qué es Repomix?什么是 RepomixRepomix 的核心价值在于无论你是在做代码评审、重构还是希望借助 AI 理解项目它都能把整个仓库的上下文以 AI 易于理解的结构化格式聚合到单个文件中让 AI 工具一次拿到全部代码无需逐文件探索。官方首页将它的能力归纳为四大特性见 es/index.md 的 features 字段面向 AI 优化Optimizado para IA输出格式经过设计便于 AI 理解与处理。对应仓库中的 outputGenerate.ts 与各输出样式模板。兼容 GitCompatibilidad con Git自动尊重你的.gitignore规则。文件收集阶段的实现见 fileSearch.ts。注重安全Enfocado en la seguridad内置 Secretlint 检测符合已知凭据格式的文件并将其排除在输出之外。核心逻辑位于 securityCheck.ts 与 securityCheckWorker.ts。Token 计数Conteo de tokens为每个文件及整个仓库提供 token 统计便于控制 LLM 的上下文窗口。实现见 TokenCounter.ts 与 calculateMetrics.ts。Inicio rápido快速开始把仓库喂给 AI使用 Repomix 生成打包文件repomix-output.xml之后就可以把它发送给 AI 助手如 ChatGPT、Claude配合类似下面的提示词Este archivo contiene todos los archivos del repositorio combinados en uno. Quiero refactorizar el código, así que por favor revísalo primero. 此文件包含仓库中的所有文件已合并为一个文件。我想重构代码请先审查它。AI 会分析你的整个代码库并给出全面的见解当讨论到具体改动时AI 还能协助生成代码。借助 Claude 的 Artifacts 等能力甚至可以一次返回多个相互依赖的文件为什么选择 RepomixRepomix 可以与 ChatGPT、Claude、Gemini、Grok 等任何订阅制服务配合使用无需担心额外的 API 成本。通过一次性提供完整代码上下文它消除了逐个浏览文件的成本让分析更快、通常也更准确。有了全部代码作为上下文Repomix 可以支撑多种用途实施规划、Bug 调查、第三方库安全审计、文档生成等。使用 CLI 工具Repomix 可以作为命令行工具使用提供强大的功能与定制选项。CLI 工具可以访问私有仓库因为它使用你本地安装的 Git。CLI 快速上手无需安装直接在项目目录中即时体验npx repomixlatest或者全局安装以便反复使用# 使用 npm 安装 npm install -g repomix # 或使用 yarn yarn global add repomix # 或使用 bun bun add -g repomix # 或使用 HomebrewmacOS/Linux brew install repomix # 然后在任意项目目录执行 repomix就这么简单Repomix 会在当前目录生成一个repomix-output.xml文件里面包含整个仓库的 AI 友好格式内容。基础用法打包整个仓库repomix打包指定目录repomix ruta/al/directorio使用 glob 模式打包特定文件或目录repomix --include src/**/*.ts,**/*.md排除特定文件或目录repomix --ignore **/*.log,tmp/打包远程仓库--remote的处理流程见 remoteAction.ts# 使用简写格式 npx repomix --remote yamadashy/repomix # 使用完整 URL支持指定分支和路径 npx repomix --remote https://github.com/yamadashy/repomix npx repomix --remote https://github.com/yamadashy/repomix/tree/main # 使用 commit 的 URL npx repomix --remote https://github.com/yamadashy/repomix/commit/836abcd7335137228ad77feb28655d85712680f1远程仓库的可用性探测依赖本机 Git从源码看gitRemoteHandle.ts 通过git ls-remote的 HEAD 探针execLsRemoteHead在不完整克隆的情况下快速确认仓库可达因此私有仓库也能借助本地 Git 凭据正常访问。初始化新的配置文件repomix.config.jsonrepomix --init--init会启动交互式向导见 initAction.ts询问是否创建repomix.config.json与.repomixignore并让你选择输出样式XML/Markdown/JSON/Plain与输出文件路径默认值来自 configSchema.ts 中的defaultFilePathMapxml 对应repomix-output.xml、markdown 对应repomix-output.md、plain 对应repomix-output.txt、json 对应repomix-output.json。此外还支持--global参数将配置写入用户主目录作为全局配置。生成打包文件后即可配合 Claude、ChatGPT、Gemini 等生成式 AI 工具使用。Docker 用法你也可以用 Docker 运行 Repomix适合希望隔离环境或偏好容器的场景。基础用法当前目录docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix打包指定目录docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix ruta/al/directorio处理远程仓库并把结果输出到output目录docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote https://github.com/yamadashy/repomix输出格式选择你偏好的输出格式# XML 格式默认 repomix --style xml # Markdown 格式 repomix --style markdown # JSON 格式 repomix --style json # 纯文本格式 repomix --style plain四种样式的取值范围定义在 configSchema.ts 的repomixOutputStyleSchema[xml, markdown, json, plain]中默认值为xml。以 XML 与 Markdown 为例最终输出由 Handlebars 模板渲染而成XML 模板见 xmlStyle.ts包含file_summary、directory_structure、files、git_diffs、git_logs、instruction等区块Markdown 模板见 markdownStyle.ts包含 File Summary、Directory Structure、Files、Git Diffs、Git Logs、Instruction 等小节JSON 与纯文本样式则分别位于 jsonStyle 对应测试 所覆盖的样式实现中。个性化定制创建repomix.config.json保存持久化设置{ output: { style: markdown, filePath: custom-output.md, removeComments: true, showLineNumbers: true, topFilesLength: 10 }, ignore: { customPatterns: [*.test.ts, docs/**] } }配置体系与默认值源码视角repomix.config.json的完整字段由 configSchema.ts 中的repomixConfigBaseSchema定义实际生效配置是默认值、文件配置与 CLI 配置三层叠加repomixConfigMergedSchema使用v.intersect合并。以下是源码确认的核心默认值配置路径默认值说明output.stylexml输出格式xml / markdown / json / plainoutput.filePathrepomix-output.xml按样式映射的默认输出文件名output.filePathStyletarget-relative输出中文件路径的展示方式可改为cwd-relativeoutput.fileSummarytrue是否包含文件摘要区块output.directoryStructuretrue是否包含目录结构树output.filestrue是否包含文件内容output.removeCommentsfalse是否移除代码注释output.removeEmptyLinesfalse是否移除空行output.compressfalse是否启用 Tree-sitter 智能压缩output.topFilesLength5摘要中列出最大的文件数量output.showLineNumbersfalse输出中是否显示行号output.truncateBase64false是否截断过长的 base64 数据output.includeFullDirectoryStructurefalse使用--include时是否展示完整仓库树output.git.sortByChangestrue是否按 Git 变更频率排序文件output.git.includeDiffs/includeLogsfalse是否包含 Git diff / 提交历史区块output.git.includeLogsCount50--include-logs包含的最近提交数input.maxFileSize50 MB单文件大小上限50 * 1024 * 1024字节ignore.useGitignore/useDotIgnore/useDefaultPatternstrue是否采用.gitignore、.ignore与内置默认忽略规则security.enableSecurityChecktrue默认开启安全扫描tokenCount.encodingo200k_baseToken 计数的编码模型忽略机制Repomix 的忽略策略共三层内置默认规则、.gitignore/.ignore文件、ignore.customPatterns。内置规则定义在 defaultIgnore.ts覆盖版本控制目录.git/**、.hg/**、依赖目录**/node_modules/**、vendor/**、构建产物dist/**、build/**、coverage/**、日志**/*.log、环境变量文件.env、锁文件package-lock.json、pnpm-lock.yaml、Cargo.lock等、编辑器目录.idea/**、.vscode/**以及 repomix 自身的输出**/repomix-output.*等防止输出文件中混入无关或敏感内容。安全扫描安全扫描默认开启security.enableSecurityCheck默认true。从 securityCheck.ts 可以看到扫描把每个文件以及可选的 Git diff、Git log 内容作为检测项按每批 50 条分组交由最多 2 个 worker 线程并发执行 Secretlint 检测命中的文件会被排除在输出之外。对远程仓库打包还有 filterOutUntrustedFiles.ts 做额外的可信度过滤。Token 计数与预算Repomix 会为每个文件与整个仓库统计 token 数量编码默认o200k_base对应 GPT-4o 系列可选值来自 tokenEncodings.ts。CLI 还提供--token-budget number当打包输出超过指定 token 数时以非零退出码失败可作为 CI 或 Agent 上下文限制的护栏见 cliRun.ts。CLI 常用参数一览以下参数在 cliRun.ts 中定义按分组列出基础-v, --version、--verbose、--quiet、--stdout直接输出到标准输出与--output互斥、--stdin从标准输入逐行读取文件路径、--copy处理后复制到剪贴板、--token-count-tree [threshold]、--top-files-len n。输出-o, --output file默认repomix-output.xml-表示 stdout、--style xml|markdown|json|plain、--output-file-path-style、--parsable-style、--compressTree-sitter 提取类/函数/接口等核心结构、--output-show-line-numbers、--no-file-summary、--no-directory-structure、--no-files仅元数据、--remove-comments、--remove-empty-lines、--truncate-base64、--header-text、--instruction-file-path、--split-output size如500kb、2mb。文件选择--include patterns、-i, --ignore patterns、--no-gitignore、--no-dot-ignore、--no-default-patterns。远程仓库--remote url、--remote-branch name、--remote-trust-config默认不信任远程仓库中的配置文件交互终端会要求确认。配置-c, --config path、--init、--global。安全--no-security-check。Token--token-count-encoding encoding、--token-budget number。MCP--mcp、--sandbox [dir]将 MCP 文件工具限制在工作区内。技能生成--skill-generate [name]、--skill-project-name、--skill-output、-f, --force。监视模式-w, --watch文件变化时自动重新打包。--watch与--remote、--stdout、--stdin、--copy、--split-output等不可同时使用冲突校验逻辑见 cliRun.ts 的validateWatchOptions。Casos de uso del mundo real真实世界用例LLM 代码生成工作流有开发者分享如何用 Repomix 从既有代码库提取代码上下文再借助 Claude、Aider 等 LLM 进行增量改进、代码评审与自动化文档生成。为 LLM 构建知识数据包作者们用 Repomix 把博客、文档、书籍等文字内容打包为 LLM 兼容格式让读者通过 AI 驱动的问答系统与他们的专业内容互动。更多场景可查看 用例指南。Guía para usuarios avanzados高级用户指南Repomix 为高级场景提供了强大能力以下指南值得继续深入MCP 服务器Model Context Protocol 集成让 AI 助手直接调用 Repomix 工具服务端实现见 mcpServer.ts内含packCodebaseTool、readRepomixOutputTool、grepRepomixOutputTool等工具。GitHub Actions在 CI/CD 工作流中自动化打包代码库。代码压缩基于 Tree-sitter 的智能压缩约可减少 70% 的 token解析实现见 parseFile.ts 与 languageConfig.ts覆盖 C、C、C#、CSS、Dart、Go、Java、JavaScript、PHP、Python、Ruby、Rust、Solidity、Swift、TypeScript、Vue 等语言。作为库使用把 Repomix 集成进你的 Node.js 应用pack与runCli导出见 src/index.ts。自定义指令向输出中添加自定义提示词与指令output.instructionFilePath/--instruction-file-path。安全特性内置 Secretlint 集成与安全检查。最佳实践用经过验证的策略优化你的 AI 工作流。完整文档目录见 西班牙语版指南首页。【免费下载链接】repomix Repomix is a powerful tool that packs your entire repository into a single, AI-friendly file. Perfect for when you need to feed your codebase to Large Language Models (LLMs) or other AI tools like Claude, ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok, and more.项目地址: https://gitcode.com/GitHub_Trending/rep/repomix创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考