尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Repomix 完整使用指南:将整个代码仓库打包为 AI 友好的单一文件(安装、CLI、配置与实战)

Repomix 完整使用指南:将整个代码仓库打包为 AI 友好的单一文件(安装、CLI、配置与实战) Repomix 完整使用指南将整个代码仓库打包为 AI 友好的单一文件安装、CLI、配置与实战【免费下载链接】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本指南基于 Repomix 项目官方葡萄牙语首页website/client/src/pt-br/index.md及其配套源码整理。Repomix 是一款把本地或远程 Git 仓库打包成单一 XML、Markdown、JSON 或纯文本文件的命令行工具输出结果专为 Claude、ChatGPT、Gemini、Grok、MCP 等 AI 工具与代码审查场景优化。读完本文你将掌握 Repomix 的安装方式、核心 CLI 用法、输出格式选择、配置文件编写以及如何将打包产物交给 AI 助手完成代码审查、重构、文档生成等实战任务。Repomix 是什么Repomix 是一个强大的仓库打包工具它把整个代码库压缩进一个 AI 兼容的文件中。无论你是在做代码审查、代码重构还是需要 AI 协助理解项目Repomix 都能让你轻松地把完整的仓库上下文一次性交给 AI 工具。它的设计围绕四个核心能力见首页特性区与 README.md为 AI 优化Otimizado para IA以 AI 易于理解和处理的方式格式化你的源代码。Git 集成Integração com Git自动尊重项目的.gitignore、.ignore与.repomixignore规则不会把不该打包的文件塞进输出。安全优先Focado na Segurança内置 Secretlint默认开启security.enableSecurityCheck默认true见 src/config/configSchema.ts。Token 计数Contagem de Tokens为每个文件乃至整个仓库提供 token 计数帮助你评估是否超出 LLM 的上下文窗口限制。从源码结构看打包的核心流程由 src/core/packager.ts 编排文件收集、Git 元数据、token 统计与安全扫描各自独立成模块src/core/file、src/core/git、src/core/metrics保证大型仓库也能高效处理。快速开始一条命令完成打包在项目目录下直接运行无需先安装npx repomixlatest命令执行后当前目录会生成一个repomix-output.xml文件其中包含整个仓库的 AI 友好格式内容。把这 个文件发送给 AI 助手如 ChatGPT、Claude并附带如下提示词Este arquivo contém todos os arquivos do repositório combinados em um. Eu quero refatorar o código, então, por favor, revise-o primeiro.此文件包含仓库中的所有文件合并为一个。我想重构代码请先审查。AI 会基于完整的代码上下文给出全面分析当讨论具体修改时AI 可以据此生成代码配合 Claude 的 Artifacts 等特性甚至可以直接产出多个相互依赖的文件安装方式全局安装还是即用即走除了npx repomixlatest的零安装用法外官方还支持多种全局安装途径# 使用 npm 安装 npm install -g repomix # 或使用 yarn yarn global add repomix # 或使用 bun bun add -g repomix # 或使用 HomebrewmacOS/Linux brew install repomix # 安装完成后在任意项目目录执行 repomix更新全局安装的 Repomixnpm update -g repomix # npm yarn global upgrade repomix # yarn bun update -g repomix # bun使用npx repomix通常更省心因为它始终拉取最新版本。当前仓库package.json中声明 Repomix 版本为 1.18.0要求 Node.js 22。Docker 用法如果你希望在隔离环境中运行 Repomix或者偏好容器化方式可以直接使用官方镜像# 基本用法打包当前目录 docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix # 打包指定目录 docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory # 处理远程仓库并将输出写入 output 目录 docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote https://github.com/yamadashy/repomixCLI 基本用法打包整个仓库repomix打包指定目录repomix path/to/directory使用 glob 模式只打包特定文件repomix --include src/**/*.ts,**/*.md--include支持逗号分隔的多个 fast-glob 模式 可以看到文件选择相关的选项还包括-i/--ignore、--no-gitignore、--no-dot-ignore与--no-default-patterns默认内置忽略node_modules、.git、构建目录等。排除特定文件repomix --ignore **/*.log,tmp/--ignore是附加排除规则会叠加在.gitignore、.ignore和内置默认规则之上。打包远程仓库# 使用 GitHub 简写格式 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 完成克隆与分析因此CLI 工具也能访问私有仓库前提是本机有权限。配套的--remote-branch name选项可指定分支、tag 或 commit。底层实现在 src/core/git 模块远程地址解析见 gitRemoteParse.ts、远程操作见 gitRemoteHandle.ts。一个值得注意的安全机制出于安全考虑远程仓库内的repomix.config.*配置文件默认不会被加载防止不可信仓库通过配置文件执行代码需要时可用--remote-trust-config显式信任交互式终端下会先展示配置并请求确认。初始化配置文件repomix --init这会在当前目录生成一份带默认值的repomix.config.json。输出格式Repomix 支持四种输出风格默认是 XML# XML 格式默认 repomix --style xml # Markdown 格式 repomix --style markdown # JSON 格式 repomix --style json # 纯文本格式 repomix --style plain不同风格对应的默认输出文件名也不同见 src/config/configSchema.tsrepomix-output.xml、repomix-output.md、repomix-output.json、repomix-output.txt。无论哪种格式输出都包含几个固定的结构区块并且以面向 AI 的说明文字开头帮助模型理解打包文件的上下文与结构File Summary / file_summary元数据与面向 AI 的使用说明Directory Structure / directory_structure目录树Files / files各文件路径与内容Instruction来自output.instructionFilePath的自定义指令。XML 格式默认This file is a merged representation of the entire codebase, combining all repository files into a single document. file_summary (Metadata and usage AI instructions) /file_summary directory_structure src/ cli/ cliOutput.ts index.ts (...remaining directories) /directory_structure files file pathsrc/index.js // File contents here /file (...remaining files) /files instruction (Custom instructions from output.instructionFilePath) /instructionXML 标签能帮助 Claude 这类模型更准确地解析多组件提示词上下文、指令、示例因此 XML 不只是格式差异而是可能更有效的喂料方式。JSON 格式与 jq 配合JSON 输出以 camelCase 属性组织为层级对象fileSummary、userProvidedHeader、directoryStructure、files、instruction非常适合程序化处理、API 集成与数据分析。例如用jq快速提取信息# 列出所有文件路径 cat repomix-output.json | jq -r .files | keys[] # 统计文件总数 cat repomix-output.json | jq .files | keys | length # 提取指定文件内容 cat repomix-output.json | jq -r .files[src/index.js] # 按扩展名筛选文件 cat repomix-output.json | jq -r .files | keys[] | select(endswith(.ts))Markdown 与纯文本格式Markdown 格式以# File Summary、# Repository Structure、# Repository Files、# Instruction等层级标题组织兼顾人类可读与 AI 可解析性纯文本格式则用分隔线区分区块是最轻量的选择。配置repomix.config.json持久化你的偏好CLI 参数适合一次性操作若希望配置持久化可创建repomix.config.json也可用 JSON5/JSONC甚至 TypeScript/JavaScript 配置文件配合defineConfig获得类型提示与动态值能力{ output: { style: markdown, filePath: custom-output.md, removeComments: true, showLineNumbers: true, topFilesLength: 10 }, ignore: { customPatterns: [*.test.ts, docs/**] } }参考仓库根目录真实的 repomix.config.json可以了解一份完整的生产级配置长什么样——它启用了文件摘要、目录结构、Git 变更排序、diff 与日志以及o200k_basetoken 编码与安全扫描。配置文件支持 JSON5 语法注释、对象/数组尾逗号、不带引号的属性名都可以用。常用配置项速查默认值见 src/config/configSchema.ts配置项说明默认值input.maxFileSize处理的最大文件字节数超出则跳过5000000050MBoutput.filePath输出文件名repomix-output.xmloutput.style输出风格xml/markdown/json/plainxmloutput.compress是否启用 Tree-sitter 智能代码提取压缩falseoutput.removeComments是否移除代码注释falseoutput.removeEmptyLines是否移除空行falseoutput.showLineNumbers是否在输出中附加行号falseoutput.fileSummary是否输出文件摘要区trueoutput.directoryStructure是否输出目录结构区trueoutput.files是否输出文件内容trueoutput.topFilesLength摘要中展示的最大文件数0 表示不展示5output.headerText自定义头部文本nulloutput.instructionFilePath自定义指令文件路径nulloutput.git.sortByChanges按 Git 变更频率排序文件trueoutput.git.includeDiffs输出中附带 Git difffalseoutput.git.includeLogs输出中附带 Git 提交历史falseinclude仅包含匹配的 glob 文件[]ignore.useGitignore是否使用.gitignoretrueignore.customPatterns附加排除模式[]security.enableSecurityCheck是否进行 Secretlint 安全检查truetokenCount.encodingtoken 计数编码o200k_base对应 GPT-4ocl100k_base对应 GPT-4/3.5o200k_base配置项与 CLI 参数一一对应例如output.style↔--style、ignore.customPatterns↔--ignore。还可以通过$schema属性接入 JSON Schema 校验在支持 JSON schema 的编辑器中获得自动补全与校验本仓库配置即带$schema声明。为什么选择 RepomixRepomix 可以与任何订阅制 AI 服务ChatGPT、Claude、Gemini、Grok 等配合使用Repomix 本身不产生额外成本。通过提供完整代码上下文它消除了逐个文件探索的繁琐让 AI 分析更快、更准确。当整个代码库都作为上下文可用时Repomix 能支撑多种应用场景实施规划、Bug 调查、第三方库安全检查、文档生成等完整场景清单见 website/client/src/pt-br/guide/use-cases.md。进阶面向高级用户的扩展能力首页还指向了六个关键进阶主题全部在仓库中有对应实现与文档MCP 服务器repomix --mcp将 Repomix 作为 Model Context Protocol 服务器运行让 AI 助手直接调用pack_codebase、pack_remote_repository、read_repomix_output、grep_repomix_output等工具工具实现位于 src/mcp/tools。还支持--sandbox将文件工具限制在指定工作区内实现见 src/mcp/pathScope.ts。GitHub Actions在 CI/CD 工作流中自动化打包配合--token-budget超出 token 上限时以非零退出码告警可作为上下文超限的防线。代码压缩--compress基于 Tree-sitter 提取类、函数、接口等关键结构、剥离实现细节可减少约 70% 的 token同时保留语义结构解析策略见 src/core/treeSitter/parseStrategies。也可通过配置output.patterns按 glob 逐文件控制三种包含级别完整内容、压缩、仅目录结构。作为库使用通过pack()/runCli()API 将 Repomix 集成进 Node.js 应用。自定义指令通过--instruction-file-path向输出注入引导 AI 分析的自定义指令。安全特性Secretlint 集成与文件安全校验src/core/security。最佳实践用经过验证的策略优化你的 AI 工作流。更完整的指南集合见 website/client/src/pt-br/guide/index.md。小结Repomix 把喂给 AI 一个完整仓库这件事压缩成了一行命令npx repomixlatest生成repomix-output.xml把它丢给任意主流 AI 助手即可获得基于全量上下文的审查、重构与文档生成结果。在此基础上--include/--ignore控制文件边界--style选择输出格式--remote直接打包 GitHub 仓库repomix.config.json固化团队约定--compress与 token 计数则帮助你把输出控制在大模型的上下文窗口之内——从个人快速尝试到团队 CI 流水线都能找到对应的打开方式。【免费下载链接】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),仅供参考
返回列表