mcpField
R
repomix

repomix

github.com/julianobarbosaエージェントワークフロー15113 回インストール6 日前に更新
リポジトリ

repomix について

repomixは、LLMによる分析やレビュー、ドキュメント作成向けにリポジトリのコンテキストをまとめる開発者向けスキルです。ローカルまたはリモートのコードを選別・圧縮して構造化出力を生成し、MCPサーバーとしても動作します。

主な機能

  1. 01ローカル・リモートリポジトリのパック
  2. 02包含・除外パターンによるファイル選択
  3. 03コード圧縮によるトークン削減
  4. 04XML、Markdown、JSON、プレーンテキスト出力
  5. 05トークン数の確認とGit履歴の追加

活用シーン

  1. 01LLMによるコードレビューの準備
  2. 02クローンせずにリモートリポジトリを分析
  3. 03アーキテクチャ分析用のコンテキスト作成
  4. 04トークン上限に対するリポジトリ規模の確認

MCP 対応

`--mcp`で起動すると、ローカル・リモートリポジトリのパック、生成出力の読み取り、ディレクトリツリーの取得を行うツールを提供します。

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/julianobarbosa/claude-code-skills --skill repomix

インストール後、Claude Code で/repomixを入力して読み込まれたか確認します。

詳細

Repomix - AI 向けコードベースのパッキング

リポジトリ全体を、Claude、ChatGPT、Gemini などの LLM に最適化された、AI フレンドリーな単一ファイルにまとめます。

このスキルを使う場面

  • 分析やリファクタリングのため、コードベースを AI に渡す
  • 包括的なコードレビューを生成する
  • コードからドキュメントを作成する
  • AI 支援開発のためのコンテキストを準備する
  • クローンせずにリモートリポジトリを分析する
  • LLM のコンテキスト上限に対するトークン数を確認する

クイックスタート

# Pack current directory (no install required)
npx repomix@latest

# Pack specific directory
npx repomix path/to/directory

# Pack with compression (~70% token reduction)
npx repomix --compress

# Copy output to clipboard
npx repomix --copy

デフォルトの出力: 現在のディレクトリにある ./repomix-output.xml

使用例

例:Claude によるレビューに向けてコードベースを準備する

User: "Pack my src folder for Claude to review the architecture"
→ npx repomix --include "src/**/*" --style xml --copy
→ Output copied to clipboard, ready to paste into Claude

例:クローンせずにリモートリポジトリを分析する

User: "I want to understand how shadcn/ui implements its button"
→ npx repomix --remote shadcn-ui/ui --include "**/button/**/*" --compress
→ Generates focused output of button component

例:レビュー用に PR の差分を準備する

User: "Pack only the files I changed for a code review"
→ git diff --name-only main | npx repomix --stdin --compress
→ Packs only modified files with compression

例:AI に送信する前にトークン使用量を確認する

User: "Is my codebase too large for GPT-4?"
→ npx repomix --token-count-tree
→ Shows token breakdown per file/directory

例:ライブラリからスキルのリファレンスを生成する

User: "Create a Claude skill from the zod repository"
→ npx repomix --remote colinhacks/zod --skill-generate zod-reference
→ Generates AI-optimized reference documentation

出力形式

# XML (default) - best for Claude
npx repomix --style xml

# Markdown - human readable
npx repomix --style markdown

# JSON - programmatic processing
npx repomix --style json

# Plain text
npx repomix --style plain

トークンの最適化

LLM のコンテキスト上限リファレンス
モデルコンテキストウィンドウ適合する一般的なリポジトリ規模
Claude 3.5/Opus200K トークン大規模モノレポ
GPT-4 Turbo/4o128K トークン中規模プロジェクト
Gemini 1.5 Pro1M トークン非常に大規模なコードベース
Gemini 1.5 Flash1M トークン非常に大規模なコードベース
トークン分析
# Show token count tree
npx repomix --token-count-tree

# Filter by minimum tokens (show files with 1000+ tokens)
npx repomix --token-count-tree 1000

# Split output for large codebases
npx repomix --split-output 1mb

ファイルの選択

含めるパターン
# Include only TypeScript files
npx repomix --include "**/*.ts"

# Include multiple patterns
npx repomix --include "src/**/*.ts,**/*.md"

# Include specific directories
npx repomix --include "src/**/*,tests/**/*"
除外パターン
# Ignore test files
npx repomix --ignore "**/*.test.ts"

# Ignore multiple patterns
npx repomix --ignore "**/*.log,tmp/,dist/"

# Combine include and ignore
npx repomix --include "src/**/*.ts" --ignore "**/*.test.ts"
標準入力
# From find command
find src -name "*.ts" -type f | npx repomix --stdin

# From git tracked files
git ls-files "*.ts" | npx repomix --stdin

# Interactive selection with fzf
find . -name "*.ts" -type f | fzf -m | npx repomix --stdin

# From ripgrep
rg --files --type ts | npx repomix --stdin

一般的なワークフロー

PR レビューの準備
# Pack only changed files for review
git diff --name-only main | npx repomix --stdin --compress

# Pack with diff context included
npx repomix --include-diffs --compress
アーキテクチャ分析
# Pack structure without implementation details
npx repomix --compress --include "src/**/*" --ignore "**/*.test.*"

# Focus on specific layer
npx repomix --include "src/api/**/*,src/services/**/*" --compress
ドキュメントの生成
# Pack with full context for docs
npx repomix --include "src/**/*,**/*.md" --style markdown

# Include git history for changelog
npx repomix --include-logs --include-logs-count 50
依存関係の分析
# Pack only config and dependency files
npx repomix --include "package.json,tsconfig.json,**/*.config.*"

リモートリポジトリ

# Pack remote repository
npx repomix --remote https://github.com/user/repo

# GitHub shorthand
npx repomix --remote user/repo

# Specific branch
npx repomix --remote user/repo --remote-branch main

# Specific commit
npx repomix --remote user/repo --remote-branch 935b695

# Branch URL format
npx repomix --remote https://github.com/user/repo/tree/feature-branch

コード圧縮

Tree-sitter を利用した圧縮では、実装の詳細を削除しながらシグネチャを抽出します。

対応言語

Tree-sitter の圧縮は、JavaScript、TypeScript、Python、Ruby、Go、Rust、Java、C、C++、C#、PHP、Swift、Kotlin などに対応しています。

使い方
npx repomix --compress

# Combine with remote
npx repomix --remote user/repo --compress

圧縮前:

const calculateTotal = (items: Item[]) => {
  let total = 0;
  for (const item of items) {
    total += item.price * item.quantity;
  }
  return total;
};

圧縮後:

const calculateTotal = (items: Item[]) => { /* ... */ };

Git 連携

# Include git logs (last 50 commits)
npx repomix --include-logs

# Specify commit count
npx repomix --include-logs --include-logs-count 20

# Include git diffs
npx repomix --include-diffs

# Combine logs and diffs
npx repomix --include-logs --include-diffs

設定

設定ファイルの初期化
# Create repomix.config.json
npx repomix --init

# Global config
npx repomix --init --global
設定ファイル
{
  "$schema": "https://repomix.com/schemas/latest/schema.json",
  "output": {
    "filePath": "repomix-output.xml",
    "style": "xml",
    "compress": false,
    "removeComments": false,
    "showLineNumbers": false,
    "copyToClipboard": false
  },
  "include": ["src/**/*", "**/*.md"],
  "ignore": {
    "useGitignore": true,
    "useDefaultPatterns": true,
    "customPatterns": ["**/*.test.ts", "dist/"]
  },
  "security": {
    "enableSecurityCheck": true
  }
}

Docker の使用方法

# Pack current directory
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix

# Pack specific directory
docker run -v .:/app -it --rm ghcr.io/yamadashy/repomix path/to/directory

# Remote repository
docker run -v ./output:/app -it --rm ghcr.io/yamadashy/repomix --remote user/repo

MCP サーバー連携

AI アシスタント向けに、Model Context Protocol サーバーとして実行します:

npx repomix --mcp
Claude Code の設定
claude mcp add repomix -- npx -y repomix --mcp
利用可能な MCP ツール

MCP サーバーとして実行すると、次の機能を提供します:

ツール説明
pack_codebaseローカルディレクトリを AI フレンドリーな形式にまとめる
pack_remote_repositoryクローンせずに GitHub リポジトリをまとめる
read_repomix_output生成された出力ファイルの内容を読み取る
file_system_treeディレクトリツリー構造を取得する

Claude Agent Skills の生成

Claude 向けにスキル形式の出力を生成します:

# Generate skills from local directory
npx repomix --skill-generate

# Generate with custom name
npx repomix --skill-generate my-project-reference

# From remote repository
npx repomix --remote user/repo --skill-generate

CLI オプションのリファレンス

オプション説明
-o, --output <file>出力ファイルのパス
--style <style>出力形式:xml、markdown、json、plain
--compressTree-sitter による圧縮を有効にする
--include <patterns>glob パターンに一致するファイルを含める
-i, --ignore <patterns>パターンに一致するファイルを除外する
--remote <url>リモートリポジトリを処理する
--remote-branch <name>リモートのブランチ、タグ、またはコミット
--stdin標準入力からファイルパスを読み取る
--copy出力をクリップボードにコピーする
--token-count-treeファイルごとのトークン数を表示する
--split-output <size>出力をサイズで分割する(例:1mb)
--include-logsgit のコミット履歴を含める
--include-diffsgit の差分を含める
--no-security-check機密データの検出をスキップする
--mcpMCP サーバーとして実行する
--skill-generateClaude のスキル形式を生成する
--init設定ファイルを作成する
--help利用可能なすべてのオプションを表示する

トラブルシューティング

問題解決策
LLM に対して出力が大きすぎる--compress を使用するか、--include でフィルタリングします
期待されるファイルが見つからない.repomixignore、.gitignore、および無視パターンを確認します
シークレットが検出された(処理がブロックされる)フラグが付いたファイルを確認します。誤検知の場合は --no-security-check を使用します
大規模なリポジトリでメモリの問題が発生する--split-output 1mb を使用して出力を分割します
リモートリポジトリへのアクセスが拒否されるURL の形式を確認し、リポジトリが公開されていることを確認するか、SSH を使用します
圧縮が機能しないTree-sitter がその言語をサポートしているか確認します
出力がクリップボードにコピーされないクリップボードへのアクセスを確認します。macOS では --output - | pbcopy を試します

無視ファイル

Repomix は複数の無視設定を優先順位順に適用します。

  1. 設定の ignore.customPatterns
  2. .repomixignore(Repomix 固有)
  3. .ignore(ripgrep 互換)
  4. .gitignore
  5. デフォルトのパターン(node_modules、.git など)

セキュリティ

Repomix は、機密情報を検出するために Secretlint を含んでいます。

# Security check enabled by default
npx repomix

# Disable security check (use with caution)
npx repomix --no-security-check

検出されるシークレットの種類: API キー、トークン、パスワード、秘密鍵、AWS 認証情報、データベース接続文字列など。

ベストプラクティス

  1. 大規模なコードベースでは圧縮を使用してトークン数を減らします(約 70% 削減)。
  2. --include でフィルタリングして関連ファイルに絞り込みます。
  3. パッキングの前に --token-count-tree を使用して大きなファイルを特定します。
  4. AI のコンテキスト上限に達した場合は出力を分割します。
  5. 必要に応じて、変更の経緯を把握するために git のログを含めます。
  6. Claude では XML 形式を使用します(XML タグに最適化されています)。
  7. 人が読みやすい出力や他の LLM には Markdown を使用します。
  8. トークン数を対象の LLM のコンテキストウィンドウと照らし合わせて確認します。
  9. パッキングした出力を共有する前に セキュリティ警告を確認します。

要件

  • Node.js 18.0.0 以降
  • PATH で npm または npx を使用可能であること

リソース


注意点

  • --compress は関数本体を削除しますが、シグネチャは残します。アーキテクチャのレビューには最適ですが、「この関数がバグを起こす理由」を尋ねる用途には役立ちません。LLM は実装を文字どおり見ることができません。
  • シークレットが検出されると、セキュリティチェックによって出力全体がブロックされます。テスト用フィクスチャに AWS キーのような文字列が 1 つでも誤検知されると、実行が中断されます。フラグが付いたファイルを確認した後に限り、--no-security-check を使用してください。
  • .gitignore は適用されますが、.dockerignore は適用されません。node_modules は除外されますが、Dockerfile で無視されている巨大な dist/ はパッキングされます。一致させるには .repomixignore を追加してください。
  • トークン数は tiktoken(GPT)に基づいています。Claude のトークナイザーとは約 10~20% の差があります。「180K トークン」と報告されたリポジトリでも、内容によっては Claude の 200K コンテキストウィンドウを超える場合も、十分に収まる場合もあります。
  • --remote user/repo はデフォルトブランチを一時ディレクトリにクローンし、ローカルで実行します。GitHub API による特別な処理はありません。プライベートリポジトリには SSH キーの設定が必要ですが、エラーメッセージには認証方法の説明がなく、「アクセス拒否」とだけ表示されます。
  • --stdin は NUL 区切りまたは改行区切りのパスを読み込みます。存在しないパスや cwd の外にあるパスは、通知なしに破棄されます。git diff --name-only の出力にタイプミスがあると、警告なしにパックの内容が少なくなります。
  • macOS で pbcopy 経由の --copy を使用すると、一部のターミナルマルチプレクサー(set-clipboard on を設定していない tmux など)では約 1MB で切り詰められます。出力全体がコピーされたと思い込む前に、貼り付け後のサイズを確認してください。

コメント