Appearance
Repomix — 程式庫打包為 AI 輸入素材
將整個程式庫打包成單一 AI 友善檔案,直接餵給 LLM 進行代碼分析、問答或輔助開發。
概述
Repomix 解決了一個常見問題:LLM 需要理解一整個程式庫的脈絡,但手動貼上數十個檔案既繁瑣又容易遺漏。Repomix 將整個 repo 的所有檔案(或指定的子集)合併成一個結構清晰的單一文件,讓你可以一次性地把完整代碼庫的上下文交給 Claude、ChatGPT、Gemini 等 LLM。
工具本身設計極為輕量,免安裝即可透過 npx 執行,也支援全域安裝。輸出格式可搭配 --compress 選項壓縮,降低 token 消耗。
核心內容
安裝與執行
最快的方式是直接用 npx 免安裝執行,在任意專案目錄下執行即可:
bash
npx repomix@latest若需要長期使用,推薦全域安裝:
| 套件管理器 | 指令 |
|---|---|
| npm | npm install -g repomix |
| yarn | yarn global add repomix |
| bun | bun add -g repomix |
| Homebrew (macOS/Linux) | brew install repomix |
打包目標的選擇
Repomix 提供三種主要方式來指定打包範圍:
- 整個當前目錄:直接執行
repomix,打包所有內容 - Glob 包含/排除:用
--include和--ignore精確指定 - stdin 管線:透過
--stdin接收外部工具輸出的檔案清單,彈性最高
stdin 模式特別適合與 find、git ls-files、rg(ripgrep)、fzf 等工具組合,例如只打包含有 TODO 的 TypeScript 檔案,或互動式地用 fzf 挑選要包含的檔案。
打包遠端倉庫
直接指定 GitHub URL 或 owner/repo 簡寫,Repomix 會自動 clone 並打包,無需手動下載:
bash
repomix --remote yamadashy/repomix
repomix --remote https://github.com/yamadashy/repomix --remote-branch main
repomix --remote https://github.com/yamadashy/repomix --remote-branch 935b695包含 Git 歷史
透過 --include-logs 和 --include-diffs,可以讓輸出同時包含 commit 記錄與差異,幫助 LLM 理解程式碼的演進脈絡:
bash
repomix --include-logs --include-diffs
repomix --include-logs --include-logs-count 10 # 只包含最近 10 筆設定檔
執行 repomix --init 會在專案目錄生成 repomix.config.json,可固化常用的 include/ignore/compress 設定,方便團隊共用並納入版控。
關鍵要點
npx repomix@latest免安裝即可使用,適合臨時打包--stdin搭配rg、fzf等工具,可精確控制打包範圍--remote可直接打包 GitHub 倉庫,無需手動 clone--include-logs --include-diffs可附上 git 歷史,讓 LLM 理解程式碼演進--compress壓縮輸出,降低 token 消耗repomix --init生成repomix.config.json固化設定
實際應用
在 AI 輔助開發流程中,Repomix 通常用於:
- 程式碼審查:打包整個 repo 請 LLM 分析架構或找 bug
- 文件生成:讓 LLM 基於完整程式碼庫生成 README 或 API 文件
- 遷移評估:打包舊版程式庫,請 LLM 規劃重構或遷移策略
- 精準子集打包:搭配
--stdin+ ripgrep,只打包相關模組交給 LLM 分析
搭配 Claude Code 等 AI 開發工具使用時,Repomix 的輸出可作為補充上下文,讓 AI agent 對整個代碼庫有全局視野。
部署設定參考
以下為實際使用的指令速查,供日後直接複製使用。
操作指令
bash
# 免安裝執行(打包當前目錄)
npx repomix@latest
# 全域安裝
npm install -g repomix
# 打包指定目錄
repomix path/to/directory
# 使用 Glob 包含 / 排除
repomix --include "src/**/*.ts,**/*.md"
repomix --ignore "**/*.log,tmp/"
# 打包遠端倉庫
repomix --remote yamadashy/repomix
repomix --remote https://github.com/yamadashy/repomix --remote-branch main
repomix --remote https://github.com/yamadashy/repomix --remote-branch 935b695
# stdin 模式(搭配其他工具)
find src -name "*.ts" -type f | repomix --stdin
git ls-files "*.ts" | repomix --stdin
rg -l "TODO|FIXME" --type ts | repomix --stdin
fzf -m | repomix --stdin
find . -name "*.ts" -type f | fzf -m | repomix --stdin
# 包含 git 日誌與 diff
repomix --include-logs
repomix --include-logs --include-logs-count 10
repomix --include-logs --include-diffs
# 壓縮輸出
repomix --compress
repomix --remote yamadashy/repomix --compress
# 初始化設定檔
repomix --init相關概念
- Claude Code 權限模式 — AI 輔助開發工具,Repomix 可補充其程式碼上下文
- Superpowers AI 開發方法論 — AI 輔助開發工作流,Repomix 可整合其中的代碼分析步驟
- GitHub Copilot Sub-Agent 編排 — Sub-Agent 開發模式,Repomix 可用於提供完整代碼上下文
- Claude Design — Codebase Input 方式比較 — 在 Claude Design 中以 Repomix XML 上傳 vs 原生 Repo 連結的場景選擇指南
來源
- Repomix 官方 GitHub — 原始碼與完整文件
- 原始素材:2026-04-21 Repomix 使用指南.md