codex-subagents について
codex-subagents は、作業をバックグラウンドスレッドに委任し、メインコンテキストを軽く保つスキルです。並行調査や長時間タスク、独立したコンテキストが有効な作業向けに、スレッドの待機・確認・アーカイブ手順を備えています。
主な機能
- 01バックグラウンドスレッドでエージェントを起動
- 02複数の調査タスクを並行実行
- 03スレッドの完了待機と状態確認
- 04停止したスレッドへの追加プロンプト
- 05完了スレッドのアーカイブと古い記録の整理
活用シーン
- 01複数の API やテーマを並行して調査
- 02長時間の調査をメインコンテキストから分離
- 03バックグラウンド処理の完了後に作業を継続
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ obra/ external-subagents --skill codex-subagentsインストール後、Claude Code で/codex-subagentsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
TODO.md.gitignoreREADME.md.prek.tomldev/build.mjs.editorconfig.prettierrcdemo-watch.ts.npmrcdemo-watch-prompt.txteslint.config.jsrun-prek-install.mjspackage.jsonpackage-lock.jsondev/src/bin/codex-subagent.tsdev/src/commands/archive.tslog.tsclean.tslabel.tslist.tsstatus.tspeek.tssend.tsstart.tswait.tswatch.tsdev/src/lib/backends.tscontroller-id.tsexec-runner.tsfile-lock.ts詳細
Codex Subagents
概要
codex-subagent はバックグラウンドスレッドに作業を委任し、メインコンテキストを軽量に保ちます。スレッドはデフォルトでデタッチ状態で実行されます。結果を確認するには wait/peek を使用してください。
重要なルール:
- 実行中のスレッドには送信できません。後続のメッセージを送る前に、必ず待機してください。
--permissions read-onlyまたは--permissions workspace-writeを使用してください(workspace-readは使用しないでください)。
詳しいワークフロードキュメントについては、reference/workflow.md を参照してください。
使用する場面
| 状況 | サブエージェントが役立つ理由 |
|---|---|
| 並列での調査タスク | 複数のスレッドを同時に実行できます |
| コンテキストが肥大化する場合 | 調査を別のスレッドに分離できます |
| 実行に時間がかかる作業 | デタッチして実行し、後で確認できます |
使用しない場面:簡単なインラインの質問、現在の状態に密接に依存する作業。
基本的なワークフロー
1. start with --prompt (inline text or stdin)
2. wait/peek → check result
3. send → resume with follow-up (ONLY after thread stops)
4. archive/clean → lifecycle management
実行中のスレッドに関するルール
実行中のスレッドには送信できません。 これは最もよくある間違いです。
# WRONG - thread might still be running
echo "followup" | codex-subagent send thread-abc --prompt -
# RIGHT - wait first, then send
codex-subagent wait --threads thread-abc
echo "followup" | codex-subagent send thread-abc --prompt -
再開可能なステータス:completed、failed、stopped、waiting
クイックリファレンス
| コマンド | 目的 | 主なフラグ |
|---|---|---|
start | 新しいスレッドを起動する | --role、--permissions、--prompt、--label、-w |
send | 停止したスレッドを再開する | <thread-id>、--prompt、-w |
peek | 未確認の最新メッセージを読む | <thread-id>、--save-response |
log | 全履歴を表示する | <thread-id>、--tail、--json |
status | スレッドの概要を表示する | <thread-id> |
wait | スレッドが停止するまで待機する | --threads、--labels、--all、--follow-last |
list | スレッドを表示する | --status、--label、--role |
archive | 完了したスレッドをアーカイブに移動する | --completed、--yes、--dry-run |
clean | 古いアーカイブを削除する | --older-than-days、--yes |
プロンプト入力:簡単なプロンプトには --prompt "text" を使用します。--prompt - は標準入力から読み込みます(複数行の場合)。ファイルには -f/--prompt-file を使用します。
位置引数のスレッド ID:peek abc123 は peek -t abc123 と同じように機能します。
よく使うパターン
シンプルなインラインプロンプト
codex-subagent start --role researcher --permissions read-only \
--label "quick-task" --prompt "List all exported functions in src/lib/"
複数行プロンプト(heredoc)
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --label "auth-research" --prompt -
Research authentication patterns in this codebase:
1. Find all auth-related files
2. Document the auth flow
3. Note any security concerns
EOF
並列調査
# Launch multiple researchers
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --label "API: Stripe" --prompt -
Research Stripe API authentication methods and best practices
EOF
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --label "API: Twilio" --prompt -
Research Twilio API authentication methods and best practices
EOF
# Wait for all, see results
codex-subagent wait --labels "API:" --follow-last
ブロッキングタスク
# -w blocks until complete (may take minutes)
cat <<'EOF' | codex-subagent start --role researcher --permissions read-only --prompt - -w --save-response result.txt
Analyze error handling patterns in src/
EOF
cat result.txt
警告:-w はエージェントの実行中、待機し続けます。時間のかかるタスクには、デタッチモードで実行して wait --follow-last を使う方法をおすすめします。
古い作業をクリーンアップする
# Two-phase: archive completed, then clean old archives
codex-subagent archive --completed --yes
codex-subagent clean --older-than-days 30 --yes
トラブルシューティング
| 問題 | 原因 | 解決方法 |
|---|---|---|
| "profile does not exist" | 権限が間違っています | read-only または workspace-write を使用してください(workspace-read は使用しないでください) |
| "not resumable" エラー | スレッドがまだ実行中です | まず wait を実行し、その後 send を実行してください |
| "different controller" | セッションが間違っています | --controller-id を使用するか、list を確認してください |
| スレッドが見つからない | アーカイブされています | アーカイブディレクトリを確認するか、タスクを再実行してください |
チェックリスト
-
startに--role、--permissions、--prompt、--labelが指定されている - 権限が
read-onlyまたはworkspace-writeになっている -
sendの前にwaitを実行している(実行中のスレッドには絶対に送信しない) -
--save-responseまたはpeekで結果を取得している