欣淇
发布于 2026-05-13 / 0 阅读
0
0

📦 Repomix:24.6k Stars,把整个代码库打包成一段话送给 AI,`npx repomix` 就行

📦 Repomix:24.6k Stars,把整个代码库打包成一段话送给 AI,npx repomix 就行

项目地址:yamadashy/repomix | ⭐ 24,635 | 🛠 TypeScript | 📅 2024-07


老实说,每次把代码库扔给 Claude 或 ChatGPT 分析的时候,最烦的就是手动挑文件、拼上下文。拖拽文件夹进去?token 分分钟爆表。写 prompt 描述项目结构?AI 理解不对还得反复调。这活儿能不能一行命令搞定?

能。这就是 Repomix 做的事:把整个仓库打包成一个 AI 友好的文件,npx repomix 就完事了。

一、为什么值得用

这玩意儿不是简单的 cat *.py > output.txt。它做的事情挺细的:

  • 自动忽略 .gitignore.repomixignore,node_modules 这种脏东西不会进来
  • Token 统计 每个文件、整个库用了多少 token 一目了然
  • 安全扫描 内置 Secretlint,API key 和密码不会意外泄漏
  • Git 感知 可以带上 commit log 和 diff,AI 知道代码演变过程
  • MCP 支持repomix --mcp,Claude Code 可以直接调它分析远程仓库
  • 二、直接用

    别整那些花里胡哨的,一条命令就够了:

    npx repomix
    

    跑完之后目录里多一个 repomix-output.xml,直接拖进 ChatGPT/Claude 就行。

    如果你有项目要经常打包,装全局:

    npm install -g repomix
    # 然后
    repomix
    

    三、高级操作

    处理远程仓库——看完这篇文章分析一下 React 源码:

    repomix --remote facebook/react
    

    指定分支或 commit:

    repomix --remote https://github.com/user/repo/tree/main
    repomix --remote https://github.com/user/repo/commit/836abcd7
    

    只打包特定文件:

    repomix --include "src/**/*.ts" --ignore "**/*.test.ts"
    

    带上 git 日志:

    repomix --include-logs --include-logs-count 30
    

    压缩输出(用 Tree-sitter 提取函数签名,省 70% token):

    repomix --compress
    

    输出到 stdout,直接管道给 LLM:

    repomix --stdout | llm "请分析这个项目的架构"
    

    四、MCP Server 配置

    这最骚的操作是当 MCP Server 用。配置好之后,Claude Code 就能直接分析任何仓库了:

    claude mcp add repomix -- npx -y repomix --mcp
    

    然后在 Claude Code 里说:

    "What's the structure of this repo? https://github.com/facebook/react"
    

    它自己会 clone、打包、分析,你等着看结果就行。

    五、踩坑记录

    踩过的坑都是泪:

  • 大项目用 --compress 不然 token 数能吓到你。React 全量打包大概 80k tokens,压缩后 25k
  • --split-output 1mb 针对 Google AI Studio 这类有文件大小限制的平台,自动切文件
  • 远程仓库的 config 默认不加载--remote-trust-config 手动信任,安全考虑
  • Docker 跑 MCP 如果用容器,记得 docker run -i --rm ghcr.io/yamadashy/repomix --mcp
  • 六、总结

  • 装完 npx repomix 就能用,零配置
  • 支持 XML / Markdown / JSON / Plain 四种输出格式
  • MCP Server 让 Claude Code 直接分析远程仓库
  • 内置安全扫描不会泄漏敏感信息
  • Tree-sitter 压缩省 70% token
  • 标签:#DeveloperTools #AI #LLM #MCP #CodeAnalysis #GitHubTool


    📦 Repomix: 24.6k Stars, Pack Your Entire Codebase for AI with npx repomix

    Project: yamadashy/repomix | ⭐ 24,635 | 🛠 TypeScript

    Honestly, every time I need to throw a codebase at Claude or ChatGPT, the most annoying part is manually picking files, stitching context together, and hoping the AI understands the structure. Dragging a whole folder? Token limit hits immediately. Writing prompts describing the project? The AI misinterprets and you have to iterate.

    Repomix solves this: one command packs your entire repo into an AI-friendly file.

    Quick start:

    npx repomix
    

    Then drag repomix-output.xml into any AI tool.

    Remote repos:

    repomix --remote facebook/react
    

    MCP integration:

    claude mcp add repomix -- npx -y repomix --mcp
    

    Key features: auto .gitignore respect, token counting, Secretlint security scanning, git log/diff support, Tree-sitter compression (70% token reduction), and MCP server mode for direct Claude Code integration.

    Tags: #DeveloperTools #AI #LLM #MCP #CodeAnalysis #GitHubTool


    评论