Codex Review Loop
Adversarial code review via Codex CLI, structured finding analysis,
HITL-gated fix loop, optional re-verification.
Arguments
--pr <N> — review PR number N (default: auto-detect most recent open PR)
--base <branch> — review changes against base branch
--uncommitted — review uncommitted local changes
Phases
- Scope Resolution — determine review target (PR/branch/uncommitted)
- Codex Review — launch adversarial review via Codex CLI (~20-50 min)
- Finding Analysis — parse raw output into structured findings
- Atomic Fix Loop — fix, verify, commit each approved finding
- Re-review Loop — re-run review until 0 findings (max 3 iterations)
- Final Report — summary of all findings, fixes, and verification status
Phase 1: Scope Resolution
Determine the review target and extract the base branch.
- PR mode (default): Use
gh pr view / gh pr list to resolve base branch
and display PR metadata (title, file count, additions/deletions).
- Branch mode (
--base): Use specified base branch directly.
- Uncommitted mode (
--uncommitted): Review working tree changes.
If no argument is given, auto-detect the user's most recent open PR and confirm.
Phase 2: Codex Review
Launch the adversarial review as a background process.
- Run the review script with
run_in_background=true:bash <skill-dir>/scripts/codex-subagent.sh --base <branch>
Note: Codex CLI v0.105.0+ does not support combining --base/--commit
with a custom prompt. The built-in review logic is used automatically.
For --uncommitted mode (no diff target), pipe stdin for custom instructions:cat <prompt-file> | bash <skill-dir>/scripts/codex-subagent.sh --uncommitted
- Inform the user the review is running (~20-50 min).
- The script parses Codex output and returns the final review text. Review
rollouts intentionally remain persistent. If terminal output is lost, use
codex resume --include-non-interactive to locate the review, or
codex resume <SESSION_ID> when its ID is known. Do not add
--ephemeral to the wrapper. The wrapper also relies on the configured
non-interactive approval/sandbox policy because Codex CLI 0.147.0 removed
the historical --full-auto argument from exec review.
Error handling
| Exit code |
Meaning |
Action |
| 0 |
Success |
Proceed to Phase 3 |
| 1 |
Codex error |
Show error, offer retry or abort |
| 127 |
codex not found |
Guide: npm i -g @openai/codex |
Environment overrides
| Variable |
Purpose |
CODEX_REVIEW_MODEL |
Override Codex model |
CODEX_REVIEW_REASONING |
Override reasoning effort |
Phase 3: Finding Analysis
Parse the raw Codex output into structured findings.
References
- Schema:
references/schemas/review-findings.md — field definitions,
severity/category/effort enums, status lifecycle
- Convention rules:
.agents/skills/project-conventions/conventions.md —
project coding conventions to cross-reference
Severity escalation/downgrade guide
- Escalate to Critical: Unvalidated external input, secret exposure,
injection vectors, data integrity compromise
- Escalate to High: API contract change without test update, possible
NoneType error, blocking I/O in async context
- Downgrade to Medium: Correct functionality but violates conventions,
duplicate logic, unnecessary complexity
- Downgrade to Low: Pure style, unused import, missing docstring
Convention-to-category mapping
- Typing violations (dict, Mapping, object, getattr) ->
typing
- Anti-patterns (speculative fallbacks, duplicate state) ->
convention
- Structure violations (core/modules boundary, DI bypass) ->
architecture
- Testing gaps (contract change without test update) ->
testing
Process
- Parse each finding from the raw output
- Assign severity and category using the schema definitions and guide above
- Cross-reference with project conventions
- Estimate fix effort
- Deduplicate (keep the most severe instance)
- Sort: severity desc, file path asc
HITL Gate 1: Finding Review
Present all findings to the user as a summary table
(ID, severity, category, file:line, title, effort).
Ask the user to choose a fix scope:
- Fix all (recommended)
- Fix Critical/High only
- Report only (no fixes)
Phase 4: Atomic Fix Loop
For each approved finding, execute an atomic fix-verify-commit cycle.
Per finding:
- Fix: Read target file(s), apply the fix.
- HITL Gate 2 (conditional): For Critical/High findings that modify existing
logic (not just adding new code), show the current and proposed code to the
user for confirmation. Medium/Low findings are auto-fixed.
- Verify (all must pass):
uvx ruff check .
uvx ruff format --check . (auto-fix and re-check if needed)
uv run ty check
uv run pytest (mapped test files, or full suite if no mapping found)
- Commit:
fix(review): P{i} - {title}
- On failure: Roll back changes, mark finding as
skipped, continue to next.
Phase 5: Re-review Loop
After all fixes are committed, automatically re-run the Codex review
to check for regressions or new issues introduced by the fixes.
Loop behaviour
- Re-run Codex review (
--base <branch>) against the same base.
- Parse findings (Phase 3) and present to user (HITL Gate 1).
- If 0 findings → loop terminates, proceed to Final Report.
- If findings exist → execute Phase 4 (fix-verify-commit), then repeat
from step 1.
Safety limits
- Max iterations: 3 (initial review + 2 re-reviews).
After 3 iterations, terminate the loop regardless of remaining findings
and output the Final Report with unresolved items noted.
- Escalation: If the same finding recurs across 2 consecutive iterations,
mark it as
wont_fix and skip in subsequent iterations.
HITL override
At each re-review result, the user may choose:
- Continue — proceed with fixes (default when findings > 0)
- Stop — terminate the loop early and output Final Report
Final Report
Output a summary including:
- PR metadata (number, title, base/head)
- Loop iteration count and termination reason (clean / max iterations / user stop)
- Findings table (ID, severity, category, title, status, commit hash)
- Commit stack
- Verification status (ruff, ty, pytest)
1---2name: codex-review-loop3description: Adversarial PR code review using Codex CLI. Codex review (~20-50 min) -> structured findings -> HITL approval -> fix loop.4---56# Codex Review Loop78Adversarial code review via Codex CLI, structured finding analysis,9HITL-gated fix loop, optional re-verification.1011## Arguments1213- `--pr <N>` — review PR number N (default: auto-detect most recent open PR)14- `--base <branch>` — review changes against base branch15- `--uncommitted` — review uncommitted local changes1617## Phases18191. **Scope Resolution** — determine review target (PR/branch/uncommitted)202. **Codex Review** — launch adversarial review via Codex CLI (~20-50 min)213. **Finding Analysis** — parse raw output into structured findings224. **Atomic Fix Loop** — fix, verify, commit each approved finding235. **Re-review Loop** — re-run review until 0 findings (max 3 iterations)246. **Final Report** — summary of all findings, fixes, and verification status2526---2728## Phase 1: Scope Resolution2930Determine the review target and extract the base branch.3132- **PR mode** (default): Use `gh pr view` / `gh pr list` to resolve base branch33 and display PR metadata (title, file count, additions/deletions).34- **Branch mode** (`--base`): Use specified base branch directly.35- **Uncommitted mode** (`--uncommitted`): Review working tree changes.3637If no argument is given, auto-detect the user's most recent open PR and confirm.3839---4041## Phase 2: Codex Review4243Launch the adversarial review as a background process.44451. Run the review script with `run_in_background=true`:46 ```47 bash <skill-dir>/scripts/codex-subagent.sh --base <branch>48 ```49 Note: Codex CLI v0.105.0+ does not support combining `--base`/`--commit`50 with a custom prompt. The built-in review logic is used automatically.51 For `--uncommitted` mode (no diff target), pipe stdin for custom instructions:52 ```53 cat <prompt-file> | bash <skill-dir>/scripts/codex-subagent.sh --uncommitted54 ```552. Inform the user the review is running (~20-50 min).563. The script parses Codex output and returns the final review text. Review57 rollouts intentionally remain persistent. If terminal output is lost, use58 `codex resume --include-non-interactive` to locate the review, or59 `codex resume <SESSION_ID>` when its ID is known. Do not add60 `--ephemeral` to the wrapper. The wrapper also relies on the configured61 non-interactive approval/sandbox policy because Codex CLI 0.147.0 removed62 the historical `--full-auto` argument from `exec review`.6364### Error handling6566| Exit code | Meaning | Action |67|-----------|---------|--------|68| 0 | Success | Proceed to Phase 3 |69| 1 | Codex error | Show error, offer retry or abort |70| 127 | codex not found | Guide: `npm i -g @openai/codex` |7172### Environment overrides7374| Variable | Purpose |75|----------|---------|76| `CODEX_REVIEW_MODEL` | Override Codex model |77| `CODEX_REVIEW_REASONING` | Override reasoning effort |7879---8081## Phase 3: Finding Analysis8283Parse the raw Codex output into structured findings.8485### References8687- **Schema**: `references/schemas/review-findings.md` — field definitions,88 severity/category/effort enums, status lifecycle89- **Convention rules**: `.agents/skills/project-conventions/conventions.md` —90 project coding conventions to cross-reference9192### Severity escalation/downgrade guide9394- **Escalate to Critical**: Unvalidated external input, secret exposure,95 injection vectors, data integrity compromise96- **Escalate to High**: API contract change without test update, possible97 NoneType error, blocking I/O in async context98- **Downgrade to Medium**: Correct functionality but violates conventions,99 duplicate logic, unnecessary complexity100- **Downgrade to Low**: Pure style, unused import, missing docstring101102### Convention-to-category mapping103104- Typing violations (dict, Mapping, object, getattr) -> `typing`105- Anti-patterns (speculative fallbacks, duplicate state) -> `convention`106- Structure violations (core/modules boundary, DI bypass) -> `architecture`107- Testing gaps (contract change without test update) -> `testing`108109### Process1101111. Parse each finding from the raw output1122. Assign severity and category using the schema definitions and guide above1133. Cross-reference with project conventions1144. Estimate fix effort1155. Deduplicate (keep the most severe instance)1166. Sort: severity desc, file path asc117118---119120## HITL Gate 1: Finding Review121122Present all findings to the user as a summary table123(ID, severity, category, file:line, title, effort).124125Ask the user to choose a fix scope:126- Fix all (recommended)127- Fix Critical/High only128- Report only (no fixes)129130---131132## Phase 4: Atomic Fix Loop133134For each approved finding, execute an atomic fix-verify-commit cycle.135136### Per finding:1371381. **Fix**: Read target file(s), apply the fix.1392. **HITL Gate 2** (conditional): For Critical/High findings that modify existing140 logic (not just adding new code), show the current and proposed code to the141 user for confirmation. Medium/Low findings are auto-fixed.1423. **Verify** (all must pass):143 - `uvx ruff check .`144 - `uvx ruff format --check .` (auto-fix and re-check if needed)145 - `uv run ty check`146 - `uv run pytest` (mapped test files, or full suite if no mapping found)1474. **Commit**: `fix(review): P{i} - {title}`1485. **On failure**: Roll back changes, mark finding as `skipped`, continue to next.149150---151152## Phase 5: Re-review Loop153154After all fixes are committed, automatically re-run the Codex review155to check for regressions or new issues introduced by the fixes.156157### Loop behaviour1581591. Re-run Codex review (`--base <branch>`) against the same base.1602. Parse findings (Phase 3) and present to user (HITL Gate 1).1613. If **0 findings** → loop terminates, proceed to Final Report.1624. If findings exist → execute Phase 4 (fix-verify-commit), then repeat163 from step 1.164165### Safety limits166167- **Max iterations**: 3 (initial review + 2 re-reviews).168 After 3 iterations, terminate the loop regardless of remaining findings169 and output the Final Report with unresolved items noted.170- **Escalation**: If the same finding recurs across 2 consecutive iterations,171 mark it as `wont_fix` and skip in subsequent iterations.172173### HITL override174175At each re-review result, the user may choose:176- **Continue** — proceed with fixes (default when findings > 0)177- **Stop** — terminate the loop early and output Final Report178179---180181## Final Report182183Output a summary including:184- PR metadata (number, title, base/head)185- Loop iteration count and termination reason (clean / max iterations / user stop)186- Findings table (ID, severity, category, title, status, commit hash)187- Commit stack188- Verification status (ruff, ty, pytest)