/claudex-loop:codex-buildfrom claudex-loop
Delegates implementation of a frozen spec to OpenAI Codex with write access, while Claude reviews diffs and iterates fixes. Use for refactors, migrations, bug fixes, or test writing.
Ships in claudex-loop. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The role-flip of /codex-review: there, Claude builds the plan and Codex critiques read-only. Here, Codex is the builder with write access; Claude is the spec-writer and reviewer. Codex implements a frozen spec end-to-end; Claude judges the diff like a contributor PR, demands proof, and iterates fixes in the same Codex session. The human enters at exactly two points: kickoff and diff sign-off.
Adapted from Peter Steinberger's codex-first pattern (agent-scripts), rebuilt on this house's verified Codex mechanics.
Spec quality decides success. Codex starts with zero session context — everything it needs must be in the prompt. A plan that survived /grill-me-codex or /codex-review already is a frozen spec; that's the ideal input.
codex --version ≥ 0.130 (older CLIs error on the default gpt-5.5 model).codex login; ChatGPT account is fine). On auth/model error, surface it — don't silently retry.-m or model config (e.g. model_reasoning_effort) unless the user asks. Pinning gpt-5.x-codex variants 400s on ChatGPT-account auth; config defaults come from ~/.codex/config.toml.model line from ~/.codex/config.toml (absent = "CLI default"); state it with the resolved tunables. If the user objects, stop before launching the build.codex exec sessions (ChatGPT-account backed, no API key; verified 2026-07-08 — it saved a generated PNG to disk headless). Specs may therefore include "generate these image assets yourself" steps: name exact file paths, dimensions, and style in the prompt contract.exec and resume then need no -C; resume doesn't support -C anyway).| Var | Default | Meaning |
|---|---|---|
SPEC_FILE | PLAN.md | The frozen spec Codex implements. |
MAX_FIX_ROUNDS | 2 | Fix iterations via resume before Claude takes over and finishes directly. |
LOG_FILE | PLAN-REVIEW-LOG.md | Append-only build transcript. If it exists (Act 1/2 ran), append ## Act 3 — Build; else create it. |
PROOF_CMD | from spec | Exact test/verify command Codex must run as proof. If the spec lacks one, ask the user ONE question to get it before launching. |
Echo resolved values before starting.
SPEC_FILE must exist and read as a work order (goal, concrete steps, bounds). No spec → offer /grill-me-codex (interview first) or /codex-review (have a plan, want it stress-tested) instead. If the user insists on building from a rough idea, write the spec WITH them first — that's design, and design stays with Claude.git status -sb. Dirty working tree → STOP and ask the user to commit or stash first. Non-negotiable: Codex writes with full access, and a dirty tree means its diff can't be isolated or cleanly reverted.Never inline-quote the prompt — write it to a temp file. Fill this contract completely; when chained from a grill/review skill, derive it from the plan's sections:
P=$(mktemp)
cat >"$P" <<'EOF'
GOAL: <one paragraph — what done looks like>
SPEC: Read <SPEC_FILE> at the repo root. It is a frozen, already-reviewed spec.
Implement it exactly. If a step is impossible as written, implement the
closest faithful version and report the deviation — do not redesign.
KEY PATHS: <files/dirs Codex will touch or must read first>
CONSTRAINTS: <"don't touch X", style rules, deps that must not change>
NON-GOALS: <explicitly out of scope — from the plan's Out of scope section>
PROOF: Run `<PROOF_CMD>` and include its full output in your report.
OUTPUT: End with a report — files changed (one line each: path + what/why),
proof output, and any deviations from the spec with reasons.
EOF
thread_id)codex exec --yolo --json -o /tmp/codex-build.txt - <"$P" 2>/dev/null | grep '"type":"thread.started"'
- <"$P") — this both avoids quoting bugs AND sidesteps the non-TTY stdin hang (codex exec blocks forever waiting on stdin EOF under Claude Code's Bash tool; feeding the file gives immediate EOF).thread_id from the {"type":"thread.started","thread_id":"..."} line → THREAD_ID. Codex's final report lands in /tmp/codex-build.txt — read that file; don't parse the JSONL stream for content.2>/dev/null suppresses cosmetic MCP/auth stderr noise. Confirm success by the report file + a thread.started line; neither → failed run (auth/model) — stop and tell the user.timeout: 600000 on the Bash tool call (default 2-min tool timeout kills real builds). If the spec is clearly >10 min of work (multi-file feature, migration, anything with image generation), launch with run_in_background: true instead and read the -o file when it exits. Don't kill a quiet background run early — Codex builds are legitimately slow.🔔 CODEX FINISHED — <what> (exit ok/fail) — verifying now — BEFORE any verification output. The user is not watching tool calls; never let a completed build slide silently into the verify phase.Codex's report is advisory. Verify yourself:
git status -sb + read the FULL diff (git diff). Judge it like a contributor PR: correctness, spec fidelity, style match with surrounding code, nothing touched outside scope.PROOF_CMD yourself (or the focused tests for the changed area). Codex's pasted output doesn't count as proof.LOG_FILE under ## Act 3 — Build: ### Round <n> — Codex build + its report summary + ### Claude's verdict + what passed/failed review.Problems found → resume the SAME session (Codex keeps its context; cheaper and better than a fresh run). Write the fix list to a temp file ($P2), same contract discipline: exact problem, exact file, proof expected.
# resume has no --yolo and no -C: run from the repo dir and spell the long flag,
# or Codex inherits config.toml's sandbox (possibly read-only) and can't write.
codex exec resume "$THREAD_ID" --dangerously-bypass-approvals-and-sandbox --json \
-o /tmp/codex-build.txt - <"$P2" 2>/dev/null >/dev/null
Re-verify (Step 3) after each round. After MAX_FIX_ROUNDS failed rounds: STOP delegating — Claude takes over and finishes the remaining fixes directly. Log the takeover. Ping-ponging trivia through delegation burns more than it saves.
Present: 3-bullet summary of what was built, files-changed list, proof-test output (pass/fail, verbatim tail), rounds used, any spec deviations. Ask: "Codex built it, proof passes, diff reviewed. Commit?"
MAX_FIX_ROUNDS — then Claude takes over. No unbounded delegation ping-pong.LOG_FILE is the deliverable — with Acts 1/2 it tells the whole story: grilled → reviewed → built → verified./grill-me-codex or /codex-review first.-codex model variants on ChatGPT-account auth — 400s.--last — capture and use the explicit THREAD_ID (parallel sessions make --last grab the wrong thread). And ECHO the id into the command visibly before running: resume with a missing/garbage id can silently fall back to the most recent session instead of erroring (observed 2026-07-08) — a wrong-target resume looks exactly like a successful one.-o file.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub az9713/claudex-loop-tutorial --plugin claudex-loop3 skills in this plugin
/claudex-loopFour-phase plan hardening (renamed from /crucible 2026-08-16; old triggers still work) — supersedes /grill-me-codex and /grill-with-docs-codex. PHASE 0 RECON — Claude scouts first (codebase + docs on brownfield; prior art, stack, and pitfalls research on greenfield) and drafts an assumptions ledger. PHASE 1 INTERROGATE — confirm the ledger in one batch, then question only the load-bearing decisions one at a time (each with why-it-matters, a recommendation, and what-breaks-if-we-guess-wrong), cosmetic ones batched, with a visible decision map and an accept-all-recommendations escape hatch. PHASE 2 REVIEW — the locked plan goes to PLAN.md and OpenAI Codex adversarially reviews it in a read-only sandbox (VERDICT: APPROVED/REVISE); Claude revises and re-submits to the SAME Codex session until APPROVED or MAX_ROUNDS, then you sign off before any code. PHASE 3 BUILD (optional) — you pick the builder and the models swap jobs: Codex builds via codex-build and Claude reads the full diff + runs the proof itself; Claude builds and a fresh read-only Codex session cross-inspects the diff (on by default, logged opt-out only); either way you approve the final diff. Use when the user says "/claudex-loop", "claudex this", "run the claudex loop", "/crucible" (legacy), "put this through the crucible", "crucible this plan", "grill me then have codex review", "stress-test this plan before we build", or is about to build something high-stakes (auth, schema, concurrency, migrations, payments, greenfield architecture) and wants alignment AND a cross-model sanity check first. Locked plan needing only the Codex loop → /codex-review. Reviewing already-written code → /codex:review. NOT for trivial changes./codex-reviewA standalone adversarial PLAN-review loop where Claude Code (builder) and OpenAI Codex (read-only critic) tag-team an implementation plan before any code is written. Use this when you ALREADY have a plan or a clear idea and just want the cross-model stress-test — no requirements interview first. Claude drafts/loads the plan into PLAN.md, Codex reviews it in a read-only sandbox and returns VERDICT:APPROVED or VERDICT:REVISE, Claude revises and re-submits to the SAME Codex session (context preserved) until APPROVED or a configurable MAX_ROUNDS cap is hit. Human approves the converged plan before code. Use when the user says "/codex-review", "codex review my plan", "have Codex review my plan", "argue this plan with Codex", "adversarial plan review", "make Claude and Codex argue/fight over the plan", or is about to build something high-stakes (auth, schema, concurrency, migrations, payments) and wants a second-model sanity check on the PLAN before implementation. For a guided requirements interview BEFORE the review, use /grill-me-codex instead. NOT for reviewing already-written CODE (that is the Codex plugin's /codex:review) and NOT for trivial changes.Other plugins' skills for the same job