oliver-kriska/claude-elixir-phoenix / targets/amp/skills/phx-codex-loop
phx-codex-loop
UnverifiedFix Elixir/Phoenix code until Codex CLI review comes back clean — bounded review, fix, verify loop before opening a PR. Use when codex is installed and you want an external cross-model critic on your changes before pushing.
Codex Loop (fix until clean)
Critic→Refiner loop with the Codex CLI as external critic: review → fix
approved findings → verify → re-review, until codex is clean or rounds run
out. Codex reviews; Claude fixes. Complements phx-review (Claude panel)
— run either or both before a PR.
Usage
phx-codex-loop # diff vs default branch, interactive
phx-codex-loop --uncommitted # staged + unstaged + untracked
phx-codex-loop --base develop # explicit base branch
phx-codex-loop --auto # auto-approve P0/P1/P2, skip P3
phx-codex-loop --max-rounds 2 # default 3
Iron Laws
- BOUNDED rounds — never exceed --max-rounds (default 3) — each round costs codex quota; report remaining findings instead of looping on
- Verify BEFORE re-review —
mix compile --warnings-as-errors+ tests must pass before burning a codex round on broken code - NEVER commit or push — leave git to the user
- Codex findings get Iron Law scrutiny — decline suggestions that violate an Iron Law, with explanation in the round report
- Skipped findings are reported, never dropped — every finding ends as fixed, declined (with reason), or deferred-by-user
- Missing CLI stops the skill with an install hint — suggest
phx-reviewas the codex-free alternative; never crash
Workflow
Step 1: Preflight
Run command -v codex. If missing: STOP.
Show the install hint (brew install codex or npm i -g @openai/codex,
then codex login; codex doctor to diagnose) and suggest phx-review.
Then two cheap checks that save review rounds:
- Dirty tree (
git status --short, only when using--base): codex inspects working-tree state too and WILL flag local dirt (stray edits, dirty submodules) as findings. Surface the dirt and ask: clean/stash first, or proceed knowing round 1 may spend findings on it. - Missing rubric: if
AGENTS.mdhas no## Review guidelinessection, note once thatphx-initinstalls the Elixir rubric that steers codex priorities — then proceed (it works without, on defaults).
Step 2: Detect Diff Mode
- Flag passed (
--base/--uncommitted) → use as given - Commits ahead of the default branch →
--base {default} - No commits yet →
--uncommitted
Step 3: Review Round (max --max-rounds, default 3)
-
Review — ONE foreground Bash call, explicit
timeout: 600000(large diffs run 10+ min). On timeout with the process alive: ONEuntil [ -f {out} ]; do sleep 5; donewait — never poll-spam orpkilla running review (quota is spent either way). ALWAYS silence the streams — only the-ofile matters (10k+ lines otherwise):codex exec review --base {branch} --ephemeral \ -o /tmp/codex-round-{n}.md > /tmp/codex-round-{n}.log 2>&1NEVER pass custom instructions with a diff-mode flag — the CLI rejects the combination; the rubric comes from AGENTS.md
## Review guidelines(phx-init). Parse the output file, NOT the exit code (0 even with findings). Recipes:references/codex-cli.md.Retired model (exit 1, no
-ofile, log:model is not supported/Model not found): resolve the account default —MODEL=$(codex debug models | jq -r '.models | map(select(.visibility == "list")) | sort_by(.priority) | .[0].slug')— retry once with-m "$MODEL" -c review_model="$MODEL"(both: a pinnedreview_modelbeats-m), reuse it every round, never hardcode a slug. Tell the user once to setmodel/review_model = "$MODEL"in~/.codex/config.toml. -
Clean check — parse the output file; no
- [P{n}]bullets means CLEAN → go to Step 5.
Step 4: Triage, Fix, Verify
-
Triage — emit the findings table (
# | P | file:line | title | proposed action) as visible response text BEFORE anyAskUserQuestioncall — a table composed only in thinking never renders. Then ask approve-or-skip per finding (AskUserQuestion). With--auto: approve P0/P1/P2, skip P3 (list skipped in the round report). -
Fix — apply approved fixes with user-visible diffs. Check each against Iron Laws first (Law 4).
-
Verify — scoped, before the next round:
mix format {changed_files} && \ mix compile --warnings-as-errors && mix test {affected_tests}If verification fails 3 times, STOP with a BLOCKER report — do not burn another codex round on broken code.
-
Next round (n+1) — back to Step 3.
Step 5: Final Report
## Codex Loop Report — {CLEAN | MAX ROUNDS REACHED | BLOCKED}
Rounds: {n}/{max} | Fixed: {n} | Declined (Iron Law): {n} | Deferred: {n}
{per-round: findings → outcome}
{remaining findings if not CLEAN}
On CLEAN: suggest phx-compound for non-obvious fixes, then commit/PR.
On MAX ROUNDS: list remaining findings; offer phx-plan to convert them
into a follow-up plan.
Integration
implement → phx-codex-loop (YOU ARE HERE) → clean → commit/PR → phx-watch-pr --codex
↑ or arrive from phx-review --codex verdict REQUIRES CHANGES
References
references/codex-cli.md— invocation recipes, parse patterns, verified gotchas (CLI 0.142.5; model fallback 0.162.1)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 463k | Updated | Claude CodeCodex | Verified | Install |
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 463k | Updated | Claude CodeCodex | Verified | Install |
| discernment-nudgeanthropics/skillsAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format. | Stars: 195k | Updated | Claude CodeCodex | Verified | Install |
| internal-commsanthropics/skillsA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.). | Stars: 195k | Updated | Claude CodeCodex | Verified | Install |