Codex Collaboration Skill
Coordinate tasks between Claude Code and OpenAI Codex CLI using adaptive workflow selection based on model strengths.
Overview
This skill enables effective collaboration between two AI systems with two workflow modes:
Codex-Leads (従来):
- Codex: Planning, code review, architectural decisions
- Claude Code: Implementation, file operations, testing
Claude-Leads (新規):
- Claude Code: Deep analysis, planning, code review
- Codex: Fast implementation with workspace-write sandbox
デフォルト(auto)は常に Codex-Leads を選択。claude-leads は workflow: claude-leads を明示指定した場合のみ有効。
通信方式: MCP primary + Bash fallback のデュアルモード。
- MCP mode (
mcp__codex__codex/codex-reply): ステートフルな会話(threadId で文脈保持)。ANSI 除去不要、ファイル I/O 不要。 - Bash mode (
codex exec/codex review): ステートレス実行。codex_run_exec()が入出力、ANSI 除去、exit code ハンドリングを統合処理。MCP 未設定時の自動フォールバック。
Prerequisites
Before starting collaboration:
- MCP tools check (primary): Try
mcp__codex__codexwith a lightweight probe. If available → MCP mode. - CLI fallback: If MCP unavailable, verify
codexCLI is available:which codexorcodex --version - Verify
codex execworks (Bash mode):codex exec -s read-only - <<< "test" - Check for project settings in
.claude/codex-collab.local.md - If neither MCP nor CLI available, inform user and proceed with Claude-only mode
Workflow: Review Type (Default)
Phase 1: Task Analysis
When receiving a task for collaboration:
Parse the task description to identify:
- Core objective
- Affected files/components
- Complexity level
- Required context
Gather relevant context:
- Read related files
- Check existing tests
- Review recent changes
Phase 2: Request Plan from Codex
MCP mode (primary):
mcp__codex__codex(prompt: "[planning prompt]", sandbox: "read-only")
→ Returns response + threadId (saved for Phase 4)
Bash mode (fallback):
source scripts/codex-helpers.sh
PROMPT_FILE=$(codex_write_prompt "$PLANNING_PROMPT" "plan")
OUTPUT_FILE="$(codex_tmp_path 'codex-plan-output.md')"
codex_run_exec "$PROMPT_FILE" "$OUTPUT_FILE" "read-only"
Read results from tool response (MCP) or output file (Bash).
Phase 3: Implement Based on Plan
After receiving Codex's plan:
- Validate the plan is reasonable
- Present plan to user for confirmation
- Execute implementation step by step
- Track changes made
Phase 4: Request Review from Codex
After implementation:
- Stage changes for Codex visibility (important!):
git add -A
git reset -- tmp/ 2>/dev/null || true
Why? Staging ensures all changes are visible to Codex regardless of its file discovery method.
- Run review (mode-dependent):
MCP mode (primary):
# Get diff, embed in prompt, continue same thread from Phase 2
mcp__codex__codex-reply(threadId: "[from Phase 2]", prompt: "[review prompt with diff]")
→ Parse verdict directly from response (no codex_infer_verdict needed)
Bash mode (fallback):
source scripts/codex-helpers.sh
REVIEW_OUTPUT="$(codex_tmp_path 'codex-review-output.md')"
codex_run_review "$REVIEW_OUTPUT" "$MODEL" || REVIEW_EXIT=$?
if [ "${REVIEW_EXIT:-0}" -ne 0 ]; then
REVIEW_PROMPT_FILE=$(codex_write_prompt "$REVIEW_PROMPT" "review")
codex_run_exec "$REVIEW_PROMPT_FILE" "$REVIEW_OUTPUT" "read-only"
fi
- Parse verdict and findings (Bash mode):
RESPONSE=$(cat "$REVIEW_OUTPUT")
VERDICT=$(codex_infer_verdict "$RESPONSE") || true
FINDINGS=$(codex_extract_review_findings "$RESPONSE")
The review uses [P1]-[P4] priority markers as the primary source for verdict inference:
[P1]/[P2]→ fail[P3]/[P4]→ conditional- No findings + sufficient output → pass
- Metadata block (
verdict: pass/conditional/fail) is also supported as an alternative
Phase 5: Handle Review Result
Based on review verdict:
Pass: Report completion to user
Conditional:
- Apply suggested improvements
- Re-request review if significant changes
Fail:
- Analyze failure reasons
- Either fix issues or escalate to user
Settings and Configuration
Reading Project Settings
Check for .claude/codex-collab.local.md in project root:
---
sandbox: read-only
language: ja
---
# Project-specific instructions
Parse YAML frontmatter for:
model: Codex model to use (omit to use the Codex default from~/.codex/config.toml)sandbox: read-only | workspace-write | danger-full-accessworkflow: Workflow mode (auto | codex-leads | claude-leads, default: auto; auto は常に codex-leads を選択)exchange.enabled: Enable planning exchange (default: true, codex-leads only)exchange.max_iterations: Maximum rounds for multi-turn exchange (default: 3)exchange.user_confirm: When to ask user confirmation (never | always | on_important)exchange.history_mode: How to handle history (full | summarize; Bash fallback only — MCP threads preserve history)review.enabled: Enable review iteration (default: true, codex-leads only)review.max_iterations: Maximum rounds for review iteration (default: 5)review.max_verdict_retries: Retries when verdict is missing/unclear (default: 3)review.user_confirm: When to ask user confirmation for reviews (default: never)claude_leads.sandbox: Sandbox for Codex implementation (default: workspace-write)claude_leads.consult_codex: Enable plan consultation phase (default: true)claude_leads.safety_checkpoint: Pre-implementation checkpoint (stash | wip-commit | none, default: stash)claude_leads.review.max_iterations: Max review-fix iterations (default: 3)codex.wait_timeout: Max execution time forcodex execin seconds (default: 180, max: 600; Bash fallback only)
Settings Priority
Apply settings in this order (later overrides earlier):
- Safe defaults: sandbox=read-only
- Global settings: ~/.claude/codex-collab.local.md
- Project settings: .claude/codex-collab.local.md
- Command arguments: Explicit user request
Safe Defaults
Always start with secure defaults:
workflow: auto- 常に codex-leads を選択(claude-leads は明示指定時のみ)sandbox: read-only- Codex cannot modify files (codex-leads)exchange.enabled: true- Planning exchange enabled by defaultexchange.max_iterations: 3- Prevent runaway exchangesexchange.user_confirm: on_important- Ask user for major decisionsexchange.history_mode: summarize- Efficient token usagereview.enabled: true- Review iteration enabled by defaultreview.max_iterations: 5- More iterations allowed (goal is clear, diff is small)review.user_confirm: never- Auto-iterate without confirmationclaude_leads.sandbox: workspace-write- Codex can modify project files (claude-leads)claude_leads.consult_codex: true- Plan consultation enabledclaude_leads.safety_checkpoint: stash- Git stash before implementationclaude_leads.review.max_iterations: 3- Claude review iterations
Quality Gates
Plan Quality Criteria
A valid plan from Codex must include:
- Clear list of files to modify
- Specific changes for each file
- Rationale for approach
- Identified risks or concerns
- Test coverage considerations
If plan is incomplete, request clarification from Codex.
Review Acceptance Criteria
Accept review as "Pass" only when:
- All changed files reviewed
- No critical bugs identified
- Security concerns addressed
- Design aligns with original plan
- Test coverage adequate
Running Codex
MCP パターン(推奨)
MCP ツールが利用可能な場合、ステートフルな通信を使用:
# 新規セッション開始
mcp__codex__codex(prompt: "...", sandbox: "read-only")
→ Returns response + threadId
# 同一スレッドで継続
mcp__codex__codex-reply(threadId: "...", prompt: "...")
→ Returns response (conversation context preserved)
codex exec パターン(フォールバック)
MCP が利用できない場合、codex exec(ステートレス実行)を使用:
# ヘルパー関数を使用(推奨)
source scripts/codex-helpers.sh
PROMPT_FILE=$(codex_write_prompt "$PROMPT_CONTENT" "plan")
OUTPUT_FILE="$(codex_tmp_path 'codex-output.md')"
codex_run_exec "$PROMPT_FILE" "$OUTPUT_FILE" "read-only"
# 直接実行(モデルは通常 Codex デフォルトを使用。指定する場合のみ -m を付ける)
codex exec -s read-only - < prompt.txt 2>&1 | tee output.md
Codex CLI Options
-m, --model <model>- Specify model (e.g., gpt-5.6-sol; omit to use the Codex default)-s, --sandbox <mode>- read-only | workspace-write | danger-full-access-C, --cd <dir>- Working directory--full-auto- Automatic execution mode-- Read prompt from stdin
Important Notes
- MCP mode: Stateful sessions via threadId. Clean text output. No file I/O for prompts. Auto-detected in Step 0a.
- Bash mode: Each
codex execcall is stateless (no conversation history between calls). Include all necessary context in each prompt. - Use
-s read-onlyfor planning/review tasks (Codex won't modify files) - Use
-s workspace-writefor implementation tasks (claude-leads workflow) - Output may contain ANSI escape codes (Bash mode only); use
codex_strip_ansi()orcodex_run_exec()to clean - Stdin input (Bash mode): Use redirect format (
codex exec - < file) for reliable input - Timeout: Bash tool has max 600s (10 minutes) timeout. MCP mode timeout is managed by MCP framework.
- Background agents: Background subagents (
run_in_background: true) require pre-approved Bash permissions in~/.claude/settings.jsonor.claude/settings.json. Without pre-approval, Bash tool calls are auto-denied because permission prompts are unavailable in background mode.
Error Handling
CLI Unavailable
If codex command is not found:
- Inform user: "Codex CLI is not installed or not in PATH"
- Offer to proceed with Claude-only mode
- Continue with standard Claude Code workflow
Codex Timeout or Error
If codex exec returns non-zero exit code or times out:
- Check error message in output file
- Retry once with simplified prompt
- If still failing, proceed manually and inform user
Bash Tool Timeout
Bash tool has max 600s (10 minutes) timeout. For long-running tasks:
- Set appropriate
codex.wait_timeoutsetting - Consider breaking tasks into smaller parts
- Use
run_in_background: truefor background execution
Structured Communication Protocol
This plugin uses a minimal protocol header to enable structured communication between Claude Code and Codex CLI.
Protocol Header
Every prompt to Codex includes a ~15-line protocol header:
## Protocol (codex-collab/v1)
format: yaml
rules:
- respond with exactly one top-level YAML mapping
- include required fields: type, id, status, body
- if unsure or blocked, use type=action_request with clarifying questions
types:
task_card: {body: title, context, requirements, acceptance_criteria, proposed_steps, risks, test_considerations}
result_report: {body: summary, changes, tests, risks, checks}
action_request: {body: question, options, expected_response}
review: {body: verdict, summary, findings, suggestions}
status: [ok, partial, blocked]
verdict: [pass, conditional, fail]
severity: [low, medium, high]
next_action: [continue, stop]
Message Types
| Type | Purpose | Used By |
|---|---|---|
task_card |
Task definition with acceptance criteria | Codex (planning) |
result_report |
Execution results with check status | Claude (reporting) |
action_request |
Request for information or decision | Both |
review |
Review verdict and findings | Codex (review) |
Parsing Strategy
- Lenient: Require only top-level envelope and core keys
- Tolerant: Accept extra fields and minor formatting differences
- Fallback: If YAML parsing fails, fall back to unstructured parsing
Multi-turn Exchange
The protocol supports two independent iteration modes:
Planning Exchange (exchange.*)
Iterative discussion during planning phase:
Flow Control:
next_action: continue- Request further exchangenext_action: stop- Exchange completetype: action_request- Impliesnext_action: continue
Settings:
exchange.enabled: true- Global kill-switchexchange.max_iterations: 3- Max roundsexchange.user_confirm: on_important- User confirmation timingexchange.history_mode: summarize- History management
Termination Conditions:
next_action: stopreceivedexchange.max_iterationsreached- Repeated same question detected
Review Iteration (review.*)
Auto-iterate on review findings:
Flow:
- Codex reviews → CONDITIONAL/FAIL
- Claude fixes issues
- Re-request review
- Repeat until PASS or max reached
Settings:
review.enabled: true- Enable auto-iterationreview.max_iterations: 5- Higher than exchange (goal is clear, diff is small)review.user_confirm: never- Auto-iterate without confirmation
Note: exchange.* and review.* are completely independent (no inheritance).
References
Detailed documentation in references/:
protocol-cheatsheet.yaml- Minimal protocol header for promptsprotocol-schema.yaml- Full protocol schema with examplesplanning-prompt.md- Template for requesting plansreview-prompt.md- Template for requesting reviewscodex-options.md- Codex CLI configuration optionsworkflow-patterns.md- Alternative workflow patterns