一、软件介绍
文末提供程序和源码下载学习
Repomix开源程序可以可以整个代码成一个单一文件、适合需要将代码输入大型语言模型(LLMs)或其他 AI 工具,如 DeepSeek等的开源程序。
二、软件特点
- AI 优化:以 AI 易于理解和处理的方式格式化您的代码库。
- 令牌计数:为每个文件和整个仓库提供令牌计数,对于LLM上下文限制很有用。
- 简单易用:只需一个命令即可打包您的整个仓库。
- 可定制:轻松配置要包含或排除的内容。
- Git 感知:自动尊重您的
.gitignore
文件和.git/info/exclude
。 - 安全优先:集成 Secretlint 进行强大的安全检查,以检测和防止敏感信息的包含。
- 代码压缩:
--compress
选项使用 Tree-sitter 提取关键代码元素,在保留结构的同时减少令牌数量。
三、快速开始
使用 CLI 工具
您可以在项目目录中立即尝试 Repomix,无需安装:
npx repomix
Or install globally for repeated use:
或者全局安装以供重复使用:
# 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
That's it! Repomix will generate a repomix-output.xml
file in your current directory, containing your entire repository in an AI-friendly format.
这就是了!Repomix 将在您的当前目录中生成一个文件,其中包含您的整个仓库,以 AI 友好的格式。
You can then send this file to an AI assistant with a prompt like:
您可以随后将此文件发送给 AI 助手,并附上如下提示:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>This file contains all the files in the repository combined into one.
I want to refactor the code, so please review it first.</code></span></span></span></span>
当你提出具体更改时,AI 可能能够相应地生成代码。凭借 Claude 的工件等特性,你可能会输出多个文件,从而生成多个相互依赖的代码片段。
替代工具
如果你使用 Python,你可能想看看 Gitingest
,它更适合 Python 生态系统和数据科学工作流程:https://github.com/cyclotruc/gitingest
使用说明
To pack your entire repository:
将您的整个仓库打包:
repomix
To pack a specific directory:
将特定目录打包:
repomix path/to/directory
To pack specific files or directories using glob patterns:
使用 glob 模式打包特定文件或目录:
repomix --include "src/**/*.ts,**/*.md"
To exclude specific files or directories:
要排除特定的文件或目录:
repomix --ignore "**/*.log,tmp/"
To pack a remote repository:
要打包远程仓库:
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
To compress the output:
压缩输出:
repomix --compress
# You can also use it with remote repositories:
repomix --remote yamadashy/repomix --compress
To initialize a new configuration file (repomix.config.json
):
初始化新的配置文件( repomix.config.json
):
repomix --init
Once you have generated the packed file, you can use it with Generative AI tools like ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok, and more.
一旦生成打包文件,您就可以使用它与 ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等生成式 AI 工具。
Docker 使用
您也可以使用 Docker 运行 Repomix。
This is useful if you want to run Repomix in an isolated environment or prefer using containers.
这在您想在一个隔离的环境中运行 Repomix 或偏好使用容器时非常有用。
Basic usage (current directory):
基本用法(当前目录):
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix
To pack a specific directory:
将特定目录打包:
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory
Process a remote repository and output to a output
directory:
处理远程仓库并将其输出到 output
目录:
docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote https://github.com/yamadashy/repomix
Prompt Examples 提示示例
Once you have generated the packed file with Repomix, you can use it with AI tools like ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok, and more. Here are some example prompts to get you started:
使用 Repomix 生成的打包文件后,您可以将其用于 ChatGPT、DeepSeek、Perplexity、Gemini、Gemma、Llama、Grok 等 AI 工具。以下是一些启动示例提示:
Code Review and Refactoring
代码审查和重构
For a comprehensive code review and refactoring suggestions:
为了全面的代码审查和重构建议:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>This file contains my entire codebase. Please review the overall structure and suggest any improvements or refactoring opportunities, focusing on maintainability and scalability.
</code></span></span></span></span>
Documentation Generation 文档生成
To generate project documentation:
生成项目文档:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>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.
</code></span></span></span></span>
Test Case Generation 测试用例生成
For generating test cases:
用于生成测试用例:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>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.
</code></span></span></span></span>
Code Quality Assessment 代码质量评估
Evaluate code quality and adherence to best practices:
评估代码质量和最佳实践遵循情况:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>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.
</code></span></span></span></span>
Library Overview 库概览
Get a high-level understanding of the library
获取对库的高级理解
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>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.
</code></span></span></span></span>
Feel free to modify these prompts based on your specific needs and the capabilities of the AI tool you're using.
请根据您的具体需求和所使用的 AI 工具的功能自由修改这些提示。
Output File Format 输出文件格式
Repomix generates a single file with clear separators between different parts of your codebase.
Repomix 会生成一个包含代码库不同部分清晰分隔符的单个文件。
To enhance AI comprehension, the output file begins with an AI-oriented explanation, making it easier for AI models to understand the context and structure of the packed repository.
为了增强 AI 的理解,输出文件以面向 AI 的解释开头,使 AI 模型更容易理解打包仓库的上下文和结构。
XML Format (default) XML 格式(默认)
The XML format structures the content in a hierarchical manner:
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>
For those interested in the potential of XML tags in AI contexts:
对于对在 AI 环境中 XML 标签的潜力感兴趣的人:
Use XML tags to structure your prompts - Anthropic
When your prompts involve multiple components like context, instructions, and examples, XML tags can be a game-changer. They help Claude parse your prompts more accurately, leading to higher-quality outputs.
当你的提示涉及多个组件,如上下文、指令和示例时,XML 标签可以成为游戏规则的改变者。它们帮助 Claude 更准确地解析你的提示,从而产生更高质量的输出。
This means that the XML output from Repomix is not just a different format, but potentially a more effective way to feed your codebase into AI systems for analysis, code review, or other tasks.
这意味着 Repomix 生成的 XML 输出不仅是一种不同的格式,而且可能是将您的代码库输入 AI 系统进行分析、代码审查或其他任务的一种更有效的方法。
Markdown Format Markdown 格式
To generate output in Markdown format, use the --style markdown
option:
要生成 Markdown 格式的输出,请使用 --style markdown
选项:
repomix --style markdown
The Markdown format structures the content in a hierarchical manner:
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`)
This format provides a clean, readable structure that is both human-friendly and easily parseable by AI systems.
这种格式提供了一个干净、易读的结构,既适合人类阅读,也易于人工智能系统解析。
Plain Text Format 纯文本格式
To generate output in plain text format, use the --style plain
option:
要生成纯文本格式的输出,请使用 --style plain
选项:
repomix --style plain
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>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`)
</code></span></span></span></span>
Command Line Options 命令行选项
Basic Options 基本选项
-v, --version
: Show tool version
-v, --version
显示工具版本
Output Options 输出选项
-o, --output <file>
: Specify the output file name
指定输出文件名--style <style>
: Specify the output style (xml
,markdown
,plain
)
指定输出样式(xml
,markdown
,plain
)--parsable-style
: Enable parsable output based on the chosen style schema. Note that this can increase token count.
启用基于所选样式方案的解析输出。注意,这可能会增加令牌数量。--compress
: Perform intelligent code extraction, focusing on essential function and class signatures to reduce token count
执行智能代码提取,重点关注基本函数和类签名以减少令牌数量--output-show-line-numbers
: Show line numbers in the output
显示输出中的行号--copy
: Additionally copy generated output to system clipboard
此外,将生成的输出复制到系统剪贴板--no-file-summary
: Disable file summary section output
禁用文件摘要部分输出--no-directory-structure
: Disable directory structure section output
禁用目录结构部分输出--remove-comments
: Remove comments from supported file types
--remove-comments
: 从支持的文件类型中删除注释--remove-empty-lines
: Remove empty lines from the output
--remove-empty-lines
: 从输出中删除空行--header-text <text>
: Custom text to include in the file header
--header-text <text>
:文件头部包含的自定义文本--instruction-file-path <path>
: Path to a file containing detailed custom instructions
--instruction-file-path <path>
: 文件路径,包含详细的自定义指令--include-empty-directories
: Include empty directories in the output
--include-empty-directories
: 在输出中包含空目录--no-git-sort-by-changes
: Disable sorting files by git change count (enabled by default)
--no-git-sort-by-changes
: 禁用按 git 更改次数排序文件(默认启用)
Filter Options 过滤选项
--include <patterns>
: List of include patterns (comma-separated)
--include <patterns>
: 包含模式列表(逗号分隔)-i, --ignore <patterns>
: Additional ignore patterns (comma-separated)
-i, --ignore <patterns>
: 额外忽略模式(逗号分隔)--no-gitignore
: Disable .gitignore file usage
--no-gitignore
: 禁用 .gitignore 文件使用--no-default-patterns
: Disable default patterns
--no-default-patterns
: 禁用默认模式
Remote Repository Options
远程仓库选项
--remote <url>
: Process a remote Git repository
--remote <url>
: 处理远程 Git 仓库--remote-branch <name>
: Specify the remote branch name, tag, or commit hash (defaults to repository default branch)
--remote-branch <name>
: 指定远程分支名称、标签或提交哈希(默认为仓库默认分支)
Configuration Options 配置选项
-c, --config <path>
: Path to a custom config file
-c, --config <path>
: 自定义配置文件路径--init
: Create config file
--init
: 创建配置文件--global
: Use global config
--global
: 使用全局配置
Security Options 安全选项
--no-security-check
: Disable security check
--no-security-check
: 禁用安全检查
Token Count Options 令牌计数选项
--token-count-encoding <encoding>
: Specify token count encoding used by OpenAI's tiktoken tokenizer (e.g.,o200k_base
for GPT-4o,cl100k_base
for GPT-4/3.5). See tiktoken model.py for encoding details.
指定 OpenAI 的 tiktoken 分词器使用的令牌计数编码(例如,o200k_base
用于 GPT-4o,cl100k_base
用于 GPT-4/3.5)。请参阅 tiktoken 模型.py 文件以获取编码详细信息。
MCP
--mcp
: Run as a MCP (Model Context Protocol) server
--mcp
: 运行为 MCP(模型上下文协议)服务器
Other Options 其他选项
--top-files-len <number>
: Number of top files to display in the summary
--top-files-len <number>
: 在摘要中显示的顶级文件数量--verbose
: Enable verbose logging
--verbose
: 启用详细日志记录--quiet
: Disable all output to stdout
--quiet
: 禁用所有输出到 stdout
Examples: 示例:
repomix -o custom-output.txt
repomix -i "*.log,tmp" -v
repomix -c ./custom-config.json
repomix --style xml
repomix --remote https://github.com/user/repo
npx repomix src
Updating Repomix 更新 Repomix
To update a globally installed Repomix:
更新全局安装的 Repomix:
# Using npm
npm update -g repomix
# Using yarn
yarn global upgrade repomix
Using npx repomix
is generally more convenient as it always uses the latest version.
使用 npx repomix
通常更方便,因为它总是使用最新版本。
Remote Repository Processing
远程仓库处理
Repomix supports processing remote Git repositories without the need for manual cloning. This feature allows you to quickly analyze any public Git repository with a single command.
Repomix 支持处理远程 Git 仓库,无需手动克隆。此功能允许您通过单个命令快速分析任何公共 Git 仓库。
To process a remote repository, use the --remote
option followed by the repository URL:
要处理远程仓库,请使用 --remote
选项后跟仓库 URL:
repomix --remote https://github.com/yamadashy/repomix
You can also use GitHub's shorthand format:
您还可以使用 GitHub 的简写格式:
repomix --remote yamadashy/repomix
You can specify the branch name, tag, or commit hash:
您可以指定分支名称、标签或提交哈希:
# 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
Or use a specific commit hash:
或使用特定的提交哈希值:
# 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
Code Compression 代码压缩
The --compress
option utilizes Tree-sitter to perform intelligent code extraction, focusing on essential function and class signatures while removing implementation details. This can help reduce token count while retaining important structural information.
该 --compress
选项利用 Tree-sitter 进行智能代码提取,专注于关键函数和类签名,同时移除实现细节。这有助于减少令牌数量,同时保留重要的结构信息。
repomix --compress
For example, this code:
例如,这段代码:
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;
}
Will be compressed to:
将被压缩为:
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 注意
This is an experimental feature that we'll be actively improving based on user feedback and real-world usage
这是一个我们将根据用户反馈和实际使用情况进行积极改进的实验性功能
MCP Server Integration MCP 服务器集成
Repomix supports the Model Context Protocol (MCP), allowing AI assistants to directly interact with your codebase. When run as an MCP server, Repomix provides tools that enable AI assistants to package local or remote repositories for analysis without requiring manual file preparation.
Repomix 支持模型上下文协议(MCP),允许 AI 助手直接与您的代码库交互。当作为 MCP 服务器运行时,Repomix 提供工具,使 AI 助手能够打包本地或远程仓库以进行分析,无需手动准备文件。
repomix --mcp
Configuring MCP Servers 配置 MCP 服务器
To use Repomix as an MCP server with AI assistants like Claude, you need to configure the MCP settings:
要将 Repomix 配置为 AI 助手(如 Claude)的 MCP 服务器,您需要配置 MCP 设置:
For VS Code: 对于 VS Code:
You can install the Repomix MCP server in VS Code using one of these methods:
您可以使用以下方法之一在 VS Code 中安装 Repomix MCP 服务器:
-
Using the Install Badge: 使用安装徽章:
Install in VS Code Install in VS Code Insiders
-
Using the Command Line: 使用命令行:
code --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'
For VS Code Insiders:
为 VS Code 内部测试版用户:code-insiders --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'
For Cline (VS Code extension):
为 Cline(VS Code 扩展):
Edit the cline_mcp_settings.json
file: 编辑 cline_mcp_settings.json
文件:
{
"mcpServers": {
"repomix": {
"command": "npx",
"args": [
"-y",
"repomix",
"--mcp"
]
}
}
}
For Cursor: 为光标:
In Cursor, add a new MCP server from Cursor Settings
> MCP
> + Add new global MCP server
with a configuration similar to Cline.
在 Cursor 中,从 Cursor Settings
> MCP
> + Add new global MCP server
添加一个与 Cline 配置类似的新 MCP 服务器。
For Claude Desktop: 为 Claude 桌面版:
Edit the claude_desktop_config.json
file with similar configuration to Cline's config.
编辑与 Cline 的配置相似的 claude_desktop_config.json
文件。
Once configured, your AI assistant can directly use Repomix's capabilities to analyze codebases without manual file preparation, making code analysis workflows more efficient.
一旦配置完成,您的 AI 助手可以直接使用 Repomix 的功能来分析代码库,无需手动准备文件,使代码分析工作流程更加高效。
Available MCP Tools 可用 MCP 工具
When running as an MCP server, Repomix provides the following tools:
作为 MCP 服务器运行时,Repomix 提供以下工具:
- pack_codebase: Package a local code directory into a consolidated file for AI analysis
将本地代码目录打包成一个用于 AI 分析的整合文件
- Parameters: 参数:
directory
: Absolute path to the directory to pack
打包的目录的绝对路径compress
: (Optional, default: true) Whether to perform intelligent code extraction
(可选,默认:true)是否执行智能代码提取includePatterns
: (Optional) Comma-separated list of include patterns
(可选)逗号分隔的包含模式列表ignorePatterns
: (Optional) Comma-separated list of ignore patterns
(可选)逗号分隔的忽略模式列表
- pack_remote_repository: Fetch, clone and package a GitHub repository
获取、克隆并打包 GitHub 仓库
- Parameters: 参数:
remote
: GitHub repository URL or user/repo format (e.g., yamadashy/repomix)
GitHub 仓库 URL 或用户/仓库名格式(例如:yamadashy/repomix)compress
: (Optional, default: true) Whether to perform intelligent code extraction
(可选,默认:true)是否执行智能代码提取includePatterns
: (Optional) Comma-separated list of include patterns
(可选)逗号分隔的包含模式列表ignorePatterns
: (Optional) Comma-separated list of ignore patterns
(可选)逗号分隔的忽略模式列表
- read_repomix_output: Read the contents of a Repomix output file in environments where direct file access is not possible
读取 Repomix 输出文件内容,在无法直接访问文件的环境中
- Parameters: 参数:
outputId
: ID of the Repomix output file to read
outputId
: 读取的 Repomix 输出文件 ID
- Features: 功能:
- Specifically designed for web-based environments or sandboxed applications
专为基于 Web 的环境或沙箱应用程序设计 - Retrieves the content of previously generated outputs using their ID
检索使用其 ID 之前生成的输出内容 - Provides secure access to packed codebase without requiring file system access
提供对打包代码库的安全访问,无需文件系统访问
- Specifically designed for web-based environments or sandboxed applications
- file_system_read_file: Read a file using an absolute path with security validation
file_system_read_file: 使用绝对路径以安全验证读取文件
- Parameters: 参数:
path
: Absolute path to the file to read
path
: 文件的绝对路径
- Security features: 安全特性:
- Implements security validation using Secretlint
实现使用 Secretlint 进行安全验证 - Prevents access to files containing sensitive information
阻止访问包含敏感信息的文件 - Validates absolute paths to prevent directory traversal attacks
验证绝对路径以防止目录遍历攻击
- Implements security validation using Secretlint
- file_system_read_directory: List contents of a directory using an absolute path
file_system_read_directory: 使用绝对路径列出目录内容
- Parameters: 参数:
path
: Absolute path to the directory to list
path
: 列出目录的绝对路径
- Features: 功能:
- Shows files and directories with clear indicators (
[FILE]
or[DIR]
)
以清晰的指示符显示文件和目录([FILE]
或[DIR]
) - Provides safe directory traversal with proper error handling
提供安全的目录遍历,并具有适当的错误处理 - Validates paths and ensures they are absolute
验证路径并确保它们是绝对路径
- Shows files and directories with clear indicators (
Configuration ⚙️ 配置
创建一个文件在项目根目录下进行自定义配置。
repomix --init
Here's an explanation of the configuration options:
这里是对配置选项的解释:
Option 选项 | Description 描述 | Default 默认 |
---|---|---|
output.filePath | The name of the output file 输出文件名 | "repomix-output.xml" |
output.style | The style of the output (xml , markdown , plain )输出样式( xml , markdown , plain ) | "xml" |
output.parsableStyle | Whether to escape the output based on the chosen style schema. Note that this can increase token count. 是否根据所选样式架构对输出进行转义。请注意,这可能会增加令牌计数。 | false |
output.compress | Whether to perform intelligent code extraction to reduce token count 是否执行智能代码提取以减少令牌计数 | false |
output.headerText | Custom text to include in the file header 自定义文本以包含在文件标题中 | null |
output.instructionFilePath | Path to a file containing detailed custom instructions 文件包含详细自定义指令的路径 | null |
output.fileSummary | Whether to include a summary section at the beginning of the output 是否在输出的开头包含摘要部分 | true |
output.directoryStructure | Whether to include the directory structure in the output 是否包含目录结构在输出中 | true |
output.removeComments | Whether to remove comments from supported file types 是否从支持的文件类型中删除注释 | false |
output.removeEmptyLines | Whether to remove empty lines from the output 是否从输出中删除空行 | false |
output.showLineNumbers | Whether to add line numbers to each line in the output 是否在输出中为每行添加行号 | false |
output.copyToClipboard | Whether to copy the output to system clipboard in addition to saving the file 是否在保存文件的同时将输出复制到系统剪贴板 | false |
output.topFilesLength | Number of top files to display in the summary. If set to 0, no summary will be displayed 在摘要中显示的文件数量排名。如果设置为 0,则不显示摘要 | 5 |
output.includeEmptyDirectories | Whether to include empty directories in the repository structure 是否在存储库结构中包含空目录 | false |
output.git.sortByChanges | Whether to sort files by git change count (files with more changes appear at the bottom) 是否按 git 变更次数排序文件(变更次数更多的文件排在底部) | true |
output.git.sortByChangesMaxCommits | Maximum number of commits to analyze for git changes 分析 git 变更的最大提交数 | 100 |
include | Patterns of files to include (using glob patterns) 要包含的文件的模式(使用 glob 模式) | [] |
ignore.useGitignore | Whether to use patterns from the project's .gitignore file是否使用项目的 .gitignore 文件中的模式 | true |
ignore.useDefaultPatterns | Whether to use default ignore patterns 是否使用默认忽略模式 | true |
ignore.customPatterns | Additional patterns to ignore (using glob patterns) 要忽略的额外模式(使用 glob 模式) | [] |
security.enableSecurityCheck | Whether to perform security checks on files 是否对文件执行安全检查 | true |
tokenCount.encoding | Token count encoding used by OpenAI's tiktoken tokenizer (e.g., o200k_base for GPT-4o, cl100k_base for GPT-4/3.5). See tiktoken model.py for encoding details.OpenAI 的 tiktoken 分词器使用的 token 计数编码(例如, o200k_base 代表 GPT-4o, cl100k_base 代表 GPT-4/3.5)。请参阅 tiktoken 模型中的 model.py 文件以获取编码细节。 | "o200k_base" |
The configuration file supports JSON5 syntax, which allows:
配置文件支持 JSON5 语法,允许:
- Comments (both single-line and multi-line)
注释(单行和多行注释) - Trailing commas in objects and arrays
对象和数组中的尾随逗号 - Unquoted property names 未引用的属性名
- More relaxed string syntax
更宽松的字符串语法
Example configuration: 示例配置:
{
"output": {
"filePath": "repomix-output.xml",
"style": "xml",
"parsableStyle": true,
"compress": false,
"headerText": "Custom header information for the packed file.",
"fileSummary": true,
"directoryStructure": true,
"removeComments": false,
"removeEmptyLines": false,
"showLineNumbers": false,
"copyToClipboard": true,
"topFilesLength": 5,
"includeEmptyDirectories": false,
"git": {
"sortByChanges": true,
"sortByChangesMaxCommits": 100
}
},
"include": [
"**/*"
],
"ignore": {
"useGitignore": true,
"useDefaultPatterns": true,
// Patterns can also be specified in .repomixignore
"customPatterns": [
"additional-folder",
"**/*.log"
],
},
"security": {
"enableSecurityCheck": true
},
"tokenCount": {
"encoding": "o200k_base"
},
}
Global Configuration 全局配置
To create a global configuration file:
创建全局配置文件:
repomix --init --global
The global configuration file will be created in:
全局配置文件将在以下位置创建:
- Windows:
%LOCALAPPDATA%\Repomix\repomix.config.json
- macOS/Linux:
$XDG_CONFIG_HOME/repomix/repomix.config.json
or~/.config/repomix/repomix.config.json
macOS/Linux:$XDG_CONFIG_HOME/repomix/repomix.config.json
或~/.config/repomix/repomix.config.json
Note: Local configuration (if present) takes precedence over global configuration.
注意:本地配置(如果存在)优先于全局配置。
Include and Ignore 包含和忽略
Include Patterns 包含模式
Repomix now supports specifying files to include using glob patterns. This allows for more flexible and powerful file selection:
Repomix 现在支持使用 glob 模式指定要包含的文件。这允许更灵活和强大的文件选择:
- Use
**/*.js
to include all JavaScript files in any directory
使用**/*.js
包含任何目录中的所有 JavaScript 文件 - Use
src/**/*
to include all files within thesrc
directory and its subdirectories
使用src/**/*
包含src
目录及其子目录中的所有文件 - Combine multiple patterns like
["src/**/*.js", "**/*.md"]
to include JavaScript files insrc
and all Markdown files
组合多个模式,如["src/**/*.js", "**/*.md"]
,以包含src
中的 JavaScript 文件和所有 Markdown 文件
Ignore Patterns 忽略模式
Repomix offers multiple methods to set ignore patterns for excluding specific files or directories during the packing process:
Repomix 提供多种方法来设置忽略模式,以在打包过程中排除特定的文件或目录:
- .gitignore: By default, patterns listed in your project's
.gitignore
files and.git/info/exclude
are used. This behavior can be controlled with theignore.useGitignore
setting or the--no-gitignore
cli option.
默认情况下,使用项目中的.gitignore
文件和.git/info/exclude
列出的模式。此行为可以通过ignore.useGitignore
设置或--no-gitignore
命令行选项进行控制。 - Default patterns: Repomix includes a default list of commonly excluded files and directories (e.g., node_modules, .git, binary files). This feature can be controlled with the
ignore.useDefaultPatterns
setting or the--no-default-patterns
cli option. Please see defaultIgnore.ts for more details.
默认模式:Repomix 包含一个默认的常用排除文件和目录列表(例如 node_modules、.git、二进制文件)。此功能可以通过ignore.useDefaultPatterns
设置或--no-default-patterns
命令行选项进行控制。请参阅 defaultIgnore.ts 获取更多详细信息。 - .repomixignore: You can create a
.repomixignore
file in your project root to define Repomix-specific ignore patterns. This file follows the same format as.gitignore
.
.repomixignore:您可以在项目根目录中创建一个.repomixignore
文件来定义 Repomix 特定的忽略模式。此文件遵循与.gitignore
相同的格式。 - Custom patterns: Additional ignore patterns can be specified using the
ignore.customPatterns
option in the configuration file. You can overwrite this setting with the-i, --ignore
command line option.
自定义模式:可以通过配置文件中的ignore.customPatterns
选项指定额外的忽略模式。您可以使用-i, --ignore
命令行选项覆盖此设置。
Priority Order (from highest to lowest):
优先级顺序(从高到低):
- Custom patterns
ignore.customPatterns
自定义模式ignore.customPatterns
.repomixignore
.gitignore
and.git/info/exclude
(ifignore.useGitignore
is true and--no-gitignore
is not used)
.gitignore
和.git/info/exclude
(如果ignore.useGitignore
为真且--no-gitignore
未使用)- Default patterns (if
ignore.useDefaultPatterns
is true and--no-default-patterns
is not used)
默认模式(如果ignore.useDefaultPatterns
为真且--no-default-patterns
未使用)
This approach allows for flexible file exclusion configuration based on your project's needs. It helps optimize the size of the generated pack file by ensuring the exclusion of security-sensitive files and large binary files, while preventing the leakage of confidential information.
此方法允许根据项目需求灵活配置文件排除配置。它通过确保排除安全敏感文件和大型二进制文件,同时防止机密信息泄露,有助于优化生成的打包文件的大小。
Note: Binary files are not included in the packed output by default, but their paths are listed in the "Repository Structure" section of the output file. This provides a complete overview of the repository structure while keeping the packed file efficient and text-based.
注意:默认情况下,打包输出不包括二进制文件,但它们的路径列在输出文件的“仓库结构”部分。这提供了对仓库结构的完整概述,同时保持打包文件高效且基于文本。
Custom Instruction 自定义指令
The output.instructionFilePath
option allows you to specify a separate file containing detailed instructions or context about your project. This allows AI systems to understand the specific context and requirements of your project, potentially leading to more relevant and tailored analysis or suggestions.
output.instructionFilePath
选项允许您指定一个包含关于您项目详细说明或背景信息的单独文件。这有助于 AI 系统理解您项目的具体背景和需求,从而可能导致更相关和定制的分析或建议。
Here's an example of how you might use this feature:
这是一个如何使用此功能的示例:
- Create a file named
repomix-instruction.md
in your project root:
创建一个名为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
- In your
repomix.config.json
, add theinstructionFilePath
option:
在你的repomix.config.json
中,添加instructionFilePath
选项:
{
"output": {
"instructionFilePath": "repomix-instruction.md",
// other options...
}
}
When Repomix generates the output, it will include the contents of repomix-instruction.md
in a dedicated section.
当 Repomix 生成输出时,它将在专用部分中包含 repomix-instruction.md
的内容。
Note: The instruction content is appended at the end of the output file. This placement can be particularly effective for AI systems. For those interested in understanding why this might be beneficial, Anthropic provides some insights in their documentation:
注意:指令内容附加在输出文件的末尾。这种放置方式对 AI 系统尤其有效。对于那些想了解为什么这可能有好处的人,Anthropic 在其文档中提供了一些见解:
Long context prompting tips - Anthropic
Put long-form data at the top: Place your long documents and inputs (~20K+ tokens) near the top of your prompt, above your query, instructions, and examples. This can significantly improve Claude's performance across all models. Queries at the end can improve response quality by up to 30% in tests, especially with complex, multi-document inputs.
将长格式数据置于顶部:将您的长文档和输入(20K+个 token)放置在提示、查询、指令和示例的上方。这可以显著提高 Claude 在所有模型上的性能。在测试中,将查询放在末尾可以提高响应质量高达 30%,尤其是在复杂的多文档输入中。
Comment Removal 评论移除
When output.removeComments
is set to true
, Repomix will attempt to remove comments from supported file types. This feature can help reduce the size of the output file and focus on the essential code content.
当 output.removeComments
设置为 true
时,Repomix 将尝试从支持的文件类型中移除注释。此功能可以帮助减小输出文件的大小,并专注于关键代码内容。
Supported languages include:
支持的语言包括:
HTML, CSS, JavaScript, TypeScript, Vue, Svelte, Python, PHP, Ruby, C, C#, Java, Go, Rust, Swift, Kotlin, Dart, Shell, and YAML.
HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell 和 YAML。
Note: The comment removal process is conservative to avoid accidentally removing code. In complex cases, some comments might be retained.
注意:注释移除过程是保守的,以避免意外删除代码。在复杂情况下,一些注释可能被保留。
🔍 Security Check 🔍 安全检查
Repomix includes a security check feature that uses Secretlint to detect potentially sensitive information in your files. This feature helps you identify possible security risks before sharing your packed repository.
Repomix 包含一个安全检查功能,该功能使用 Secretlint 在您的文件中检测可能敏感的信息。此功能有助于您在共享打包的仓库之前识别可能的安全风险。
The security check results will be displayed in the CLI output after the packing process is complete. If any suspicious files are detected, you'll see a list of these files along with a warning message.
打包过程完成后,安全检查结果将在 CLI 输出中显示。如果检测到任何可疑文件,您将看到这些文件的列表以及警告信息。
Example output: 示例输出:
<span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><span style="color:#1f2328"><span style="color:var(--fgColor-default, var(--color-fg-default))"><span style="background-color:var(--bgColor-muted, var(--color-canvas-subtle))"><code>🔍 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.
</code></span></span></span></span>
By default, Repomix's security check feature is enabled. You can disable it by setting security.enableSecurityCheck
to false
in your configuration file:
默认情况下,Repomix 的安全检查功能已启用。您可以通过在配置文件中将 security.enableSecurityCheck
设置为 false
来禁用它:
{
"security": {
"enableSecurityCheck": false
}
}
Or using the --no-security-check
command line option:
或者使用 --no-security-check
命令行选项:
repomix --no-security-check
Note 注意
Disabling security checks may expose sensitive information. Use this option with caution and only when necessary, such as when working with test files or documentation that contains example credentials.
禁用安全检查可能会泄露敏感信息。请谨慎使用此选项,仅在必要时使用,例如处理测试文件或包含示例凭证的文档。
软件下载
本文信息来源于GitHub作者地址:https://github.com/yamadashy/repomix