cross-agent-delegation
Cross-agent task routing — Codex auto-review, Kimi delegation by complexity score (iCPG + Claude reasoning), iCPG + Mnemos mandatory for all agents
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o cross-agent-delegation.zip https://jpskill.com/download/21634.zip && unzip -o cross-agent-delegation.zip && rm cross-agent-delegation.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21634.zip -OutFile "$d\cross-agent-delegation.zip"; Expand-Archive "$d\cross-agent-delegation.zip" -DestinationPath $d -Force; ri "$d\cross-agent-delegation.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
cross-agent-delegation.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
cross-agent-delegationフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[スキル名] cross-agent-delegation
エージェント間委任
Claude Code は、タスクのルーティングを Kimi と Codex に調整します。ユーザーは Claude とのみ対話し、委任は舞台裏で行われます。
ツール検出
セッション開始時に、利用可能なツールを検出します。
command -v kimi &>/dev/null && HAS_KIMI=true || HAS_KIMI=false
command -v codex &>/dev/null && HAS_CODEX=true || HAS_CODEX=false
Codex 自動レビュー (停止フック — 自動)
Codex がインストールされている場合、テスト合格後に停止フックがコードをレビューします。
- TDD ループチェックがテストを実行します
codex-auto-review.shが差分に対して Codex を実行します- 重大/高レベルの検出結果は Claude にフィードバックされます (終了コード 2)
- クリーンなレビューは通過します (終了コード 0)
完全に自動です。 ユーザーや Claude の操作は不要です。
Kimi 委任 (Claude が調整)
Kimi がインストールされており、タスクの複雑さが限定的である場合、Claude は直接委任します。ユーザーは何も実行する必要はありません。
ステップ 1: 複雑さをスコア化し、ファイル数ではない
ファイル数は委任リスクの悪い代理指標です。認証パスへの 1 ファイルの変更は、12 ファイルのリネームよりも困難です。iCPG シグナルと Claude の意味的推論から得られる、5 つの次元でタスクをスコア化します (各 0-2)。
| 次元 | 0 (低) | 1 (中) | 2 (高) | ソース |
|---|---|---|---|---|
| 循環的複雑度 / 表面深度 | <10 LOC、分岐なし | 10-50 LOC、≤3 分岐 | 50+ LOC またはネストされた制御フロー | 関数本体に対する iCPG query_graph |
| ファンアウト (コンシューマーへの影響範囲) | 0-2 呼び出し元 | 3-10 呼び出し元 | 11+ 呼び出し元 | iCPG trace_path(<symbol>, mode=callers) |
| セキュリティ境界を越えるか (SEC-006、認証、PII、RLS、組織スコープ、課金、支払い) | なし | 関連性あり | 直接読み取りまたは書き込み | iCPG SEC-* / R-063 タグ + org_id、user_id、auth、pii の grep |
| 並行性 / トランザクション | 純粋 / 同期 | 非同期のみ | ロック、トランザクション、アトミックな要求、FOR UPDATE、asyncio.Lock、session.begin |
iCPG 並行性フラグ + grep |
| ドメイン不変条件が必要か | なし / インラインで十分に文書化されている | 暗黙的 (1-2 ファイルを読む必要がある) | 重い (クロスドキュメント、ADR 依存、RFC 依存) | Claude の推論 + iCPG ADR 連携 |
# シグナルを自動収集
icpg query blast <scope> --format json # ファンアウト、非同期フラグ、セキュリティタグ
grep -rE "org_id|user_id|auth|pii" <file> # iCPG フラグがない場合の安価なセキュリティヒューリスティック
grep -rE "asyncio.Lock|FOR UPDATE|session.begin" <file> # 並行性ヒューリスティック
ステップ 2: 合計 → ルーティング
| 合計スコア | ルート | 根拠 |
|---|---|---|
| 0-3 | Kimi 単独 | 表面が限定的で、セキュリティ/並行性/クロスドキュメントの懸念なし |
| 4-6 | Kimi → Codex 自動レビュー (ユーザープロンプトなし) | 実際のリスクはあるが、Claude の完全なコンテキストが必要なほど高くはない — Kimi が見逃す可能性のあるものを Codex が捕捉 |
| 7-10 | Claude が直接処理 | 横断的 / セキュリティ上重要 / 並行性が高い — 完全なコンテキストが必要 |
ステップ 3: フロア — 些細なケースのショートカット
本当に些細な作業で iCPG クエリのコストをスキップするには:
# 変更されたファイルが 2 未満 AND 差分に SEC/auth/PII/concurrency キーワードがない場合、
# → スコアリングなしで自動 Kimi。
FILES=$(git diff --name-only | wc -l)
HAS_RISK_KEYWORDS=$(git diff | grep -ciE "org_id|auth|pii|asyncio|FOR UPDATE|transaction|session\.begin" || true)
if [ "$FILES" -lt 2 ] && [ "$HAS_RISK_KEYWORDS" -eq 0 ]; then
AUTO_KIMI=true
fi
これにより、iCPG の往復コストを支払うことなく、些細なリネームやタイプミス修正のケースを処理します。
委任しない場合 (スコアリングを上書き)
- ユーザーが明示的に Claude に実行を依頼した場合
- クロスサービス変更 (API + フロントエンド + データベース) — スコアに関係なく完全なコンテキストが必要
- リリースブランチでの本番ホットフィックス — ツール間のレビューレイテンシが高すぎる
- いずれかの次元でスコアが 7 以上の場合 (1 つの重要な軸で十分、Claude をループに留めるため)
ステップ 4: Bash 経由で委任
Claude は mnemos チェックポイントを書き込み、Kimi をヘッドレスで実行します。
# 1. 現在のコンテキストをディスクに保存
mnemos checkpoint --force
# 2. Kimi のコンテキストサマリーを取得
CONTEXT=$(mnemos resume 2>/dev/null)
# 3. ターゲットファイルの制約を取得
CONSTRAINTS=$(icpg query constraints <target-file> 2>/dev/null)
# 4. Kimi を完全なコンテキストでヘッドレス実行
kimi --print -y -w . -p "
## コンテキスト (mnemos チェックポイントから)
$CONTEXT
## 制約 (iCPG から)
$CONSTRAINTS
## タスク
<具体的なタスクの説明>
## ルール
- 変更後にテストを実行する
- 変更を記録する: icpg record --base main
- 完了時にチェックポイントを書き込む: mnemos checkpoint --force
"
ステップ 4: 結果の読み取り
Kimi が完了した後、Claude は以下を実行します。
# Kimi が何をしたか読み取る
mnemos resume # Kimi のチェックポイント
icpg status # Kimi の記録されたシンボル
git diff # Kimi のファイル変更
委任しない場合
- セキュリティに敏感なコード (認証、暗号、支払い)
- クロスサービス変更 (API + フロントエンド + データベース)
- 共有インターフェースに影響を与えるリファクタリング
- ユーザーが明示的に Claude に実行を依頼した場合
iCPG — すべてのエージェントに必須
いかなるコード変更の前にも、Claude はこれらを実行し (委任時にも結果を含めます)、以下を実行します。
タスク前クエリ
# 1. 重複チェック — すでに完了しているか?
icpg query prior "<goal>"
# 2. 制約 — どのような不変条件が適用されるか?
icpg query constraints <file-path>
# 3. リスク — このシンボルは脆弱か?
icpg query risk <symbol-name>
コード変更後
icpg record --reason <id> --base main
icpg drift check
Mnemos — すべてのエージェントに必須
タスク開始時
mnemos add goal "<task description>"
サブゴール境界時
mnemos checkpoint
タスク終了時 (停止フックによって自動処理)
mnemos checkpoint --force
ツール間のコンテキスト転送
チェックポイントが橋渡し役です。Claude が書き込み、Kimi が読み取ります。
# Claude が状態を保存
mnemos checkpoint --force
# Kimi (または Codex) が状態を読み取る
mnemos resume
チェックポイントには、目標、制約、最近のファイル、git 状態、疲労レベルが含まれます。
完全な調整フロー
タスクが到着 (ユーザーが Claude に指示)
|
v
[1] Claude: icpg query prior "<goal>" ← すでに完了しているか?
[2] Claude: 些細なケースのショートカット ← 2 ファイル未満 & リスクなし 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Cross-Agent Delegation
Claude Code orchestrates task routing to Kimi and Codex. The user interacts with Claude only — delegation happens behind the scenes.
Tool Detection
At session start, detect available tools:
command -v kimi &>/dev/null && HAS_KIMI=true || HAS_KIMI=false
command -v codex &>/dev/null && HAS_CODEX=true || HAS_CODEX=false
Codex Auto-Review (Stop Hook — Automatic)
When Codex is installed, a Stop hook reviews code after tests pass:
- TDD loop check runs tests
codex-auto-review.shruns Codex on the diff- Critical/High findings feed back to Claude (exit 2)
- Clean reviews pass through (exit 0)
Fully automatic. No user or Claude action needed.
Kimi Delegation (Claude Orchestrates)
When Kimi is installed and the task complexity is bounded, Claude delegates directly — the user does not need to run anything.
Step 1: Score complexity, not file count
File count is a poor proxy for delegation risk. A 1-file change to an authz path is harder than a 12-file rename. Score the task on five dimensions, each 0-2, sourced from iCPG signals plus Claude's semantic reasoning:
| Dimension | 0 (low) | 1 (medium) | 2 (high) | Source |
|---|---|---|---|---|
| Cyclomatic / surface depth | <10 LOC, no branches | 10-50 LOC, ≤3 branches | 50+ LOC or nested control flow | iCPG query_graph over function bodies |
| Fan-out (consumer blast radius) | 0-2 callers | 3-10 callers | 11+ callers | iCPG trace_path(<symbol>, mode=callers) |
| Crosses a security boundary (SEC-006, auth, PII, RLS, org-scope, billing, payments) | None | Tangential | Direct read or write | iCPG SEC-* / R-063 tags + grep for org_id, user_id, auth, pii |
| Concurrency / transactional | Pure / sync | Async only | Locks, transactions, atomic claims, FOR UPDATE, asyncio.Lock, session.begin |
iCPG concurrency flags + grep |
| Domain invariants required | None / well-documented inline | Some implicit (need to read 1-2 files) | Heavy (cross-doc, ADR-bound, RFC-bound) | Claude reasoning + iCPG ADR linkage |
# Auto-collect signals
icpg query blast <scope> --format json # fan-out, async flags, sec tags
grep -rE "org_id|user_id|auth|pii" <file> # cheap sec heuristic if iCPG flags absent
grep -rE "asyncio.Lock|FOR UPDATE|session.begin" <file> # concurrency heuristic
Step 2: Sum → routing
| Total score | Route | Rationale |
|---|---|---|
| 0-3 | Kimi solo | Bounded surface, no security/concurrency/cross-doc concerns |
| 4-6 | Kimi → Codex auto-review (no user prompt) | Real risk, but not so high that we need full Claude context — Codex catches what Kimi might miss |
| 7-10 | Claude handles directly | Cross-cutting / security-critical / concurrency-heavy — needs full context |
Step 3: Floor — trivial-case shortcut
To skip iCPG-query cost on truly trivial work:
# If <2 files changed AND no SEC/auth/PII/concurrency keyword in diff,
# → auto-Kimi without scoring.
FILES=$(git diff --name-only | wc -l)
HAS_RISK_KEYWORDS=$(git diff | grep -ciE "org_id|auth|pii|asyncio|FOR UPDATE|transaction|session\.begin" || true)
if [ "$FILES" -lt 2 ] && [ "$HAS_RISK_KEYWORDS" -eq 0 ]; then
AUTO_KIMI=true
fi
This handles the trivial-rename / typo-fix case without paying the iCPG round-trip.
When NOT to Delegate (overrides scoring)
- User explicitly asked Claude to do it
- Cross-service changes (API + frontend + database) — needs full context regardless of score
- Production hotfix on a release branch — cross-tool review latency is too high
- Score 7+ in any single dimension (one critical axis is enough to keep Claude in the loop)
Step 4: Delegate via Bash
Claude writes a mnemos checkpoint, then runs Kimi headless:
# 1. Save current context to disk
mnemos checkpoint --force
# 2. Get context summary for Kimi
CONTEXT=$(mnemos resume 2>/dev/null)
# 3. Get constraints for target files
CONSTRAINTS=$(icpg query constraints <target-file> 2>/dev/null)
# 4. Run Kimi headless with full context
kimi --print -y -w . -p "
## Context (from mnemos checkpoint)
$CONTEXT
## Constraints (from iCPG)
$CONSTRAINTS
## Task
<specific task description>
## Rules
- Run tests after changes
- Record changes: icpg record --base main
- Write checkpoint when done: mnemos checkpoint --force
"
Step 4: Read Results
After Kimi finishes, Claude:
# Read what Kimi did
mnemos resume # Kimi's checkpoint
icpg status # Kimi's recorded symbols
git diff # Kimi's file changes
When NOT to Delegate
- Security-sensitive code (auth, crypto, payments)
- Cross-service changes (API + frontend + database)
- Refactors that touch shared interfaces
- User explicitly asked Claude to do it
iCPG — Mandatory for All Agents
Before ANY code change, Claude runs these (and includes results when delegating):
Pre-Task Queries
# 1. Duplicate check — already done?
icpg query prior "<goal>"
# 2. Constraints — what invariants apply?
icpg query constraints <file-path>
# 3. Risk — is this symbol fragile?
icpg query risk <symbol-name>
After Code Changes
icpg record --reason <id> --base main
icpg drift check
Mnemos — Mandatory for All Agents
At Task Start
mnemos add goal "<task description>"
At Sub-Goal Boundaries
mnemos checkpoint
At Task End (auto-handled by Stop hook)
mnemos checkpoint --force
Context Transfer Between Tools
The checkpoint is the bridge. Claude writes it, Kimi reads it:
# Claude saves state
mnemos checkpoint --force
# Kimi (or Codex) reads state
mnemos resume
The checkpoint contains: goal, constraints, recent files, git state, fatigue level.
Full Orchestration Flow
TASK ARRIVES (user tells Claude)
|
v
[1] Claude: icpg query prior "<goal>" ← Already done?
[2] Claude: trivial-case shortcut ← <2 files & no risk keywords?
|
+-- YES + Kimi installed -----> AUTO-KIMI (no scoring)
|
+-- NO ↓
v
[3] Claude: score complexity (5 dims × 0-2, iCPG + reasoning)
|
+-- score 0-3 ----> KIMI SOLO PATH
| [a] mnemos checkpoint --force
| [b] kimi --print -y -p "..."
| [c] mnemos resume + git diff
| [d] Continue in Claude
|
+-- score 4-6 ----> KIMI + CODEX REVIEW PATH
| [a] mnemos checkpoint --force
| [b] kimi --print -y -p "..."
| [c] codex review --uncommitted ← Auto-review the diff
| [d] If P0/P1 findings: re-prompt Kimi with findings
| [e] Once clean: continue in Claude
|
+-- score 7-10 ----> CLAUDE DIRECT PATH (full context)
|
v
[4] icpg query constraints <files> ← Invariants
[5] icpg query risk <symbols> ← Fragility
[6] mnemos add goal "<task>" ← Track in memory
|
v
[7] IMPLEMENT (TDD: RED -> GREEN)
|
v
[8] Stop: tdd-loop-check.sh ← Tests pass?
[9] Stop: codex-auto-review.sh ← Codex reviews diff
[10] Stop: icpg-stop-record.sh ← Record symbols
[11] Stop: mnemos-checkpoint.sh ← Save memory