agentleFS
kohojkohoj/skills/codex-collab/SKILL.md

codex-collab

Skill1 starsChanged 7 months agoMITView on GitHub

Background dual-agent collaboration with Codex CLI. Sends tasks to Codex via `codex exec` in the background, captures JSONL output, and integrates results without blocking Claude Code. No tmux, no Terminal windows. Use when asked to "codex collab", "dual agent", "pair with codex", "codex tmux", "collaborate with codex", "let codex help", or "spiral coding".

  • Deletes or force-pushes
  • Installs packages

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. 0 are common, 17 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 17

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check that codex is available:

    line 59
  2. Very specific:

    If codex is NOT_FOUND, stop and tell the user:

    line 67
  3. Distinctive:

    Use the current working directory or the git repository root:

    line 74
  4. Distinctive:

    Use single quotes around the prompt text in the echo to avoid shell expansion

    line 119
  5. Distinctive:

    When you need the result (or are notified the background task completed), read the output files:

    line 142
  6. Very specific:

    If STILL_RUNNING, the background Bash command hasn't completed yet.

    line 150
  7. Distinctive:

    If there are errors, check:

    line 174
  8. Distinctive:

    After receiving Codex's response:

    line 193
  9. Distinctive:

    Analyze: Read and understand what Codex said

    line 195
  10. Distinctive:

    If you and Codex agree -> execute the plan (edit files, run tests, etc.)

    line 198
  11. Distinctive:

    If you disagree -> explain the disagreement to the user, ask for direction

    line 199
  12. Distinctive:

    If more context needed -> send a follow-up task to Codex (new task ID)

    line 200
  13. Distinctive:

    If Codex found something you missed -> investigate it yourself first

    line 201
  14. Distinctive:

    Challenge: Ask Codex to find holes in your implementation

    line 209
  15. Distinctive:

    When the collaboration is complete:

    line 221
  16. Distinctive:

    When sending prompts to Codex:

    line 233
  17. Distinctive:

    One task per message: Don't bundle multiple unrelated questions.

    line 237
  18. Very specific:

    Codex not in git repo: Ensure -C points to a git repository

    line 253
  19. Very specific:

    Codex exec fails: Check the .err file for error details

    line 254
  20. Very specific:

    Non-blocking: ALWAYS use run_in_background: true when sending tasks to Codex.

    line 265
  21. Very specific:

    No Terminal windows: NEVER use open -a Terminal, osascript, or any command that opens GUI windows.

    line 267
  22. Distinctive:

    Transparency: Always show the user what you're sending to Codex and what Codex responded.

    line 271
  23. Distinctive:

    Don't send vague "what do you think?" messages.

    line 276

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

/codex-collab — Claude + Codex Background Collaboration

You are running the /codex-collab skill. This sends tasks to Codex CLI via codex exec --full-auto --json in the background, captures structured JSONL output, and integrates results — all without blocking Claude Code or opening any extra windows.

This is NOT the same as codex:codex-rescue (which uses the shared Codex runtime). This skill runs a standalone Codex process per task.


Architecture

 Claude Code (foreground)              Codex (background process)
 ┌──────────────────────┐              ┌──────────────────────┐
 │                      │   Bash bg    │                      │
 │  Send task ──────────────────────►  │  codex exec          │
 │                      │              │  --full-auto --json  │
 │  Continue working    │              │  > output.jsonl      │
 │  on other things     │              │                      │
 │                      │   Read file  │  Writes JSONL events │
 │  Read results  ◄────────────────── │  to output file      │
 │                      │              │                      │
 │  Integrate & iterate │              └──────────────────────┘
 └──────────────────────┘

Key advantages over v1 (tmux-based):

  • No Terminal windows opened — zero visual clutter
  • Non-blocking — Claude Code continues while Codex works
  • Structured output — JSONL events, no TUI scraping
  • Reliable — no Ink TUI quirks, no tmux send-keys timing issues

Step 0: Preflight

Check that codex is available:

CODEX_BIN=$(which codex 2>/dev/null || echo "")
echo "codex: ${CODEX_BIN:-NOT_FOUND}"
codex --version 2>/dev/null || true

If codex is NOT_FOUND, stop and tell the user:

  • codex: npm install -g @openai/codex or bun install -g @openai/codex

Step 1: Determine Working Directory

Use the current working directory or the git repository root:

WORK_DIR=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
echo "WORK_DIR: $WORK_DIR"

Important: codex exec requires being inside a git repository. If the working directory is not a git repo, warn the user.


Step 2: Create Session Directory

Each collaboration session gets a directory under /tmp/codex-collab/:

SESSION_ID=$(date +%s)
SESSION_DIR="/tmp/codex-collab/$SESSION_ID"
mkdir -p "$SESSION_DIR"
echo "SESSION_DIR: $SESSION_DIR"

Step 3: Send a Task to Codex (Background)

To send a task to Codex, use the Bash tool with run_in_background: true. This is the key difference from v1 — Claude Code is NOT blocked.

The command pattern:

TASK_ID=1  # increment for each task in the session
echo '<prompt_text>' | codex exec \
  --full-auto \
  --json \
  --ephemeral \
  -C "$WORK_DIR" \
  > "$SESSION_DIR/task_${TASK_ID}.jsonl" \
  2> "$SESSION_DIR/task_${TASK_ID}.err"
echo "CODEX_EXIT=$?" >> "$SESSION_DIR/task_${TASK_ID}.status"

Critical rules for the prompt:

  • Use single quotes around the prompt text in the echo to avoid shell expansion
  • For prompts containing single quotes, use a heredoc instead:
    codex exec --full-auto --json --ephemeral -C "$WORK_DIR" \
      > "$SESSION_DIR/task_${TASK_ID}.jsonl" \
      2> "$SESSION_DIR/task_${TASK_ID}.err" \
      << 'PROMPT'
    Your prompt text here, can contain any characters
    PROMPT
    echo "CODEX_EXIT=$?" >> "$SESSION_DIR/task_${TASK_ID}.status"

Always use run_in_background: true for the Bash tool call so Claude Code can continue working while Codex processes the task.

Tell the user:

Codex 任务 #N 已在后台启动,你可以继续其他工作。稍后我会检查结果。


Step 4: Check Task Status

When you need the result (or are notified the background task completed), read the output files:

# Check if task is done
cat "$SESSION_DIR/task_${TASK_ID}.status" 2>/dev/null || echo "STILL_RUNNING"

If STILL_RUNNING, the background Bash command hasn't completed yet. You'll be notified automatically when it finishes — do NOT poll or sleep.


Step 5: Extract the Response

Once the task is complete, read the JSONL output:

cat "$SESSION_DIR/task_${TASK_ID}.jsonl"

Parse the JSONL events. The key event types:

  • {"type":"thread.started","thread_id":"..."} — session started
  • {"type":"turn.started"} — a turn began
  • {"type":"item.completed","item":{"type":"agent_message","text":"..."}} — Codex's response text
  • {"type":"item.completed","item":{"type":"tool_call",...}} — Codex executed a tool
  • {"type":"item.completed","item":{"type":"tool_output",...}} — tool output
  • {"type":"turn.completed","usage":{...}} — turn finished with token usage

Extract the agent_message text from item.completed events. That is Codex's response.

If there are errors, check:

cat "$SESSION_DIR/task_${TASK_ID}.err"

Present the response to the user:

Codex 回复 (任务 #N):
────────────────────────────────────────
<extracted response>
────────────────────────────────────────

Step 6: Spiral Collaboration Loop

After receiving Codex's response:

  1. Analyze: Read and understand what Codex said
  2. Synthesize: Combine Codex's insight with your own analysis
  3. Act or Iterate:
    • If you and Codex agree -> execute the plan (edit files, run tests, etc.)
    • If you disagree -> explain the disagreement to the user, ask for direction
    • If more context needed -> send a follow-up task to Codex (new task ID)
    • If Codex found something you missed -> investigate it yourself first

Collaboration patterns:

  • Divide and conquer: You handle file A, send Codex to review file B
  • Verify: You implement, send Codex to review your changes
  • Brainstorm: You propose approach A, ask Codex for alternatives
  • Debug: You share error context, ask Codex for diagnosis
  • Challenge: Ask Codex to find holes in your implementation

For each iteration, increment the task ID and go back to Step 3.

Important: Since each codex exec is a fresh process, you must include sufficient context in each prompt. Codex does NOT remember previous tasks. Include relevant file paths, previous decisions, and constraints.


Step 7: Cleanup

When the collaboration is complete:

rm -rf "$SESSION_DIR"

Tell the user: "Codex 协作已完成,临时文件已清理。"


Prompt Composition Guidelines

When sending prompts to Codex:

  1. Be an operator, not a collaborator. Give Codex clear, scoped tasks.
  2. Provide context inline. Tell Codex which files to look at by path.
  3. One task per message. Don't bundle multiple unrelated questions.
  4. Be specific about output format. Tell Codex what you want back: a diff, a list of issues, a yes/no verdict, etc.
  5. Include the working directory context. Codex runs with -C $WORK_DIR so it can read files in the repo, but explicit paths help.

Example prompts:

  • "Review src/auth.ts for security issues. Focus on token handling. List each issue with file:line and severity."
  • "What's the simplest way to add rate limiting to the /api/chat endpoint? Return a concrete implementation plan."
  • "Find all places where we catch errors but don't log them. Return file paths and line numbers."
  • "Read the diff in CHANGES.md and write a changelog entry for it."

Error Handling

  • Codex not in git repo: Ensure -C points to a git repository
  • Codex exec fails: Check the .err file for error details
  • Timeout: codex exec has no built-in timeout. If a task seems stuck (background process not completing after 10+ minutes), inform the user and consider killing the process
  • Multiple concurrent tasks: Each task gets its own files in $SESSION_DIR, so multiple background tasks can run simultaneously without conflict

Important Rules

  • Non-blocking: ALWAYS use run_in_background: true when sending tasks to Codex. Claude Code should NEVER block waiting for Codex.
  • No Terminal windows: NEVER use open -a Terminal, osascript, or any command that opens GUI windows. Everything runs headlessly.
  • No tmux: This skill does NOT use tmux. All interaction is through codex exec and file I/O.
  • Transparency: Always show the user what you're sending to Codex and what Codex responded. No hidden conversations.
  • No blind trust: Codex's suggestions should be verified. Don't apply changes without understanding them first.
  • Keep it focused: Each Codex task should have a clear purpose. Don't send vague "what do you think?" messages.
  • Context per task: Each codex exec is stateless. Include all necessary context in each prompt.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.