
codex-collaboration
by masuP9
Claude Code と OpenAI Codex CLI を協調させてタスクを実行するプラグイン
SKILL.md
name: Codex Collaboration description: This skill should be used when the user asks to "collaborate with Codex", "use Codex for planning", "get Codex review", "delegate to Codex", "Codexと協調", "Codexにレビューを依頼", "Codexに計画を作成させたい", or mentions coordinating tasks between Claude Code and Codex CLI.
Codex Collaboration Skill
Coordinate tasks between Claude Code and OpenAI Codex CLI using a review-based workflow where Codex handles planning and review while Claude Code handles implementation.
Overview
This skill enables effective collaboration between two AI systems:
- Codex: Planning, code review, architectural decisions
- Claude Code: Implementation, file operations, testing
The primary pattern is "Review Type" where Codex creates plans and reviews implementation, while Claude Code executes the actual work.
Key Feature: WSL環境では、Codexは新しいペインで起動するため、リアルタイムで出力を確認できます。完了は自動検知されます。その他の環境では現在のターミナルで実行されます。
Alternative Mode: /collab-attachコマンドで既存のCodexペインに接続し、永続的なコラボレーションが可能です(tmux環境のみ)。
Prerequisites
Before starting collaboration:
- Verify
codexCLI is available:which codexorcodex --version - Verify terminal launcher is available:
- WSL:
which wt.exe(Windows Terminal) - Linux:
which gnome-terminalorwhich xterm
- WSL:
- Check for project settings in
.claude/codex-collab.local.md - If Codex CLI unavailable, 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: Launch Codex for Planning (New Pane)
- Prepare files in project directory:
CODEX_OUTPUT="$(pwd)/.codex-plan-output.md"
CODEX_PROMPT="$(pwd)/.codex-plan-prompt.txt"
rm -f "$CODEX_OUTPUT"
cat > "$CODEX_PROMPT" << 'EOF'
[Planning prompt content]
EOF
- Launch Codex in a new pane:
tmux mode (recommended - instant completion detection):
# Unique signal: PID + timestamp + random suffix to avoid collisions
SIGNAL="codex-plan-$$-$(date +%s)-$RANDOM"
tmux split-window -h -d \
"cd \"$(pwd)\"; \
cat [PROMPT_FILE] | codex exec -s read-only - 2>&1 | tee [OUTPUT_FILE]; \
echo '=== CODEX_DONE ===' >> [OUTPUT_FILE]; \
tmux wait-for -S \"$SIGNAL\""
WSL / Windows Terminal:
# Note: using ; instead of && so marker is written even on Codex failure
wt.exe -w -1 -d "$(pwd)" -p Ubuntu wsl.exe zsh -i -l -c "cat [PROMPT_FILE] | codex exec -s read-only - 2>&1 | tee [OUTPUT_FILE]; echo '=== CODEX_DONE ===' >> [OUTPUT_FILE]"
- Wait for completion:
tmux mode (signal-based):
# Note: Requires GNU coreutils `timeout`. On macOS: `brew install coreutils` (provides `gtimeout`)
timeout 180s tmux wait-for "$SIGNAL" && echo "Codex completed"
wt/inline mode (file polling):
for i in {1..120}; do
if grep -q "=== CODEX_DONE ===" "$CODEX_OUTPUT" 2>/dev/null; then
echo "Codex completed after ${i}s"
break
fi
sleep 1
done
- Read results from output file
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: Launch Codex for Review (New Pane)
After implementation:
- Stage changes for Codex visibility (important!):
git add -A
git reset -- .codex-*.md .codex-*.txt 2>/dev/null || true
Why? Staging ensures all changes are visible to Codex regardless of its file discovery method. Some tools may use
git ls-files(which only shows tracked files) or respect.gitignore. Staging guarantees consistency.Note: This is staging only, not a commit. After review, you can optionally run
git resetto unstage if needed.Note: The
git resetline explicitly unstages temporary files (.codex-*.md,.codex-*.txt) to ensure they are not included in the review, even if the user's project doesn't have a.gitignorefor these files.
- Prepare review files:
CODEX_REVIEW="$(pwd)/.codex-review-output.md"
REVIEW_PROMPT="$(pwd)/.codex-review-prompt.txt"
rm -f "$CODEX_REVIEW"
cat > "$REVIEW_PROMPT" << 'EOF'
[Review prompt with original plan and diff summary]
EOF
- Launch Codex for review:
tmux mode (recommended):
# Unique signal: PID + timestamp + random suffix to avoid collisions
SIGNAL="codex-review-$$-$(date +%s)-$RANDOM"
tmux split-window -h -d \
"cd \"$(pwd)\"; \
cat [REVIEW_PROMPT] | codex exec -s read-only - 2>&1 | tee [CODEX_REVIEW]; \
echo '=== CODEX_DONE ===' >> [CODEX_REVIEW]; \
tmux wait-for -S \"$SIGNAL\""
# Note: Requires GNU coreutils `timeout`. On macOS: `brew install coreutils`
timeout 180s tmux wait-for "$SIGNAL" && echo "Review completed"
wt mode:
# Note: using ; instead of && so marker is written even on Codex failure
wt.exe -w -1 -d "$(pwd)" -p Ubuntu wsl.exe zsh -i -l -c "cat [REVIEW_PROMPT] | codex exec -s read-only - 2>&1 | tee [CODEX_REVIEW]; echo '=== CODEX_DONE ===' >> [CODEX_REVIEW]"
for i in {1..120}; do
if grep -q "=== CODEX_DONE ===" "$CODEX_REVIEW" 2>/dev/null; then
break
fi
sleep 1
done
- Read and process review results
The review prompt must request:
- Design alignment check
- Bug/vulnerability detection
- Improvement suggestions
- Verdict: Pass / Fail / Conditional
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:
---
model: o4-mini
sandbox: read-only
---
# Project-specific instructions
Parse YAML frontmatter for:
model: Codex model to usesandbox: read-only | workspace-write | danger-full-accessexchange.enabled: Enable planning exchange (default: true)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)review.enabled: Enable review iteration (default: true)review.max_iterations: Maximum rounds for review iteration (default: 5)review.user_confirm: When to ask user confirmation for reviews (default: never)
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:
sandbox: read-only- Codex cannot modify filesexchange.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 confirmation
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
Launching Codex in New Pane
WSL / Windows Terminal (Pane - Default)
# Output files in project directory (shared between WSL sessions)
CODEX_OUTPUT="$(pwd)/.codex-output.md"
CODEX_PROMPT="$(pwd)/.codex-prompt.txt"
rm -f "$CODEX_OUTPUT"
# Write prompt to file
cat > "$CODEX_PROMPT" << 'EOF'
Your prompt here
EOF
# Launch in new pane (use cat | codex exec - format)
wt.exe -w -1 -d "$(pwd)" -p Ubuntu wsl.exe zsh -i -l -c "cat [PROMPT_FILE] | codex exec -s read-only - 2>&1 | tee [OUTPUT_FILE] ; echo '=== CODEX_DONE ===' >> [OUTPUT_FILE]"
# Auto-detect completion (poll for marker)
for i in {1..120}; do
if grep -q "=== CODEX_DONE ===" "$CODEX_OUTPUT" 2>/dev/null; then
echo "Codex completed after ${i}s"
break
fi
sleep 1
done
Native Linux (gnome-terminal)
CODEX_OUTPUT="$(pwd)/.codex-output.md"
CODEX_PROMPT="$(pwd)/.codex-prompt.txt"
rm -f "$CODEX_OUTPUT"
gnome-terminal -- bash -c "cat $CODEX_PROMPT | codex exec -s read-only - 2>&1 | tee $CODEX_OUTPUT ; echo '=== CODEX_DONE ===' >> $CODEX_OUTPUT"
Native Linux (xterm)
CODEX_OUTPUT="$(pwd)/.codex-output.md"
CODEX_PROMPT="$(pwd)/.codex-prompt.txt"
rm -f "$CODEX_OUTPUT"
xterm -e bash -c "cat $CODEX_PROMPT | codex exec -s read-only - 2>&1 | tee $CODEX_OUTPUT ; echo '=== CODEX_DONE ===' >> $CODEX_OUTPUT"
Codex CLI Options
-m, --model <model>- Specify model (e.g., o4-mini, o3)-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
- 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) - Project directory: Output files saved in project directory (not
/tmp) to share between WSL sessions. These files (.codex-*.md,.codex-*.txt) are explicitly unstaged aftergit add -Ato ensure they don't appear in review diffs - Completion marker:
=== CODEX_DONE ===appended to output file for auto-detection - Stdin input: Use
cat file | codex exec -format to avoid escaping issues
Error Handling
Terminal Launcher Unavailable
If wt.exe is not available (non-WSL/Linux環境):
- Fall back to running
codex execin current terminal - Inform user: "WSL環境ではないため、現在のターミナルでCodexを実行します。完了まで出力は表示されません。"
- 出力はファイルに保存されるので、完了後に結果を確認できます
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 returns error:
- Check error message in output file
- Retry once with simplified prompt
- If still failing, proceed manually and inform user
Auto-detection Timeout
If 120 seconds pass without detecting completion marker:
- Ask user if Codex is still running
- Offer to extend wait time or read partial output
- Check output file manually:
cat "$CODEX_OUTPUT"
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).
Alternative: Persistent Collaboration with Attach Mode
For ongoing collaboration with an existing Codex session, use /collab-attach:
Requirements
- Must be inside a tmux session (
$TMUXmust be set) - Codex must be running in interactive mode in another pane
Usage
# Start Codex in a new pane (interactive mode)
tmux split-window -h 'codex'
# Send prompts to the existing Codex pane
/collab-attach この機能の設計を考えて
# Check status
/collab-attach status
# Capture output
/collab-attach capture
# Detach from pane (clear stored pane ID)
/collab-attach detach
When to Use Attach Mode
- Persistent context: Codex maintains conversation history across multiple prompts
- Interactive exploration: Quick back-and-forth discussions with Codex
- Manual control: You control when to send prompts and can view Codex's real-time output
Differences from /collab
| Feature | /collab | /collab-attach |
|---|---|---|
| Codex mode | exec (single prompt) | Interactive (persistent) |
| Context | Stateless per call | Maintained across calls |
| Pane management | Auto-creates and closes | Uses existing pane |
| Best for | Structured workflows | Exploratory discussions |
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
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です