$npx -y skills add ThibautBaissac/rails_ai_agents --skill codex-reviewGet an independent second opinion from OpenAI Codex CLI on a plan, diff, spec, or Claude's last response. Use when the user asks to "get a second opinion", "have codex review", "cross-check with codex", or wants adversarial review of Claude's output. Argument is one of plan|diff|
| 1 | # /codex-review — Independent second opinion from Codex CLI |
| 2 | |
| 3 | Argument: `$ARGUMENTS` — one of `plan` | `diff` | `spec` | `last-response`. Default `last-response`. |
| 4 | |
| 5 | Never fall back to reviewing Claude's own output if Codex fails. If Codex can't run, say so and stop. |
| 6 | |
| 7 | ## 1. Preflight |
| 8 | |
| 9 | Run in order. Stop cleanly on first failure: |
| 10 | |
| 11 | ```bash |
| 12 | command -v codex >/dev/null 2>&1 || { echo "codex CLI not found. Install: https://github.com/openai/codex"; exit 0; } |
| 13 | codex login status 2>&1 | grep -qi "logged in" || { echo "codex not logged in. Run: codex login"; exit 0; } |
| 14 | ``` |
| 15 | |
| 16 | ## 2. Resolve target |
| 17 | |
| 18 | - **`last-response`** (default): identify your *previous substantive assistant turn* (the last turn with user-facing prose — skip turns that are pure tool calls or tool results). Write that prose verbatim to a temp file via the Write tool: `$(mktemp -t codex-review).md`. Record the path as `$TARGET_FILE`. |
| 19 | - **`plan`**: if there is an active in-conversation plan, write it to a temp file as above. Otherwise pick the newest file under `./.claude/plans/` (`ls -t ./.claude/plans/*.md 2>/dev/null | head -1`). If neither exists, report "no plan found" and stop. |
| 20 | - **`spec`**: pick the newest `spec.md` under `./specs/` (`fd -t f 'spec\.md$' ./specs 2>/dev/null | xargs ls -t 2>/dev/null | head -1`). If none, stop. |
| 21 | - **`diff`**: no file needed — Codex reads the repo directly via `codex review --uncommitted`. |
| 22 | |
| 23 | ## 3. Build rubric (skip for `diff`) |
| 24 | |
| 25 | The `diff` target uses `codex review`'s built-in review prompt — do **not** pass a custom rubric there (`--uncommitted` is mutually exclusive with `[PROMPT]` and will error). |
| 26 | |
| 27 | For `plan` | `spec` | `last-response`, write this rubric to `$(mktemp -t codex-rubric).txt`: |
| 28 | |
| 29 | ``` |
| 30 | You are an adversarial reviewer giving a second opinion. Be terse. Do not restate what is correct. |
| 31 | |
| 32 | Check, in order: |
| 33 | 1. Correctness — logic errors, off-by-one, wrong APIs, broken invariants. |
| 34 | 2. Missing edge cases — nulls, empty inputs, concurrent writes, partial failures, auth gaps. |
| 35 | 3. Simpler alternatives — is there a shorter, more conventional, or better-supported approach? |
| 36 | 4. Risk — blast radius, reversibility, data loss, security implications. |
| 37 | |
| 38 | Output format: 4 sections with those exact headings. Skip a section if you have nothing material. No preamble, no summary, no praise. |
| 39 | ``` |
| 40 | |
| 41 | ## 4. Invoke Codex |
| 42 | |
| 43 | Use a single Bash call with 600000ms timeout. Capture stdout and exit code. Do **not** pass `-c model=...` — rely on the user's `~/.codex/config.toml` defaults. |
| 44 | |
| 45 | - **`diff`**: |
| 46 | ```bash |
| 47 | codex review --uncommitted |
| 48 | ``` |
| 49 | - **`plan` | `spec` | `last-response`**: |
| 50 | ```bash |
| 51 | { printf '=== CONTENT TO REVIEW ===\n'; cat "$TARGET_FILE"; printf '\n\n=== REVIEW INSTRUCTIONS ===\n'; cat "$RUBRIC_FILE"; } \ |
| 52 | | codex exec --sandbox read-only --skip-git-repo-check - |
| 53 | ``` |
| 54 | |
| 55 | Pass all content via stdin. Never put file contents on argv. |
| 56 | |
| 57 | ## 5. Emit review |
| 58 | |
| 59 | On exit code `0`: |
| 60 | |
| 61 | ``` |
| 62 | ### Codex Review |
| 63 | |
| 64 | <codex stdout verbatim — no edits, no paraphrase> |
| 65 | ``` |
| 66 | |
| 67 | On non-zero exit or timeout: |
| 68 | |
| 69 | ``` |
| 70 | ### Codex Review (FAILED) |
| 71 | |
| 72 | Codex exited with status <N>. Stderr tail: |
| 73 | <last 20 lines of stderr> |
| 74 | ``` |
| 75 | |
| 76 | Stop after emitting failure. Do not substitute your own review. |
| 77 | |
| 78 | ## 6. Ask before reconciling |
| 79 | |
| 80 | After a successful review, end your turn with one question to the user: |
| 81 | |
| 82 | > Want me to reconcile — decide which points to adopt, reject, or defer? |
| 83 | |
| 84 | Only if the user says yes, produce a `### Reconciliation` section with three bullet lists: **Adopt**, **Reject** (each with a one-line reason), **Defer** (each with a one-line reason to revisit later). Do not rubber-stamp Codex; reject points that are wrong or off-scope. |