Codex Iterative Repair Loop (JSON-Schema Review → Repair)

OpenAI's first-party loop recipe: a script alternates a Codex review pass that emits machine-readable findings with a repair pass fed those findings verbatim, looping until validation passes, attempts run out, progress stalls, or a decision needs human review.

prompt
→ Claude
Script alternates two `codex exec` calls: (a) review pass with a JSON schema output ("list remaining issues as machine-readable findings"), (b) repair pass fed those findings verbatim. Loop while findings remain, capped by max attempts. Stops for one of four reasons: validation passes, max attempts reached, remaining delta stops changing, or next decision needs human review.
claude-code

Implementation note

When to use: repair work you want structured rather than freeform — a codebase with known issues where you need machine-readable findings driving fixes, with clear stop conditions. This is OpenAI's first-party loop recipe. How it works: a script alternates two codex exec calls. The review pass emits remaining issues as machine-readable findings conforming to a JSON schema; the repair pass is fed those findings verbatim and fixes them. The loop continues while findings remain and halts for exactly one of four reasons: validation passes, max attempts are reached, the remaining delta stops changing between passes, or the next decision needs human review. Safety: the four enumerated stop conditions are the rail — stalled progress and needs-a-human are first-class exits rather than failure modes discovered later, and the attempt cap bounds spend. The JSON-schema findings double as an audit trail of what the loop believed was wrong at each pass.

Source: OpenAI Cookbook

More review loops

Map codebase with review prompt

Loop/ralphnew

Run a review prompt against your codebase repeatedly until the completion promise resolves, with no iteration cap.

prompt
→ Claude
/ralph-loop "<review prompt>" --completion-promise "CODEBASE MAP COMPLETE" . One ralph loop per discovered codebase (loops until the promise; no iteration cap per v3.8.0 unbounded solving
reviewmedium riskclaude-code

Address review comments, fix CI

Loop/loop

Check your PR for new comments and CI failures, address them, then loop every 5 minutes until all pass.

prompt
→ Claude
/loop 5m check my PR, address review comments, and fix failing CI
reviewmedium riskclaude-code

The nested perfect loop

Loop/loop

A loop wrapping a goal wrapping a review: every 30 minutes, drive all PR review comments to resolved via /review, 10 turns max per pass.

prompt
→ Claude
/loop 30m /goal all PR review comments resolved via /review, stop after 10 turns
reviewhigh riskclaude-code