Skip to main content
Glama
MIT License
14,323
16,906
  • Linux
  • Apple

Warp,开发者的代理终端

适用于 MacOS、Linux 和 Windows

📦 Repomix 是一个强大的工具,它可以将您的整个存储库打包成一个 AI 友好的文件。
当您需要将代码库提供给大型语言模型 (LLM) 或其他 AI 工具(如 Claude、ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等)时,它是完美的选择。

🎉 新功能:Repomix 网站和 Discord 社区!

我们期待在那里见到您!

🌟 功能

  • 人工智能优化:以人工智能易于理解和处理的方式格式化您的代码库。
  • 令牌计数:提供每个文件和整个存储库的令牌计数,对于 LLM 上下文限制很有用。
  • 使用简单:您只需一个命令即可打包整个存储库。
  • 可定制:轻松配置要包含或排除的内容。
  • Git-Aware :自动尊重您的.gitignore文件和.git/info/exclude
  • 以安全为中心:结合Secretlint进行强大的安全检查,以检测并防止敏感信息的包含。
  • 代码压缩--compress选项使用Tree-sitter提取关键代码元素,减少标记数,同时保留结构。

🚀 快速入门

使用 CLI 工具>_

您可以在项目目录中立即尝试 Repomix,无需安装:

npx repomix

或者全局安装以便重复使用:

# Install using npm npm install -g repomix # Alternatively using yarn yarn global add repomix # Alternatively using Homebrew (macOS/Linux) brew install repomix # Then run in any project directory repomix

就是这样!Repomix 将在您的当前目录中生成一个repomix-output.xml文件,其中包含 AI 友好格式的整个存储库。

然后,您可以将此文件发送给 AI 助手,并提示如下:

This file contains all the files in the repository combined into one. I want to refactor the code, so please review it first.

Repomix 文件用法 1

当你提出具体的修改建议时,AI 或许能够生成相应的代码。借助 Claude's Artifacts 等功能,你可以输出多个文件,从而生成多个相互依赖的代码片段。

Repomix 文件用法 2

祝你编码愉快!🚀

使用网站🌐

想快速尝试吗?请访问官方网站repomix.com 。只需输入你的仓库名称,填写任何可选详细信息,然后单击**“打包”**按钮即可查看生成的输出。

可用选项

该网站提供了几个便捷的功能:

  • 可定制的输出格式(XML、Markdown 或纯文本)
  • 即时令牌计数估计
  • 更多!

使用浏览器扩展🧩

直接从任何 GitHub 仓库即时访问 Repomix!我们的 Chrome 扩展程序会在 GitHub 仓库页面添加一个便捷的“Repomix”按钮。

Repomix 浏览器扩展

安装
特征
  • 一键访问任何 GitHub 存储库的 Repomix
  • 更多精彩功能即将推出!

使用 VSCode 扩展⚡️

社区维护的 VSCode 扩展程序Repomix Runner (由massdo创建)让您只需点击几下即可在编辑器中直接运行 Repomix。您可以在任何文件夹上运行它,无缝管理输出,并通过 VSCode 直观的界面控制一切。

您希望输出为文件还是仅显示内容?需要自动清理?这款扩展可以满足您的需求。此外,它还能与您现有的 repomix.config.json 无缝兼容。

立即在VSCode Marketplace上试用!源代码可在GitHub上获取。

替代工具🛠️

如果您使用的是 Python,您可能需要查看Gitingest ,它更适合 Python 生态系统和数据科学工作流程: https://github.com/cyclotruc/gitingest

📊 使用方法

打包整个存储库:

repomix

打包特定目录:

repomix path/to/directory

使用glob 模式打包特定文件或目录:

repomix --include "src/**/*.ts,**/*.md"

要排除特定文件或目录:

repomix --ignore "**/*.log,tmp/"

打包远程存储库:

repomix --remote https://github.com/yamadashy/repomix # You can also use GitHub shorthand: repomix --remote yamadashy/repomix # You can specify the branch name, tag, or commit hash: repomix --remote https://github.com/yamadashy/repomix --remote-branch main # Or use a specific commit hash: repomix --remote https://github.com/yamadashy/repomix --remote-branch 935b695 # Another convenient way is specifying the branch's URL repomix --remote https://github.com/yamadashy/repomix/tree/main # Commit's URL is also supported repomix --remote https://github.com/yamadashy/repomix/commit/836abcd7335137228ad77feb28655d85712680f1

压缩输出:

repomix --compress # You can also use it with remote repositories: repomix --remote yamadashy/repomix --compress

初始化新的配置文件( repomix.config.json ):

repomix --init

生成打包文件后,您可以将其与生成式 AI 工具(如 ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等)一起使用。

Docker 使用

您还可以使用 Docker 运行 Repomix。
如果您想在隔离环境中运行 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/repomix

提示示例

使用 Repomix 生成打包文件后,您可以将其与 ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等 AI 工具一起使用。以下是一些入门示例:

代码审查和重构

对于全面的代码审查和重构建议:

This file contains my entire codebase. Please review the overall structure and suggest any improvements or refactoring opportunities, focusing on maintainability and scalability.
文档生成

生成项目文档:

Based on the codebase in this file, please generate a detailed README.md that includes an overview of the project, its main features, setup instructions, and usage examples.
测试用例生成

用于生成测试用例:

Analyze the code in this file and suggest a comprehensive set of unit tests for the main functions and classes. Include edge cases and potential error scenarios.
代码质量评估

评估代码质量和遵守最佳实践:

Review the codebase for adherence to coding best practices and industry standards. Identify areas where the code could be improved in terms of readability, maintainability, and efficiency. Suggest specific changes to align the code with best practices.
图书馆概况

对图书馆有更深层次的了解

This file contains the entire codebase of library. Please provide a comprehensive overview of the library, including its main purpose, key features, and overall architecture.

您可以根据您的特定需求和所使用的 AI 工具的功能随意修改这些提示。

社区讨论

查看我们的社区讨论,用户在其中分享:

  • 他们与 Repomix 一起使用了哪些 AI 工具
  • 他们发现的有效提示
  • Repomix 如何帮助他们
  • 充分利用 AI 代码分析的技巧和窍门

欢迎参与讨论并分享你的经验!你的见解可以帮助其他人更好地使用 Repomix。

输出文件格式

Repomix 生成一个单独的文件,其中代码库的不同部分之间有清晰的分隔符。
为了增强 AI 理解能力,输出文件以面向 AI 的解释开始,使 AI 模型更容易理解打包存储库的上下文和结构。

XML 格式(默认)

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 path="src/index.js"> // File contents here </file> (...remaining files) </files> <instruction> (Custom instructions from `output.instructionFilePath`) </instruction>

对于那些对 XML 标签在 AI 环境中的潜力感兴趣的人:
https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/use-xml-tags

当你的提示包含上下文、说明和示例等多个元素时,XML 标签可以发挥重要作用。它们可以帮助 Claude 更准确地解析你的提示,从而获得更高质量的输出。

这意味着 Repomix 的 XML 输出不仅是一种不同的格式,而且可能是一种将代码库输入 AI 系统进行分析、代码审查或其他任务的更有效的方式。

Markdown 格式

要生成 Markdown 格式的输出,请使用--style markdown选项:

repomix --style markdown

Markdown 格式以分层方式构建内容:

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) # Repository Structure ``` src/ cli/ cliOutput.ts index.ts ``` (...remaining directories) # Repository Files ## File: src/index.js ``` // File contents here ``` (...remaining files) # Instruction (Custom instructions from `output.instructionFilePath`)

这种格式提供了一种干净、可读的结构,既对人友好,又易于被人工智能系统解析。

纯文本格式

要以纯文本格式生成输出,请使用--style plain选项:

repomix --style plain
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) ================================================================ Directory Structure ================================================================ src/ cli/ cliOutput.ts index.ts config/ configLoader.ts (...remaining directories) ================================================================ Files ================================================================ ================ File: src/index.js ================ // File contents here ================ File: src/utils.js ================ // File contents here (...remaining files) ================================================================ Instruction ================================================================ (Custom instructions from `output.instructionFilePath`)

命令行选项

基本选项
  • -v, --version :显示工具版本
输出选项
  • -o, --output <file> :指定输出文件名
  • --stdout :输出到 stdout 而不是写入文件(不能与--output选项一起使用)
  • --style <style> :指定输出样式( xmlmarkdownplain
  • --parsable-style :根据所选样式模式启用可解析输出。请注意,这可能会增加标记数量。
  • --compress :执行智能代码提取,重点关注基本功能和类签名以减少标记数
  • --output-show-line-numbers :在输出中显示行号
  • --copy :另外将生成的输出复制到系统剪贴板
  • --no-file-summary :禁用文件摘要部分输出
  • --no-directory-structure :禁用目录结构部分输出
  • --remove-comments :从支持的文件类型中删除注释
  • --remove-empty-lines :从输出中删除空行
  • --header-text <text> :包含在文件头中的自定义文本
  • --instruction-file-path <path> :包含详细自定义说明的文件路径
  • --include-empty-directories :在输出中包含空目录
  • --include-diffs :在输出中包含 git diff(分别包含工作树和暂存更改)
  • --no-git-sort-by-changes :禁用按 git 更改计数对文件进行排序(默认启用)
筛选选项
  • --include <patterns> :包含模式列表(以逗号分隔)
  • -i, --ignore <patterns> :附加忽略模式(以逗号分隔)
  • --no-gitignore :禁用 .gitignore 文件使用
  • --no-default-patterns :禁用默认模式
远程存储库选项
  • --remote <url> :处理远程 Git 存储库
  • --remote-branch <name> :指定远程分支名称、标签或提交哈希(默认为存储库默认分支)
配置选项
  • -c, --config <path> :自定义配置文件的路径
  • --init :创建配置文件
  • --global :使用全局配置
安全选项
  • --no-security-check :禁用安全检查
令牌计数选项
  • --token-count-encoding <encoding> :指定 OpenAI 的tiktoken分词器使用的分词计数编码(例如,GPT-4o 为o200k_base ,GPT-4/3.5 为cl100k_base )。有关编码详情,请参阅tiktoken model.py
微胶囊钙
其他选项
  • --top-files-len <number> :摘要中显示的顶级文件数
  • --verbose :启用详细日志记录
  • --quiet :禁用所有输出到标准输出

例子:

# Basic usage repomix # Custom output repomix -o output.xml --style xml # Output to stdout repomix --stdout > custom-output.txt # Send output to stdout, then pipe into another command (for example, simonw/llm) repomix --stdout | llm "Please explain what this code does." # Custom output with compression repomix --compress # Process specific files repomix --include "src/**/*.ts" --ignore "**/*.test.ts" # Remote repository with branch repomix --remote https://github.com/user/repo/tree/main # Remote repository with commit repomix --remote https://github.com/user/repo/commit/836abcd7335137228ad77feb28655d85712680f1 # Remote repository with shorthand repomix --remote user/repo

更新 Repomix

要更新全局安装的 Repomix:

# Using npm npm update -g repomix # Using yarn yarn global upgrade repomix

使用npx repomix通常更方便,因为它总是使用最新版本。

远程存储库处理

Repomix 支持处理远程 Git 仓库,无需手动克隆。此功能允许您使用单个命令快速分析任何公共 Git 仓库。

要处理远程存储库,请使用--remote选项,后跟存储库 URL:

repomix --remote https://github.com/yamadashy/repomix

您还可以使用 GitHub 的简写格式:

repomix --remote yamadashy/repomix

您可以指定分支名称、标签或提交哈希:

# Using --remote-branch option repomix --remote https://github.com/yamadashy/repomix --remote-branch main # Using branch's URL repomix --remote https://github.com/yamadashy/repomix/tree/main

或者使用特定的提交哈希:

# Using --remote-branch option repomix --remote https://github.com/yamadashy/repomix --remote-branch 935b695 # Using commit's URL repomix --remote https://github.com/yamadashy/repomix/commit/836abcd7335137228ad77feb28655d85712680f1

代码压缩

--compress选项利用Tree-sitter执行智能代码提取,专注于关键函数和类签名,同时删除实现细节。这有助于减少 token 数量,同时保留重要的结构信息。

repomix --compress

例如,以下代码:

import { ShoppingItem } from './shopping-item'; /** * Calculate the total price of shopping items */ const calculateTotal = ( items: ShoppingItem[] ) => { let total = 0; for (const item of items) { total += item.price * item.quantity; } return total; } // Shopping item interface interface Item { name: string; price: number; quantity: number; }

将被压缩为:

import { ShoppingItem } from './shopping-item'; ⋮---- /** * Calculate the total price of shopping items */ const calculateTotal = ( items: ShoppingItem[] ) => { ⋮---- // Shopping item interface interface Item { name: string; price: number; quantity: number; }

[!NOTE] 这是一项实验性功能,我们将根据用户反馈和实际使用情况积极改进

MCP 服务器集成

Repomix 支持模型上下文协议 (MCP) ,允许 AI 助手直接与您的代码库交互。当作为 MCP 服务器运行时,Repomix 提供的工具可使 AI 助手打包本地或远程存储库进行分析,而无需手动准备文件。

repomix --mcp
配置 MCP 服务器

要将 Repomix 用作带有 Claude 等 AI 助手的 MCP 服务器,您需要配置 MCP 设置:

对于 VS Code:

您可以使用以下方法之一在 VS Code 中安装 Repomix MCP 服务器:

  1. 使用安装徽章:

  1. 使用命令行:
code --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'

对于 VS Code 内部人员:

code-insiders --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'

对于 Cline(VS Code 扩展):

编辑cline_mcp_settings.json文件:

{ "mcpServers": { "repomix": { "command": "npx", "args": [ "-y", "repomix", "--mcp" ] } } }

对于光标:

在 Cursor 中,从Cursor Settings > MCP > + Add new global MCP server ,其配置与 Cline 类似。

对于 Claude 桌面:

编辑claude_desktop_config.json文件,其配置与 Cline 的配置类似。

使用 Docker 代替 npx:

您可以使用 Docker 作为 npx 的替代方案来运行 Repomix 作为 MCP 服务器:

{ "mcpServers": { "repomix-docker": { "command": "docker", "args": [ "run", "-i", "--rm", "ghcr.io/yamadashy/repomix", "--mcp" ] } } }

配置完成后,您的 AI 助手可以直接使用 Repomix 的功能来分析代码库,而无需手动准备文件,从而使代码分析工作流程更加高效。

可用的 MCP 工具

当作为 MCP 服务器运行时,Repomix 提供以下工具:

  1. pack_codebase :将本地代码目录打包成合并的 XML 文件,用于 AI 分析
  • 参数:
    • directory :要打包的目录的绝对路径
    • compress :(可选,默认值:false)启用 Tree-sitter 压缩功能,提取必要的代码签名和结构,同时移除实现细节。在保留语义含义的同时,可减少约 70% 的 token 使用量。由于 grep_repomix_output 允许增量内容检索,因此通常不需要使用。仅在您明确需要获取大型代码库的完整代码库内容时使用。
    • includePatterns :(可选)使用快速全局模式指定要包含的文件。多个模式可以用逗号分隔(例如,“ /*.{js,ts}”、“src/ ,docs/**”)。只有匹配的文件才会被处理。
    • ignorePatterns :(可选)使用快速全局模式指定要排除的其他文件。多个模式可以用逗号分隔(例如,“test/ ,*.spec.js”、“node_modules/ ,dist/**”)。这些模式是对 .gitignore 和内置排除规则的补充。
    • topFilesLength :(可选,默认值:10)代码库分析的指标摘要中显示的最大文件数。
  1. pack_remote_repository :获取、克隆并将 GitHub 存储库打包到合并的 XML 文件中,用于 AI 分析
  • 参数:
    • remote :GitHub 存储库 URL 或 user/repo 格式(例如,“yamadashy/repomix”、“ https://github.com/user/repo ”或“ https://github.com/user/repo/tree/branch ”)
    • compress :(可选,默认值:false)启用 Tree-sitter 压缩功能,提取必要的代码签名和结构,同时移除实现细节。在保留语义含义的同时,可减少约 70% 的 token 使用量。由于 grep_repomix_output 允许增量内容检索,因此通常不需要使用。仅在您明确需要获取大型代码库的完整代码库内容时使用。
    • includePatterns :(可选)使用快速全局模式指定要包含的文件。多个模式可以用逗号分隔(例如,“ /*.{js,ts}”、“src/ ,docs/**”)。只有匹配的文件才会被处理。
    • ignorePatterns :(可选)使用快速全局模式指定要排除的其他文件。多个模式可以用逗号分隔(例如,“test/ ,*.spec.js”、“node_modules/ ,dist/**”)。这些模式是对 .gitignore 和内置排除规则的补充。
    • topFilesLength :(可选,默认值:10)代码库分析的指标摘要中显示的最大文件数。
  1. read_repomix_output :读取 Repomix 生成的输出文件的内容。对于大文件,支持指定行范围的部分读取。
  • 参数:
    • outputId :要读取的 Repomix 输出文件的 ID
    • startLine :(可选)起始行号(从 1 开始,包含 1)。如果未指定,则从头开始读取。
    • endLine :(可选)结束行号(从 1 开始,包含 1)。若未指定,则读至结束。
  • 特征:
    • 专为基于 Web 的环境或沙盒应用程序设计
    • 使用 ID 检索先前生成的输出的内容
    • 提供对打包代码库的安全访问,无需访问文件系统
    • 支持大文件的部分读取
  1. grep_repomix_output :使用类似 grep 的功能和 JavaScript RegExp 语法在 Repomix 输出文件中搜索模式
  • 参数:
    • outputId :要搜索的 Repomix 输出文件的 ID
    • pattern :搜索模式(JavaScript RegExp 正则表达式语法)
    • contextLines :(可选,默认值:0)每次匹配前后显示的上下文行数。如果指定,则由 beforeLines/afterLines 覆盖。
    • beforeLines :(可选)每次匹配前显示的上下文行数(类似 grep -B)。优先级高于 contextLines。
    • afterLines :(可选)每次匹配后显示的上下文行数(类似 grep -A)。优先级高于 contextLines。
    • ignoreCase :(可选,默认值:false)执行不区分大小写的匹配
  • 特征:
    • 使用 JavaScript RegExp 语法实现强大的模式匹配
    • 支持上下文行以便更好地理解匹配
    • 允许单独控制前后上下文行
    • 区分大小写和不区分大小写的搜索选项
  1. file_system_read_file :使用绝对路径从本地文件系统读取文件。包含内置安全验证,用于检测并阻止访问包含敏感信息的文件。
  • 参数:
    • path :要读取的文件的绝对路径
  • 安全功能:
    • 使用Secretlint实现安全验证
    • 防止访问包含敏感信息(API 密钥、密码、机密)的文件
    • 验证绝对路径以防止目录遍历攻击
  1. file_system_read_directory :使用绝对路径列出目录内容。返回一个格式化的列表,其中显示文件和子目录,并带有清晰的指示符。
  • 参数:
    • path :要列出的目录的绝对路径
  • 特征:
    • 用清晰的指示符显示文件和目录( [FILE][DIR]
    • 提供安全的目录遍历和适当的错误处理
    • 验证路径并确保它们是绝对的
    • 有助于探索项目结构和理解代码库组织

⚙️ 配置

在项目根目录中创建一个repomix.config.json文件以进行自定义配置。

repomix --init

以下是配置选项的解释:

选项描述默认
input.maxFileSize需要处理的最大文件大小(以字节为单位)。大于此大小的文件将被跳过50000000
output.filePath输出文件的名称"repomix-output.xml"
output.style输出的样式( xmlmarkdownplain"xml"
output.parsableStyle是否根据所选样式架构对输出进行转义。请注意,这可能会增加标记数量。false
output.compress是否执行智能代码提取以减少令牌数量false
output.headerText包含在文件头中的自定义文本null
output.instructionFilePath包含详细自定义说明的文件路径null
output.fileSummary是否在输出的开头包含摘要部分true
output.directoryStructure是否在输出中包含目录结构true
output.files是否在输出中包含文件内容true
output.removeComments是否从支持的文件类型中删除评论false
output.removeEmptyLines是否从输出中删除空行false
output.showLineNumbers是否为输出中的每一行添加行号false
output.copyToClipboard除了保存文件之外,是否还将输出复制到系统剪贴板false
output.topFilesLength摘要中显示的顶级文件数。如果设置为 0,则不显示摘要5
output.includeEmptyDirectories是否在存储库结构中包含空目录false
output.git.sortByChanges是否按 git 更改计数对文件进行排序(更改较多的文件显示在底部)true
output.git.sortByChangesMaxCommits需要分析 git 更改的最大提交数100
output.git.includeDiffs是否在输出中包含 git diff(分别包含工作树和暂存更改)false
include要包含的文件模式(使用glob 模式[]
ignore.useGitignore是否使用项目.gitignore文件中的模式true
ignore.useDefaultPatterns是否使用默认忽略模式true
ignore.customPatterns要忽略的其他模式(使用glob 模式[]
security.enableSecurityCheck是否对文件进行安全检查true
tokenCount.encodingOpenAI 的tiktoken分词器使用的分词计数编码(例如,GPT-4o 的o200k_base ,GPT-4/3.5 的cl100k_base )。有关编码详细信息,请参阅tiktoken model.py"o200k_base"

该配置文件支持JSON5语法,允许:

  • 注释(单行和多行)
  • 对象和数组中的尾随逗号
  • 不带引号的属性名称
  • 更宽松的字符串语法

示例配置:

{ "input": { "maxFileSize": 50000000 }, "output": { "filePath": "repomix-output.xml", "style": "xml", "parsableStyle": false, "compress": false, "headerText": "Custom header information for the packed file.", "fileSummary": true, "directoryStructure": true, "files": true, "removeComments": false, "removeEmptyLines": false, "topFilesLength": 5, "showLineNumbers": false, "copyToClipboard": false, "includeEmptyDirectories": false, "git": { "sortByChanges": true, "sortByChangesMaxCommits": 100, "includeDiffs": false } }, "include": ["**/*"], "ignore": { "useGitignore": true, "useDefaultPatterns": true, // Patterns can also be specified in .repomixignore "customPatterns": [ "additional-folder", "**/*.log" ], }, "security": { "enableSecurityCheck": true }, "tokenCount": { "encoding": "o200k_base" } }

全局配置

要创建全局配置文件:

repomix --init --global

全局配置文件将在以下位置创建:

  • Windows: %LOCALAPPDATA%\Repomix\repomix.config.json
  • macOS/Linux: $XDG_CONFIG_HOME/repomix/repomix.config.json~/.config/repomix/repomix.config.json

注意:本地配置(如果存在)优先于全局配置。

包含和忽略

包含模式

Repomix 现在支持使用glob 模式指定要包含的文件。这允许更灵活、更强大的文件选择:

  • 使用**/*.js包含任意目录中的所有 JavaScript 文件
  • 使用src/**/*包含src目录及其子目录中的所有文件
  • 组合多个模式,如["src/**/*.js", "**/*.md"]以在src和所有 Markdown 文件中包含 JavaScript 文件
忽略模式

Repomix 提供了多种方法来设置忽略模式,以便在打包过程中排除特定的文件或目录:

  • .gitignore :默认情况下,使用项目.gitignore文件和.git/info/exclude中列出的模式。您可以使用ignore.useGitignore设置或--no-gitignore cli 选项来控制此行为。
  • 默认模式:Repomix 包含一个默认的常见排除文件和目录列表(例如,node_modules、.git、二进制文件)。此功能可以通过ignore.useDefaultPatterns设置或--no-default-patterns命令行选项控制。更多详情请参阅defaultIgnore.ts 文件
  • .repomixignore :您可以在项目根目录中创建一个.repomixignore文件,以定义特定于 Repomix 的忽略模式。此文件遵循与.gitignore相同的格式。
  • 自定义模式:可以使用配置文件中的ignore.customPatterns选项指定其他忽略模式。您可以使用-i, --ignore命令行选项覆盖此设置。

优先顺序(从高到低):

  1. 自定义模式ignore.customPatterns
  2. .repomixignore
  3. .gitignore.git/info/exclude (如果ignore.useGitignore为 true 且未使用--no-gitignore
  4. 默认模式(如果ignore.useDefaultPatterns为 true 并且未使用--no-default-patterns

此方法允许您根据项目需求灵活地配置文件排除。它通过确保排除安全敏感文件和大型二进制文件,从而优化生成的包文件的大小,同时防止机密信息泄露。

注意:默认情况下,二进制文件不包含在打包输出中,但它们的路径列在输出文件的“存储库结构”部分。这提供了存储库结构的完整概述,同时保持了打包文件的高效性和基于文本的特性。

定制指令

output.instructionFilePath选项允许您指定一个单独的文件,其中包含有关项目的详细说明或上下文。这使得 AI 系统能够理解项目的具体背景和要求,从而可能提供更相关、更有针对性的分析或建议。

以下是如何使用此功能的示例:

  1. 在项目根目录中创建一个名为repomix-instruction.md的文件:
# Coding Guidelines - Follow the Airbnb JavaScript Style Guide - Suggest splitting files into smaller, focused units when appropriate - Add comments for non-obvious logic. Keep all text in English - All new features should have corresponding unit tests # Generate Comprehensive Output - Include all content without abbreviation, unless specified otherwise - Optimize for handling large codebases while maintaining output quality
  1. 在您的repomix.config.json中,添加instructionFilePath选项:
{ "output": { "instructionFilePath": "repomix-instruction.md", // other options... } }

当 Repomix 生成输出时,它将在专用部分中包含repomix-instruction.md的内容。

注意:指令内容附加在输出文件的末尾。这种放置方式对于人工智能系统尤其有效。对于那些有兴趣了解这种做法为何有益的人,Anthropic 在其文档中提供了一些见解:
https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/long-context-tips

将长格式数据放在顶部:将长文档和输入(约 2 万多个词法单元)放在提示顶部附近,即查询、说明和示例的上方。这可以显著提升 Claude 在所有模型上的性能。查询放在末尾可以将测试中的响应质量提高高达 30%,尤其是在处理复杂的多文档输入时。

删除评论

output.removeComments设置为true时,Repomix 将尝试从支持的文件类型中删除注释。此功能有助于减小输出文件的大小,并专注于必要的代码内容。

支持的语言包括:
HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell 和 YAML。

注意:注释删除过程较为保守,以避免意外删除代码。在复杂情况下,部分注释可能会被保留。

🔍 安全检查

Repomix 包含一项安全检查功能,该功能使用Secretlint检测文件中潜在的敏感信息。此功能可帮助您在共享打包的存储库之前识别潜在的安全风险。

打包过程完成后,安全检查结果将显示在 CLI 输出中。如果检测到任何可疑文件,您将看到这些文件的列表以及一条警告消息。

示例输出:

🔍 Security Check: ────────────────── 2 suspicious file(s) detected: 1. src/utils/test.txt 2. tests/utils/secretLintUtils.test.ts Please review these files for potentially sensitive information.

默认情况下,Repomix 的安全检查功能处于启用状态。您可以通过在配置文件中将security.enableSecurityCheck设置为false来禁用它:

{ "security": { "enableSecurityCheck": false } }

或者使用--no-security-check命令行选项:

repomix --no-security-check

禁用安全检查可能会泄露敏感信息。请谨慎使用此选项,且仅在必要时使用,例如处理包含示例凭据的测试文件或文档时。

🤖 将 Repomix 与 GitHub Actions 结合使用

您还可以在 GitHub Actions 工作流程中使用 Repomix。这对于自动化打包代码库以进行 AI 分析的过程非常有用。

基本用法:

- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomix@main with: output: repomix-output.xml style: xml

使用--style生成不同格式的输出:

- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomix@main with: output: repomix-output.md style: markdown

使用压缩打包特定目录:

- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomix@main with: directories: src tests include: "**/*.ts,**/*.md" ignore: "**/*.test.ts" output: repomix-output.txt compress: true

将输出文件作为工件上传:

- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomix@main with: directories: src output: repomix-output.txt compress: true - name: Upload Repomix output uses: actions/upload-artifact@v4 with: name: repomix-output path: repomix-output.txt

完整工作流程示例:

name: Pack repository with Repomix on: workflow_dispatch: push: branches: [ main ] pull_request: branches: [ main ] jobs: pack-repo: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomix@main with: output: repomix-output.xml - name: Upload Repomix output uses: actions/upload-artifact@v4 with: name: repomix-output.xml path: repomix-output.xml retention-days: 30

请参阅此处的完整工作流程示例。

动作输入

姓名描述默认
directories要处理的目录的空格分隔列表(例如, src tests docs.
include以逗号分隔的 glob 模式包含文件(例如, **/*.ts,**/*.md""
ignore使用逗号分隔的 glob 模式来忽略文件(例如, **/*.test.ts,**/node_modules/**""
output打包文件的相对路径(扩展名决定格式: .txt.md.xmlrepomix-output.xml
compress通过修剪实现细节来启用智能压缩以减少输出大小true
style输出样式( xmlmarkdownplainxml
additional-argsrepomix CLI 的额外原始参数(例如, --no-file-summary --no-security-check""
repomix-version要安装的 npm 包的版本(支持 semver 范围、标签或特定版本,如0.2.25latest

动作输出

姓名描述
output_file生成的输出文件的路径。可用于后续步骤中的工件上传、LLM 处理或其他操作。该文件包含基于指定选项的代码库的格式化表示。

📚 使用 Repomix 作为库

除了将 Repomix 用作 CLI 工具之外,您还可以将其用作 Node.js 应用程序中的库。

安装

npm install repomix

基本用法

import { runCli, type CliOptions } from 'repomix'; // Process current directory with custom options async function packProject() { const options = { output: 'output.xml', style: 'xml', compress: true, quiet: true } as CliOptions; const result = await runCli(['.'], process.cwd(), options); return result.packResult; }

处理远程存储库

import { runCli, type CliOptions } from 'repomix'; // Clone and process a GitHub repo async function processRemoteRepo(repoUrl) { const options = { remote: repoUrl, output: 'output.xml', compress: true } as CliOptions; return await runCli(['.'], process.cwd(), options); }

使用核心组件

如果您需要更多控制,您可以使用低级 API:

import { searchFiles, collectFiles, processFiles, TokenCounter } from 'repomix'; async function analyzeFiles(directory) { // Find and collect files const { filePaths } = await searchFiles(directory, { /* config */ }); const rawFiles = await collectFiles(filePaths, directory); const processedFiles = await processFiles(rawFiles, { /* config */ }); // Count tokens const tokenCounter = new TokenCounter('o200k_base'); // Return analysis results return processedFiles.map(file => ({ path: file.path, tokens: tokenCounter.countTokens(file.content) })); }

有关更多示例,请查看website/server/src/remoteRepo.ts上的源代码,其中演示了 repomix.com 如何使用该库。

🤝 贡献

我们欢迎社区的贡献!请参考我们的贡献指南,开始您的贡献之旅。

贡献者

🔒 隐私政策

Repomix CLI 工具

  • 数据收集:Repomix CLI 工具不会收集、传输或存储任何用户数据、遥测或存储库信息。
  • 网络使用:Repomix CLI 安装后可完全离线运行。以下情况才需要网络连接:
    • 通过 npm/yarn 安装。
    • 使用--remote标志来处理远程存储库。
    • 检查更新(手动触发)。
  • 安全注意事项:由于所有处理都是本地的,因此 Repomix CLI 可以安全地与私有和内部存储库一起使用。

Repomix 网站( repomix.com

  • 数据收集:Repomix 网站使用Google Analytics收集使用数据,例如页面浏览量和用户互动。这有助于我们了解网站的使用情况并改善用户体验。

责任免责声明

Repomix(CLI 工具和网站)按“原样”提供,不提供任何担保或保证。
我们不对生成的输出如何使用负责,包括但不限于其准确性、合法性或因其使用而产生的任何潜在后果。

📜 许可证

该项目已获得MIT 许可

Related MCP Servers

  • A
    security
    A
    license
    A
    quality
    The ArXiv MCP Server bridges the gap between AI models and academic research by providing a sophisticated interface to arXiv's extensive research repository. This server enables AI assistants to perform precise paper searches and access full paper content, enhancing their ability to engage with scientific literature.
    Last updated -
    4
    1,218
    Python
    Apache 2.0
    • Linux
    • Apple
  • -
    security
    F
    license
    -
    quality
    🔍 Enable AI assistants to search and access bioRxiv papers through a simple MCP interface. The bioRxiv MCP Server provides a bridge between AI assistants and bioRxiv's preprint repository through the Model Context Protocol (MCP). It allows AI models to search for biology preprints and access their
    Last updated -
    4
    Python
    • Linux
    • Apple
  • -
    security
    F
    license
    -
    quality
    🔍 Enable AI assistants to search and access medRxiv papers through a simple MCP interface. The medRxiv MCP Server provides a bridge between AI assistants and medRxiv's preprint repository through the Model Context Protocol (MCP). It allows AI models to search for health sciences preprints and acce
    Last updated -
    1
    Python
    • Linux
    • Apple
  • A
    security
    A
    license
    A
    quality
    An open-source MCP server that connects to various data sources (SQL databases, CSV, Parquet files), allowing AI models to execute SQL queries and generate data visualizations for analytics and business intelligence.
    Last updated -
    10
    35
    Python
    MIT License
    • Linux
    • Apple

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yamadashy/repomix'

If you have feedback or need assistance with the MCP directory API, please join our Discord server