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/repomix
Repomix 是一款将完整代码库打包成单个 AI 友好文件的命令行工具,专为把代码交给大型语言模型(LLM)分析而设计,兼容 ChatGPT、Claude、Gemini、Grok、DeepSeek、Perplexity、Gemma、Llama 等主流模型。本文将围绕其入门使用展开,从快速开始、安装方式、核心功能到配置与进阶用法逐层深入,并结合仓库源码说明其底层实现,帮助你在几分钟内获得"一个文件喂给 AI 做全库审查、重构、排障"的完整实战能力。
快速开始
在你的项目根目录下运行一行命令即可完成打包:
npx repomix@latest就这么简单!命令执行后,你会在当前目录中找到一个repomix-output.xml文件,其中以 AI 友好的格式整理并合并了整个代码库(文件摘要、目录结构、文件内容等)。
然后,你可以把这个文件直接发送给 AI 助手,并附上类似这样的提示:
这个文件包含了仓库中所有文件的合并内容。 我想重构代码,请先帮我审查一下。AI 将基于完整的代码库上下文进行分析并提供全面见解。在讨论具体修改时,AI 还可以帮助你生成代码——通过像 Claude 的 Artifacts 这样的功能,你甚至可以一次性接收多个相互依赖的文件。
提示:默认输出文件名与格式可通过
-o, --output与--style选项调整,详见后文"输出格式"与"命令行选项"章节。
为什么选择 Repomix?
Repomix 的优势在于能够搭配 ChatGPT、Claude、Gemini、Grok 等任何订阅服务使用,无需额外费用。它提供完整的代码库上下文,省去了逐个查看文件的麻烦,让分析更快速、更准确。
有了整个代码库作为上下文,Repomix 可以应用于各种场景,包括但不限于:
- 方案设计与实施规划:AI 基于现有架构给出建议
- Bug 排查:跨文件追踪问题根本原因
- 第三方库安全审计:分析依赖项的安全隐患
- 文档生成:自动产出 API 文档、开发者指南等
核心功能一览
- AI 优化:以 AI 易于理解的结构化格式整理代码库,默认输出 XML
- Token 计数:统计 Token 使用量,方便管理 LLM 上下文窗口
- Git 感知:自动识别并遵循
.gitignore和.git/info/exclude文件 - 注重安全:使用 Secretlint 进行敏感信息(API 密钥、令牌、私钥等)检测
- 多种输出格式:可选 XML、Markdown、JSON 或纯文本格式
- 远程仓库支持:直接打包 GitHub 仓库而无需本地克隆
- 代码压缩:基于 Tree-sitter 提取类、函数、接口签名,显著减少 Token 数量
安装方式
使用 npx(无需安装)
npx repomix@latest这是最轻量的方式,npx 会临时拉取并运行 Repomix,适合快速体验。
全局安装
# npm npm install -g repomix # yarn yarn global add repomix # pnpm pnpm add -g repomix # bun bun add -g repomix # Homebrew brew install repomixDocker 安装
Docker 是最便捷的方式之一,可以避免本机环境配置问题:
# 处理当前目录 docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix # 处理指定目录 docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory # 处理远程仓库 docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote yamadashy/repomix浏览器扩展与 VS Code 扩展
此外,仓库中还提供了 Chrome/Firefox 浏览器扩展(browser/目录,入口见 browser/entrypoints/content.ts),可直接在 GitHub 仓库页面添加"Repomix"按钮一键打包;社区也维护了 VS Code 扩展。浏览器扩展相关实现与测试可参考 browser/README.md 与 browser/tests/repomix-integration.test.ts。
系统要求与验证
- Node.js ≥ 22.0.0
- Git(处理远程仓库时需要)
安装完成后验证:
repomix --version repomix --help常见使用场景
打包指定目录
repomix path/to/directory包含与排除文件
使用 glob 模式精确控制文件选择:
# 仅包含指定模式的文件 repomix --include "src/**/*.ts,**/*.md" # 排除指定模式的文件 repomix --ignore "**/*.log,tmp/"处理远程仓库
# 使用 GitHub URL repomix --remote https://github.com/user/repo # 使用简写形式 repomix --remote user/repo # 不使用 --remote 的简写(自动检测) repomix user/repo # 指定分支/标签/提交 repomix --remote user/repo --remote-branch main repomix --remote user/repo --remote-branch 935b695文件列表输入(stdin)
通过 stdin 逐行传入文件路径,实现最大的文件选择灵活性:
# 使用 find 命令 find src -name "*.ts" -type f | repomix --stdin # 使用 git 获取跟踪的文件 git ls-files "*.ts" | repomix --stdin # 使用 ripgrep 查找文件 rg --files --type ts | repomix --stdin # 使用 grep 查找包含特定内容的文件 grep -l "TODO" **/*.ts | repomix --stdin # 使用 fzf 进行交互式文件选择 find . -name "*.ts" -type f | fzf -m | repomix --stdin # 从包含文件路径的文件中读取 cat file-list.txt | repomix --stdin # 使用 echo 直接输入 echo -e "src/index.ts\nsrc/utils.ts" | repomix --stdin使用--stdin时,指定的文件会被添加到包含模式中,正常的包含和忽略行为仍然生效;路径可以是相对路径或绝对路径,Repomix 会自动处理路径解析和去重。stdin 的文件收集实现在 src/core/file/fileStdin.ts。
Git 集成:差异与提交日志
为 AI 提供开发上下文:
# 包含 git 差异(未提交的更改) repomix --include-diffs # 包含 git 提交日志(默认最近 50 个提交) repomix --include-logs # 包含特定数量的提交 repomix --include-logs --include-logs-count 10 # 同时包含差异和日志 repomix --include-diffs --include-logs这能带来有价值的上下文信息:
- 最近更改:Git 差异显示未提交的修改
- 开发规律:Git 日志揭示通常一起更改的文件
- 提交历史:最近的提交消息提供开发重点的洞察
- 文件关系:理解在同一提交中修改的文件
对应实现位于 src/core/git/gitDiffHandle.ts 与 src/core/git/gitLogHandle.ts,测试覆盖见 tests/core/git/gitDiffHandle.test.ts。
Token 数量优化:token 计数树
了解代码库的 Token 分布对优化 AI 交互至关重要:
repomix --token-count-tree输出类似:
🔢 Token Count Tree: ──────────────────── └── src/ (70,925 tokens) ├── cli/ (12,714 tokens) │ ├── actions/ (7,546 tokens) │ └── reporters/ (990 tokens) └── core/ (41,600 tokens) ├── file/ (10,098 tokens) └── output/ (5,808 tokens)还可以设置最小 Token 阈值以聚焦大文件:
repomix --token-count-tree 1000 # 仅显示拥有 1000+ token 的文件/目录这有助于:识别高 Token 文件、用--include/--ignore优化文件选择、规划压缩策略、平衡内容与上下文。Token 计数的核心实现见 src/core/metrics/TokenCounter.ts 与 src/core/tokenCount/buildTokenCountStructure.ts。
输出拆分
处理大型代码库时,打包输出可能超过某些 AI 工具的文件大小限制(例如 Google AI Studio 的 1MB 限制):
repomix --split-output 1mb这将生成编号文件:repomix-output.1.xml、repomix-output.2.xml等。大小可用500kb、1mb、2mb、1.5mb等可读单位指定,支持小数值。文件按顶级目录分组以保持上下文,单个文件或目录永远不会被拆分到多个输出文件中。实现见 src/core/output/outputSplit.ts。
输出格式详解
Repomix 支持四种输出格式,通过--style指定:
| 格式 | 命令 | 适用场景 |
|---|---|---|
| XML(默认) | repomix --style xml | 配合 Claude 使用时推荐,解析精度更高 |
| Markdown | repomix --style markdown | 注重可读性时使用 |
| JSON | repomix --style json | 程序化处理或 API 集成 |
| 纯文本 | repomix --style plain | 追求简洁与通用兼容性 |
为什么 XML 是默认格式?
Repomix 基于广泛的研究与测试选择 XML 作为默认格式:Anthropic(Claude)明确推荐使用 XML 标签来构建提示,声明模型在训练过程中接触过此类提示;Google(Gemini)推荐在复杂任务中使用包括 XML 在内的结构化格式;OpenAI(GPT)也在复杂场景中倡导结构化提示。基于实证证据与 AI 辅助代码分析的实际考量,XML 成为默认选择。
XML 输出结构示例(概要):
<file_summary> (元数据和 AI 指令) </file_summary> <directory_structure> src/ index.ts utils/ helper.ts </directory_structure> <files> <file path="src/index.ts"> // 文件内容 </file> </files> <git_logs> <git_log_commit> <date>2025-08-20 00:47:19 +0900</date> <message>feat(cli): Add --include-logs option</message> <files>...</files> </git_log_commit> </git_logs>JSON 格式与 jq 处理
JSON 格式输出 camelCase 属性名(fileSummary、directoryStructure、files、instruction等),便于程序化解析:
# 列出所有文件路径 cat repomix-output.json | jq -r '.files | keys[]' # 计算文件总数 cat repomix-output.json | jq '.files | keys | length' # 提取特定文件内容 cat repomix-output.json | jq -r '.files["README.md"]' # 按扩展名查找文件 cat repomix-output.json | jq -r '.files | keys[] | select(endswith(".ts"))' # 查找包含特定文本的文件 cat repomix-output.json | jq -r '.files | to_entries[] | select(.value | contains("function")) | .key' # 提取目录结构 cat repomix-output.json | jq -r '.directoryStructure' # 获取自定义指令 cat repomix-output.json | jq -r '.instruction // "未提供指令"'各种输出样式的底层实现在 src/core/output/outputStyles/ 目录:markdownStyle.ts、plainStyle.ts、xmlStyle.ts,对应测试见 tests/core/output/outputStyles/。
配置文件:从 JSON 到 TypeScript
Repomix 支持配置文件与命令行选项两种配置方式。配置文件允许你自定义代码库的处理和输出方式。
初始化配置文件
repomix --init这会在项目目录创建带默认设置的repomix.config.json。也可创建全局配置作为后备:
repomix --init --global配置文件格式与搜索优先级
Repomix 按以下优先级自动搜索配置文件(同类别内 TS > JS > JSON):
- TypeScript:
repomix.config.ts、repomix.config.mts、repomix.config.cts - JavaScript/ES Module:
repomix.config.js、repomix.config.mjs、repomix.config.cjs - JSON:
repomix.config.json5、repomix.config.jsonc、repomix.config.json
配置文件支持 JSON5 语法:注释、尾随逗号、无引号属性名等。仓库测试夹具见 tests/fixtures/config-ts/ 与 tests/fixtures/config-js/。
全局配置位置:
- Windows:
%LOCALAPPDATA%\Repomix\repomix.config.* - macOS/Linux:
~/.config/repomix/repomix.config.*
命令行选项优先于配置文件设置。
TypeScript 配置示例
TypeScript 配置提供完整的类型检查与 IDE 支持,需将 Repomix 安装为开发依赖:
npm install -D repomix// repomix.config.ts import { defineConfig } from 'repomix'; export default defineConfig({ output: { filePath: 'output.xml', style: 'xml', removeComments: true, }, ignore: { customPatterns: ['**/node_modules/**', '**/dist/**'], }, });defineConfig与配置 Schema 定义见 src/config/configSchema.ts,repomix.config.ts的动态值(时间戳、环境变量等)能力使其比 JSON 更灵活。
完整配置示例
以下是完整的repomix.config.json示例(仓库根目录亦提供实际示例 repomix.config.json):
{ "$schema": "https://repomix.com/schemas/latest/schema.json", "input": { "maxFileSize": 50000000 }, "output": { "filePath": "repomix-output.xml", "style": "xml", "filePathStyle": "target-relative", "parsableStyle": false, "compress": false, "headerText": "打包文件的自定义头部信息", "fileSummary": true, "directoryStructure": true, "files": true, "removeComments": false, "removeEmptyLines": false, "topFilesLength": 5, "showLineNumbers": false, "truncateBase64": false, "copyToClipboard": false, "includeEmptyDirectories": false, "git": { "sortByChanges": true, "sortByChangesMaxCommits": 100, "includeDiffs": false, "includeLogs": false, "includeLogsCount": 50 } }, "include": ["**/*"], "ignore": { "useGitignore": true, "useDefaultPatterns": true, "customPatterns": [ "additional-folder", "**/*.log" ] }, "security": { "enableSecurityCheck": true }, "tokenCount": { "encoding": "o200k_base" } }关键配置项说明
| 选项 | 说明 | 默认值 |
|---|---|---|
input.maxFileSize | 最大处理文件大小(字节),超过则跳过,用于排除大型二进制或数据文件 | 50000000 |
output.filePath | 输出文件名 | "repomix-output.xml" |
output.style | 输出样式:xml、markdown、json、plain | "xml" |
output.compress | 使用 Tree-sitter 执行智能代码提取,减少 Token | false |
output.parsableStyle | 是否按所选样式转义输出,解析更佳但可能增加 Token | false |
output.headerText | 输出文件头部的自定义文本,可为 AI 提供上下文 | null |
output.fileSummary | 是否包含文件计数、大小等摘要 | true |
output.directoryStructure | 是否包含目录结构 | true |
output.removeComments | 从支持的文件类型中移除注释 | false |
output.removeEmptyLines | 删除空行减少 Token | false |
output.showLineNumbers | 为每行添加行号 | false |
output.splitOutput | 按大小拆分输出为多个编号文件 | 未设置 |
output.tokenBudget | 输出超限时以非零退出码失败,作为 CI/Agent 防护 | 未设置 |
output.git.sortByChanges | 按 Git 更改次数排序文件 | true |
output.git.sortByChangesMaxCommits | 分析 Git 更改的最大提交数 | 100 |
output.git.includeDiffs/includeLogs | 是否包含 Git 差异/日志 | false |
output.git.includeLogsCount | 包含的 Git 日志提交数 | 50 |
include | 包含的文件 glob 模式 | [] |
ignore.useGitignore | 是否使用.gitignore模式 | true |
ignore.useDotIgnore | 是否使用.ignore文件模式 | true |
ignore.useDefaultPatterns | 是否使用内置默认忽略模式 | true |
ignore.customPatterns | 额外忽略模式 | [] |
security.enableSecurityCheck | 是否使用 Secretlint 检测敏感信息 | true |
tokenCount.encoding | Token 计数编码:o200k_base(GPT-4o)、cl100k_base(GPT-3.5/4) | "o200k_base" |
模式验证
通过$schema属性为配置文件启用 JSON Schema 验证,在支持 JSON Schema 的编辑器中获得自动完成与校验:
{ "$schema": "https://repomix.com/schemas/latest/schema.json", "output": { "filePath": "repomix-output.md", "style": "markdown" } }仓库中的 Schema 生成脚本见 website/client/scripts/generateSchema.ts,生成的 Schema 位于 website/client/public/schemas/。
忽略机制与二进制文件处理
多层级忽略规则
Repomix 提供多种设置忽略模式的方式:
.gitignore:默认使用项目.gitignore与.git/info/exclude,可通过ignore.useGitignore或--no-gitignore控制.ignore:项目根目录的.ignore文件,与.gitignore同格式(ripgrep、the silver searcher 等工具也遵守)- 默认模式:内置常见排除项(node_modules、.git、二进制文件、构建产物、各类锁文件等),完整列表见 src/config/defaultIgnore.ts
.repomixignore:Repomix 专属忽略文件,同样遵循 gitignore 格式- 自定义模式:
ignore.customPatterns或-i, --ignoreCLI 选项
优先顺序(从高到低):
- 自定义模式(
ignore.customPatterns) - 忽略文件(
.repomixignore、.ignore、.gitignore、.git/info/exclude),嵌套目录中更深层的文件优先级更高 - 默认模式(
ignore.useDefaultPatterns为 true 时)
.repomixignore示例:
# 缓存目录 .cache/ tmp/ # 构建输出 dist/ build/ # 日志 *.log二进制文件处理
二进制文件(图像、PDF、编译产物、归档等)采用特殊策略保持输出高效:
- 文件内容:二进制文件不包含在打包输出中
- 目录结构:二进制文件路径被列出在目录结构部分,提供仓库完整概览
例如仓库包含logo.png和app.jar时,它们出现在目录结构中,但内容不会进入文件部分。大于input.maxFileSize(默认 50MB)的文件会被完全跳过。
安全检查与远程仓库配置信任
Secretlint 安全检查
Repomix 使用 Secretlint 在打包前检测敏感信息:
- API 密钥
- 访问令牌
- 认证凭证
- 私钥
- 密码与环境变量
安全检查默认启用,发现问题时输出类似:
🔍 Security Check: ────────────────── 2 suspicious file(s) detected and excluded: 1. config/credentials.json - Found AWS access key 2. .env.local - Found database password通过命令行禁用:
repomix --no-security-check或配置文件:
{ "security": { "enableSecurityCheck": false } }安全检测核心实现见 src/core/security/securityCheck.ts,Worker 实现见 src/core/security/workers/securityCheckWorker.ts。
远程仓库配置信任
使用--remote打包远程仓库时,Repomix 将仓库自身的repomix.config.*视为不受信任的代码,原因在于:
repomix.config.ts/.js/.mjs在加载时会被执行input.processors会对匹配文件运行外部命令output.instructionFilePath及包含../的 include 模式会读取仓库之外的文件
默认情况下,远程仓库配置永远不会被加载。选择信任需显式操作:
# 使用 CLI 标志 repomix --remote user/repo --remote-trust-config # 使用环境变量 REPOMIX_REMOTE_TRUST_CONFIG=true repomix --remote user/repo交互式终端中会显示即将运行的配置并征求确认;提示对控制字符、ANSI 转义、双向控制字符进行转义以防终端篡改,拒绝符号链接配置,并按行数与字节数限制输出。相关实现见 src/cli/prompts/remoteConfigTrustPrompt.ts 与 src/cli/prompts/remoteConfigTrustStore.ts。
进阶功能:代码压缩与文件处理器
代码压缩(Tree-sitter)
--compress(或配置output.compress: true)使用 Tree-sitter 解析代码,智能提取类、函数、接口、导入导出等基本结构,同时移除实现细节:
repomix --compress # 远程仓库同样适用 repomix --remote yamadashy/repomix --compress主要优点:
- 显著减少 Token 数量
- 保留类和函数签名
- 保持导入和导出
- 保留类型定义和接口
- 移除函数体和实现细节
Tree-sitter 解析策略位于 src/core/treeSitter/parseStrategies/(含 TypeScript、Python、Go、Vue、C/C++、Rust、Java 等语言),查询文件位于 src/core/treeSitter/queries/。
按文件设置包含级别
output.patterns允许按 glob 为不同文件设置详细级别,覆盖全局output.compress:
{ "output": { "compress": false, // 全局默认值作为兜底 "patterns": [ { "pattern": "docs/**/*", "compress": true }, { "pattern": "website/**/*", "directoryStructureOnly": true } ] } }每个文件解析为三个级别之一:完整内容(默认)、压缩(Tree-sitter 处理)或仅目录结构(内容块完全省略)。模式按数组顺序求值,第一个匹配优先;directoryStructureOnly优先于compress。该选项仅适用于配置文件,无对应 CLI 选项。
文件处理器(input.processors)
input.processors在文件打包之前运行外部命令转换内容,用命令标准输出替换匹配文件的内容,适合减少 Token 或转换格式:
{ "input": { "processors": [ { "pattern": "**/*.json", "command": "npx @toon-format/cli {file}" } ] } }工作原理:Repomix 将匹配文件内容写入临时文件,{file}占位符(必需)替换为文件路径;命令通过 shell 运行,标准输出成为文件新内容,随后照常经过安全检查、Token 计数与输出生成。常见用例:
| 模式 | command | 作用 |
|---|---|---|
**/*.json | jq -c . {file} | 去除空白压缩 JSON |
**/*.json | npx @toon-format/cli {file} | 转换为紧凑省 Token 的 TOON 格式 |
**/*.svg | npx svgo -i {file} -o - | 压缩 SVG |
**/*.ipynb | jupyter nbconvert --to script --stdout {file} | notebook 转纯 Python 脚本 |
每个处理器选项:timeout(默认 60000ms)与onError("fail"中止打包 /"skip"回退原始内容)。⚠️ 安全提醒:文件处理器会执行配置中的任意命令,仅在本地 CLI 运行、或对--remote显式传入--remote-trust-config时启用;库 API、MCP 服务器与托管 Web 中均被禁用。信任边界逻辑见 src/core/file/workers/fileProcessWorker.ts。
命令行选项速查
# 基本使用 repomix # 自定义输出文件与格式 repomix -o my-output.xml --style xml # 输出到标准输出 repomix --stdout > custom-output.txt # 输出到标准输出后管道给其他命令 repomix --stdout | llm "请解释这段代码的作用。" # Git 集成 repomix --include-logs repomix --include-logs --include-logs-count 10 repomix --include-diffs --include-logs # 模式筛选 repomix --include "src/**/*.ts,*.md" --ignore "*.test.js,docs/**" # 远程仓库(分支/提交/简写) repomix --remote https://github.com/user/repo/tree/main repomix --remote https://github.com/user/repo/commit/836abcd7335137228ad77feb28655d85712680f1 repomix --remote user/repo # stdin 文件列表 find src -name "*.ts" -type f | repomix --stdin # Token 计数分析 repomix --token-count-tree repomix --token-count-tree 1000 # 监视模式:文件变更时自动重新打包 repomix --watch repomix -w --include "src/**/*.ts"CLI 入口与参数解析见 src/cli/cliRun.ts,各动作实现见 src/cli/actions/。常用选项速查:
| 选项 | 说明 |
|---|---|
-v, --version | 显示版本信息并退出 |
--verbose/--quiet | 详细调试日志 / 仅输出错误 |
--stdout | 输出写入标准输出而非文件 |
--stdin | 从标准输入逐行读取文件路径 |
--copy | 输出同时复制到系统剪贴板 |
--token-count-tree [threshold] | 显示带 Token 计数的文件树 |
-o, --output <file> | 输出文件路径(-表示标准输出) |
--style <style> | 输出格式:xml / markdown / json / plain |
--compress | Tree-sitter 代码压缩 |
--remove-comments | 打包前剥离代码注释 |
--split-output <size> | 拆分输出(如500kb、2mb) |
--include/-i, --ignore | 包含 / 排除 glob 模式 |
--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-budget <number> | 输出超 N Token 时非零退出码失败 |
--mcp/--sandbox [dir] | 作为 MCP 服务器运行 / 限制文件工具范围 |
-w, --watch | 监视模式自动重新打包 |
监视模式仅适用于本地目录,无法与--remote、--stdout、--stdin、--split-output、--skill-generate或--copy组合使用。
写给 AI 的高质量提示词模板
将打包文件交给 AI 时,一份结构化的提示词能显著提升结果质量:
分析此代码库的架构: 1. 评估整体结构和模式 2. 识别潜在的架构问题 3. 提出改进可扩展性的建议 4. 标注遵循最佳实践的部分对此代码库进行安全性评审: 1. 识别潜在的安全漏洞 2. 检查常见的安全反模式 3. 评审错误处理和输入验证 4. 评估依赖项的安全性这个代码库在服务器端有内存泄漏问题。应用程序运行几个小时后会崩溃。 请分析整个代码库并识别潜在原因。我想为这个应用程序添加用户认证功能。请审查当前的代码库结构, 并建议最适合现有架构的方法。你正在帮助一位新开发者了解这个代码库。请提供架构概述, 解释主要组件及其交互,并突出显示首先应该审查的最重要文件。获取更好结果的技巧:明确具体(包含清晰目标和评估标准)、设置上下文(说明角色与专业水平)、请求格式(定义期望响应结构)、设置优先级(指出最重要方面)。
模型特定使用建议
- Claude:使用 XML 输出格式,将重要指令放在最后,指定响应结构
- ChatGPT:使用 Markdown 格式,大型代码库分成小节,包含系统角色提示
- Gemini:适用于所有格式,每次请求专注于特定领域,使用逐步分析
与 AI 工具链集成:MCP 服务器
Repomix 还可以作为 Model Context Protocol(MCP)服务器运行,将打包能力直接集成到 AI 助手中:
repomix --mcp --sandbox path/to/project--sandbox将文件工具限制在工作区目录内,所有路径相对根目录解析,绝对路径/主机路径被拒绝,同时禁用远程打包与 Skill 生成等能力。MCP 服务器实现见 src/mcp/mcpServer.ts 与 src/mcp/tools/(含packCodebaseTool.ts、packRemoteRepositoryTool.ts、readRepomixOutputTool.ts、grepRepomixOutputTool.ts等)。
下一步学习路径
围绕本入门指南,仓库提供了完整的配套文档与源码可继续深入:
- 安装指南:更多安装方式与验证步骤
- 使用指南:基本与高级用法
- 配置:完整配置项参考
- 安全功能:安全检查与远程配置信任细节
- 输出格式:四种格式详细对比
- 命令行选项:完整 CLI 参考
- 提示词示例:更多提示模板
- 使用场景:实际案例与工作流
- MCP 服务器:与 AI 助手直接集成
核心源码入口为 src/index.ts(导出pack、collectFiles、runSecurityCheck、TokenCounter、defineConfig等 API),仓库根配置示例见 repomix.config.json,行为测试覆盖于 tests/ 目录。祝你在 AI 辅助开发中,用 Repomix 打通"全库上下文"这一步。
【免费下载链接】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),仅供参考