Address 10+ findings from two rounds of adversarial review of the
previous Step 4/5/7 design. Major changes:
- Use `codex exec --json` so `thread_id` can be parsed deterministically
from the first JSONL line on stdout (bypasses the ~30KB Bash-tool
truncation that could drop stderr metadata in the old flow).
- Capture REPO_ROOT via `git rev-parse --show-toplevel` at Step 2 and
substitute the absolute path literally. Pin the initial exec with
`-C "${REPO_ROOT}"` and prefix every resume with `cd '${REPO_ROOT}' &&`
because `codex exec resume` has no `-C` flag and inherits cwd from
the invoking shell.
- Drop `resume --last` from the fallback chain (cwd filtering is not
enough to distinguish our session from unrelated parallel codex runs).
- Update CODEX_SESSION_ID only on full success (exit 0, no stderr error
line, review file contains VERDICT and findings on REVISE); rotate
to the resumed session's new thread_id each round.
- Harden the "show review" gate (Step 5 "YOUR NEXT MESSAGE" instruction
and Step 6 precondition check) now that --json stdout no longer leaks
review text into the Bash tool result.
- Add strict check order for launch and resume (exit → stderr → review
file) so we never commit a broken session-id on a half-failed run.
- Replace silent fresh-exec fallback with interactive ask / headless
severity-based decision. Fresh-exec prompt rebuilds prior rounds from
conversation history.
- Bare repo / submodule / shell-hostile paths abort at Step 2 with a
clear message rather than failing silently later.
- Conditional cleanup: keep temp files on abort paths for diagnostics.
- Expand REVIEW_ID random to 8 digits.
README: update permissions (add stdout JSONL read, resume-prompt write,
narrower `cd * && ... codex exec resume *` pattern) and troubleshooting
(NOT VERIFIED outcome, bare repo, submodule).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
30 KiB
name, description, user_invocable
| name | description | user_invocable |
|---|---|---|
| adversarial-review | Adversarial AI code/plan review. Codex reviews, Claude fixes, iterative loop until approved. Auto-detects plan/code/code-vs-plan mode. | true |
Adversarial Code Review
Platform: Claude Code only. This skill orchestrates Claude ↔ Codex interaction, where Claude is the executor and Codex is the external reviewer. Running this skill from Codex CLI itself creates a recursive loop — Codex would try to launch itself. If you are Codex — do NOT invoke this skill; perform the review directly.
Sends current work for adversarial review through an external AI model (OpenAI Codex by default). Auto-detects what to review: plan or code. Claude fixes issues based on reviewer feedback and resubmits until approved. Maximum 5 rounds.
When to invoke
/adversarial-review— auto-detect what to review/adversarial-review plan— force plan review/adversarial-review code— force code review/adversarial-review <file-path>— review a specific file (argument contains/or.)- Override reasoning:
/adversarial-review xhighor/adversarial-review medium(one of:medium,high,xhigh) - Override model:
/adversarial-review model:gpt-5.3-codex(argument withmodel:prefix)
Instructions
Placeholders:
${REVIEW_ID},${CODEX_SESSION_ID},${REPO_ROOT}, and${BASE_BRANCH}in the steps below are template placeholders, NOT shell variables. Substitute literal values directly into each tool call. In particular,${REPO_ROOT}is ALWAYS an absolute path captured at Step 2; never replace it with$(pwd).
Step 1: Determine review mode
Determine what to review. Check in priority order:
1. Explicit argument (plan, code, file path) → use it.
- For
plan→ skip all git checks, proceed to step 2 (REVIEW_ID only).
2. Claude Code Plan Mode — if context contains the system message "Plan mode is active" → mode = plan, skip git. In Plan Mode code is not edited, so code/code-vs-plan are impossible.
3. Auto-detect (no explicit argument, not in Plan Mode):
- Check for code changes (any non-empty output means changes exist):
git diff --name-only— unstagedgit diff --cached --name-only— stagedgit diff --name-only ${BASE_BRANCH}...HEAD— branch commits
- Check if a plan exists in the current conversation context (from plan mode, tasks, or discussion).
| Code changes? | Plan in context? | Mode |
|---|---|---|
| No | Yes | plan — review the plan |
| Yes | Yes | code-vs-plan — review implementation against plan |
| Yes | No | code — review code changes |
| No | No | Ask the user what to review |
Step 2: Generate Session ID, capture REPO_ROOT, determine base branch
REVIEW_ID: generate yourself, format {unix_timestamp}-{random_8digit_number}.
Example: 1711872000-48217593. Do NOT use bash — substitute the value directly into commands in the following steps. 8-digit random makes collisions negligible (1 in 10^8 per same-second invocation).
Capture REPO_ROOT:
git rev-parse --show-toplevel
- Exit 0, non-empty output → absolute path. Save literally as
REPO_ROOT(a template placeholder — substitute verbatim into codex commands; do NOT use$(pwd)anywhere). - Exit 128 (bare repo, or not in a work tree) → tell the user:
Cannot run adversarial review — current directory is not inside a git working tree.Abort the skill. - Path contains single quote, double quote,
$, backtick, newline → tell the user:REPO_ROOT path contains shell-special characters; cannot safely construct codex commands.Abort.
Submodule warning: after capturing REPO_ROOT, run:
git rev-parse --show-superproject-working-tree
If this returns non-empty, the user is inside a git submodule. Tell the user: You are inside a submodule. The review will be scoped to this submodule (${REPO_ROOT}), not the parent repo. If you meant to review the parent, invoke from there. Proceed — this is a warning, not an abort.
Determining base branch (only for code and code-vs-plan modes):
For plan mode — skip base branch detection, proceed to step 3.
For other modes, determine the repository's base branch:
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/origin/||'
If the command returns empty (remote HEAD not configured), use fallback:
git rev-parse --verify main 2>/dev/null && echo main || echo master
Save the result as BASE_BRANCH — used in git diff ${BASE_BRANCH}...HEAD below.
Step 3: Prepare review material
Plan review:
- If the plan already exists as a file (in
project/, plan file from Plan Mode, memory, or somewhere in the repo) — use the path directly. Do NOT copy. In Claude Code Plan Mode the plan is always a file. - If the plan is only in the conversation context (outside Plan Mode) — write via Write tool to
/tmp/codex-plan-${REVIEW_ID}.md. - Always print the plan file path for the user so they can open it in their IDE:
Plan for review: <file-path>
Code review:
Collect the list of changed files:
git diff --name-only— unstaged changesgit diff --cached --name-only— staged changes
Merge unstaged + staged (unique paths). If both are empty:
git diff --name-only ${BASE_BRANCH}...HEAD— branch commits (fallback)
Branch diff is used ONLY when there are no local changes — otherwise context bloats.
For branch diff, include the command git diff ${BASE_BRANCH}...HEAD (full diff) in the prompt.
The reviewer has access to the repo and will read full diffs and files on its own. In the prompt (step 4), pass the file list and which git diff commands to run.
Many files (> 50): if the combined list exceeds 50 paths, pass only git commands without the file list — the reviewer will figure it out.
If all sources are empty — no changes to review, inform the user.
Code-vs-plan review: prepare the plan path AND collect the list of changed files (as above).
Step 4: Build the prompt and launch the first round
Build the prompt depending on the mode. All prompts use the adversarial stance.
Prompt for plan review:
<role>
You are a senior adversarial reviewer of implementation plans.
Your job is to break confidence in the plan, not to validate it.
</role>
<operating_stance>
Default to skepticism. Assume the plan has gaps until the evidence says otherwise.
Do not give credit for good intent or likely follow-up work.
If something only works on the happy path, treat that as a real weakness.
</operating_stance>
<task>
Review the implementation plan in <plan-path>.
</task>
<attack_surface>
Check each area. Skip if not applicable:
- Feasibility — will this approach actually work given the codebase and constraints?
- Missing steps — what is forgotten or assumed but not stated?
- Risk areas — what could go wrong during implementation? Data loss? Downtime?
- Sequencing — are steps in the right order? Are there hidden dependencies?
- Alternatives — is there a simpler or more robust approach?
- Rollback — can this be safely reverted if it fails halfway?
- Security — auth, data exposure, injection, unsafe operations
</attack_surface>
<finding_bar>
Each finding MUST answer:
1. What can go wrong? (concrete scenario, not hypothetical)
2. Why is this plan vulnerable? (cite specific section)
3. Impact — what breaks and how badly?
4. Recommendation — specific change to the plan
</finding_bar>
<scope_exclusions>
DO NOT comment on: formatting, wording style, speculative issues without concrete trigger scenario.
</scope_exclusions>
<calibration>
Prefer one strong finding over several weak ones.
If the plan is solid, say so clearly — false positives erode trust.
</calibration>
<output_format>
Use markdown headers for sections: Summary, Findings, Verdict.
Summary: one paragraph — what this plan does and your overall assessment.
Findings: for each finding, use a sub-header with [severity: critical|high|medium] and title.
Include these fields per finding:
- **Section:** which part of the plan
- **What can go wrong:** ...
- **Why vulnerable:** ...
- **Impact:** ...
- **Recommendation:** ...
If no findings: "No actionable findings."
Verdict rules: approve if no findings or all low severity; revise if any high/critical.
Choose exactly one. The LAST line of your response must be one of:
VERDICT: APPROVED
VERDICT: REVISE
</output_format>
Prompt for code review (<= 50 files):
<role>
You are a senior adversarial code reviewer.
Your job is to break confidence in the change, not to validate it.
</role>
<operating_stance>
Default to skepticism. Assume the change can fail in subtle, high-cost,
or user-visible ways until the evidence says otherwise.
Do not give credit for good intent, partial fixes, or likely follow-up work.
If something only works on the happy path, treat that as a real weakness.
</operating_stance>
<task>
Review the code changes in this repo. Changed files:
<file list from --name-only>
Changes include: <unstaged changes / staged changes / unstaged + staged changes / branch changes vs ${BASE_BRANCH}>.
Run <git diff commands> to see the full diffs.
</task>
<attack_surface>
Check each area. Skip if not applicable to this change:
- Auth & permissions: bypasses, privilege escalation, missing checks
- Data integrity: loss, corruption, partial writes, constraint violations
- Race conditions: TOCTOU, concurrent access, deadlocks
- Rollback safety: can this change be safely reverted?
- Schema drift: migrations, backward compatibility, data format changes
- Error handling: swallowed errors, missing retries, cascading failures
- Observability: will operators know when this breaks?
</attack_surface>
<finding_bar>
Each finding MUST answer:
1. What can go wrong? (concrete scenario, not hypothetical)
2. Why is this code vulnerable? (cite specific file and lines)
3. Impact — what breaks and how badly? (data loss > downtime > degraded UX)
4. Recommendation — specific fix with code reference
</finding_bar>
<scope_exclusions>
DO NOT comment on: code style, formatting, naming conventions,
speculative issues without concrete trigger scenario,
"nice to have" improvements unrelated to correctness or safety.
</scope_exclusions>
<calibration>
Prefer one strong finding over several weak ones.
Severity: critical (data loss/security) > high (bug in prod) > medium (edge case).
If the change is solid, say so clearly — false positives erode trust.
</calibration>
<output_format>
Use markdown headers for sections: Summary, Findings, Verdict.
Summary: one paragraph — what this change does and your overall assessment.
Findings: for each finding, use a sub-header with [severity: critical|high|medium] and title.
Include these fields per finding:
- **File:** path/to/file.ext lines N-M
- **What can go wrong:** ...
- **Why vulnerable:** ...
- **Impact:** ...
- **Recommendation:** ...
If no findings: "No actionable findings."
Verdict rules: approve if no findings or all low severity; revise if any high/critical.
Choose exactly one. The LAST line of your response must be one of:
VERDICT: APPROVED
VERDICT: REVISE
</output_format>
Prompt for code review (> 50 files):
Same prompt as above, but the <task> section without the file list:
<task>
Review the code changes in this repo.
Changes include: <unstaged changes / staged changes / ...>.
Run <git diff commands> to see changed files and full diffs.
</task>
Prompt for code-vs-plan review:
Same prompt as code review, but the <task> section is extended:
<task>
Review the code changes in this repo against the implementation plan in <plan-path>.
Changed files:
<file list or empty if > 50>
Changes include: <type>.
Run <git diff commands> to see the full diffs.
</task>
And the following items are added to <attack_surface>:
- Completeness: does the implementation cover all plan steps?
- Deviations: where does the code differ from the plan? Are deviations justified?
- Missing: what from the plan is not yet implemented?
Launching Codex — command template:
Flags:
--json— stdout becomes JSONL events; required for deterministic session-ID capture-m gpt-5.4— model (overridden bymodel:...argument)-c model_reasoning_effort=high— reasoning depth (overridden byxhigh,low, etc.)-s read-only— reviewer only reads, does not write-C "${REPO_ROOT}"— pin codex workdir to absolute repo root-o /tmp/codex-review-${REVIEW_ID}.md— file for capturing final agent text
Prompt delivery: write the prompt to /tmp/codex-prompt-${REVIEW_ID}.md via Write tool, then pass via stdin redirection (- < file). This avoids shell quoting issues with long XML prompts.
Plan Mode note: Writing to /tmp via Write tool may trigger a permission prompt or exit Plan Mode. This is a known Claude Code limitation — Plan Mode restricts edits to the plan file only. If this happens, it does not affect review correctness: the review mode is already determined, and the skill only edits the plan file and /tmp temp files.
timeout 600 codex exec --json \
-m gpt-5.4 \
-c model_reasoning_effort=high \
-s read-only \
-C "${REPO_ROOT}" \
-o /tmp/codex-review-${REVIEW_ID}.md \
- < /tmp/codex-prompt-${REVIEW_ID}.md \
> /tmp/codex-stdout-${REVIEW_ID}.jsonl \
2>/tmp/codex-stderr-${REVIEW_ID}.txt
CRITICAL — the Bash tool result is NOT the review. With
--json, stdout is a machine-readable JSONL event stream (thread.started, turn.started, item.completed, turn.completed). It is not human-readable. The human-readable review exists ONLY in/tmp/codex-review-${REVIEW_ID}.md. Do not attempt to extract review text from the Bash result — there is none.
Important:
- Always wrap
codex execintimeout 600(10 minutes). If Codex hangs — the command exits with code 124. - Use
timeout: 620000parameter in Bash tool for headroom. - The command is synchronous: when it returns, all four files (
-o, stdout jsonl, stderr, prompt) are in their final state. Do NOT use a poll-loop. - With
--json, stderr is empty on success. It contains content only on errors (e.g. "Failed to write last message file ..."). Use stderr for diagnostics, NOT for session-id capture.
Post-launch strict check order (do each before moving to the next):
-
Exit code.
124→ timeout. Tell the user "Reviewer did not respond within 10 minutes" and offer retry. Retry does NOT consume the round counter; max 1 retry per round.≠ 0 and ≠ 124→ launch error. Read/tmp/codex-stderr-${REVIEW_ID}.txt(if it exists), show its contents to the user, abort the skill.0→ proceed.
-
Stderr sanity (even on exit 0). Read
/tmp/codex-stderr-${REVIEW_ID}.txt.- If file missing → redirect itself failed; tell user
Could not create stderr file — check /tmp writability, abort. - If file contains a line matching
^Error:orFailed to write→ codex reported an infrastructure failure despite exit 0. Show stderr to user, route to launch-failure retry (max 1 per round; after retry failure → hard abort). - Otherwise → proceed.
- If file missing → redirect itself failed; tell user
-
Capture
CODEX_SESSION_IDfrom JSONL stdout. Read/tmp/codex-stdout-${REVIEW_ID}.jsonl. First line format:{"type":"thread.started","thread_id":"<uuid>","...":...}Parse the first line as JSON and extract
thread_id. Save asCODEX_SESSION_ID.- If the first line is not valid JSON or has no
thread_id→ treat as launch failure; show stderr, retry once, then abort.
- If the first line is not valid JSON or has no
-
Review file sanity. (Performed again in Step 5, but note upfront.)
/tmp/codex-review-${REVIEW_ID}.mdmust exist and contain a line matching^VERDICT: (APPROVED|REVISE)$. If not → Step 5 will handle it via retry/abort.
Where thread_id / session id is NOT:
- NOT in
/tmp/codex-review-${REVIEW_ID}.md(only contains the final agent text) - NOT in stderr file under
--json(empty on success; error text only on failure) - NOT in the middle or tail of stdout — only the first line of the JSONL file
Notes:
- Default model:
gpt-5.4withmodel_reasoning_effort=high. User can override via arguments. - Always
-s read-only— reviewer must not write files. - Do NOT run in background.
Step 5: Read the review, show it, then check the verdict
1. Read the review file. Read /tmp/codex-review-${REVIEW_ID}.md.
2. Semantic sanity checks. The file MUST pass all of these:
- Exists and is non-empty.
- Contains a line exactly matching
^VERDICT: (APPROVED|REVISE)$. - If verdict is
REVISE→ file must also contain at least one line matching\[severity:\s*(critical|high|medium)(i.e. at least one structured finding).
If any check fails → this is a launch failure (model produced no actionable review):
- Show the user the
/tmp/codex-stderr-${REVIEW_ID}.txtcontents (if any) AND the raw review file. - Offer ONE retry of Step 4 (re-launch the same round). Retry does NOT consume the round counter — the round counter advances only when a valid review is produced.
- Track the retry counter in your current round's reasoning only. The counter resets at the start of every new round.
- After a failed retry → hard abort the skill. Do NOT route to the Step 7 fresh-exec fallback (that path is for resume failures in rounds 2+, and depends on prior-round content).
3. Show the review to the user. This is mandatory and blocking.
Your VERY NEXT MESSAGE to the user must begin with the header below, followed by the file contents verbatim. Not "I've received the review", not "The reviewer said:", not a summary — the literal file content.
Do NOT wrap the review in a code fence (the review is already markdown, and an outer fence would break on inner fences).
Do NOT call any Edit, Write, or fix-applying tool in the same message as the review. The review output is a standalone user-visible message.
Message format:
## Adversarial Review — Round N (mode: <plan|code|code-vs-plan>, model: gpt-5.4)
<verbatim contents of /tmp/codex-review-${REVIEW_ID}.md>
4. Only AFTER the review message has been sent — parse the VERDICT line and dispatch:
VERDICT: APPROVED→ Step 8 (Done).VERDICT: REVISE→ Step 6 (Fixes).- Maximum rounds reached (5 rounds) → Step 8 with the max-rounds note.
Step 6: Apply fixes
Precondition gate (check first). Before calling any Edit, Write, or other fix-applying tool: confirm that you have already sent a user-visible message in THIS round whose body contains the verbatim review text. If you have not — STOP. Go back to Step 5 and send the review message now. This is the same rule that protects the "user sees the review" contract; a literal reader may otherwise slip past it.
Based on the reviewer's findings:
For plan review: fix the plan — address each finding. Update the plan file (or temp file). Show the user:
### Fixes (Round N)
- [What was changed and why, one item per finding]
For code review: fix the code directly — edit files, run tests if applicable. Show the user:
### Fixes (Round N)
- [What was fixed and why, one item per finding]
Skip a fix if it contradicts the user's explicit requirements — note this for the user.
Step 7: Resubmit to Codex (Rounds 2-5)
Resume is the primary path. Saves tokens and preserves session context. A fresh codex exec without resume is an emergency fallback — costly in tokens, and requires rebuilding prior-round context.
1. Write the resume prompt to /tmp/codex-resume-prompt-${REVIEW_ID}.md via Write tool. Use a separate file from the initial prompt so round-1 material remains available for diagnostics.
I've revised based on your feedback.
Here's what I changed:
[List of fixes]
Re-review with the same adversarial stance. Focus on:
1. Whether my fixes actually resolve the reported issues
2. Any NEW issues introduced by the fixes
End with VERDICT: APPROVED or VERDICT: REVISE
2. Run resume. Resume does NOT accept -C, so prefix the command with an explicit cd to ${REPO_ROOT} (captured at Step 2). Use single quotes around ${REPO_ROOT} — the path was validated at Step 2 to contain no single quotes.
cd '${REPO_ROOT}' && timeout 600 codex exec resume --json \
${CODEX_SESSION_ID} \
-o /tmp/codex-review-${REVIEW_ID}.md \
- < /tmp/codex-resume-prompt-${REVIEW_ID}.md \
> /tmp/codex-stdout-${REVIEW_ID}.jsonl \
2>/tmp/codex-stderr-${REVIEW_ID}.txt
Use timeout: 620000 in Bash tool parameters.
Note: Resume does NOT accept -s (sandbox — inherited from the original session; always read-only here) or -C (see above). It DOES accept --json, -o, -m, and -i.
3. Post-resume strict check order (do each before moving to the next):
-
Exit code.
124→ timeout. Tell the user and offer retry. Retry does not consume the round counter.≠ 0→ resume failed. Do NOT updateCODEX_SESSION_ID. Route to fallback.0→ proceed.
-
Stderr error check (exit 0 can hide
Error:orthread/resume failed). Read/tmp/codex-stderr-${REVIEW_ID}.txt:- If file is missing → redirect failed; tell user
/tmp not writable, abort. - If contains a line matching
thread/resume failedor^Error:→ route to fallback. Do NOT updateCODEX_SESSION_ID.
- If file is missing → redirect failed; tell user
-
Review file sanity. Read
/tmp/codex-review-${REVIEW_ID}.mdand apply the same checks as Step 5.2:- Missing / empty / no
^VERDICT: (APPROVED|REVISE)$line / REVISE without[severity:lines → route to fallback. Do NOT updateCODEX_SESSION_ID.
- Missing / empty / no
4. Only if all three checks pass → update CODEX_SESSION_ID from the first JSONL line of /tmp/codex-stdout-${REVIEW_ID}.jsonl. Each successful resume rotates the thread id; subsequent resumes MUST use the new id.
After updating CODEX_SESSION_ID, return to Step 5 with the new review.
Fallback chain — triggered when any of the three resume checks above fails.
--lastis deliberately NOT used.codex exec resume --lastpicks the newest session in the current cwd, which may be an unrelated codex invocation and cannot be distinguished from the intended one until after damage is done.
Severity classification — parse the previous round's review file (which is still in /tmp/codex-review-${REVIEW_ID}.md only if the resume overwrote the current-round result but not the previous-round; in general, rely on conversation history where prior rounds were shown verbatim per Step 5.3).
Parse case-insensitively for \[severity:\s*(critical|high|medium)\b and take the highest. If zero matches (reviewer format drift), default to critical to force re-verification in non-interactive mode.
Interactive mode (you received a direct user message earlier in this session, not a trigger/cron):
Ask the user:
Resume failed — the reviewer's re-review did not produce a usable result.
Last round's maximum severity: <level>.
Options:
(a) Run a fresh `codex exec` with full previous-rounds context (higher token cost, new session)
(b) Conclude the review — show current findings as NOT VERIFIED
- (a) → fresh-exec path below.
- (b) → Step 8 with the not-verified terminal state (same as maximum-reached, but with a different header).
Non-interactive mode (headless, scheduled run, no direct user message in this conversation):
- Max severity
criticalorhigh→ fresh exec automatically. The risk of silently skipping a serious finding outweighs the token cost. - Max severity
mediumonly → Step 8 with the not-verified terminal state.
Fresh-exec prompt template. The lead rebuilds prior-round context from the conversation (all prior rounds were shown verbatim in Step 5.3 user messages, so they are available in context):
[Original adversarial prompt for the current mode, from Step 4]
## Previous review rounds
### Round 1 findings (verbatim from earlier in this conversation):
<copy the round-1 review text that you already output as a user message>
### Round 1 fixes:
<copy the round-1 fixes list you output in Step 6>
### Round 2 findings (verbatim):
<...>
### Round 2 fixes:
<...>
## Current state of the artifact
[plan mode] Full current plan text: <insert>
[code mode] Run `git diff` from ${REPO_ROOT} to see the current changes.
Re-review. Focus on whether prior fixes resolved the reported issues and on any NEW issues introduced by the fixes.
End with VERDICT: APPROVED or VERDICT: REVISE.
Write this prompt to /tmp/codex-prompt-${REVIEW_ID}.md (overwriting the original is acceptable here; diagnostic files for the failed resume remain in /tmp/codex-stderr-* and /tmp/codex-stdout-*).
Launch using the same command template as Step 4 (with --json, -C, -o, stdin, stdout jsonl, stderr), apply the same post-launch strict check order, capture a fresh CODEX_SESSION_ID, then return to Step 5.
This fresh exec consumes one round from the 5-round counter — same as a successful resume would have.
Step 8: Final result
Approved:
## Adversarial Review — Summary (mode: <mode>, model: gpt-5.4)
**Status:** Approved after N round(s)
[Final review]
---
**Reviewed and approved by the reviewer. Awaiting your decision.**
Maximum rounds reached:
## Adversarial Review — Summary (mode: <mode>, model: gpt-5.4)
**Status:** Maximum reached (5 rounds) — not fully approved
**Remaining findings:**
[Unresolved issues]
---
**The reviewer still has findings. Please review them and decide how to proceed.**
Not verified (resume failed and the operator chose to conclude, or headless with only medium severity):
## Adversarial Review — Summary (mode: <mode>, model: gpt-5.4)
**Status:** NOT VERIFIED — fixes applied, reviewer did not re-verify
**Last round's findings:**
[Verbatim findings from the last successful round]
**Applied fixes:**
[List of fixes per finding]
---
**WARNING: This is NOT an approval. Fixes were applied but never verified by the reviewer. Manual review is required before merging.**
Step 9: Cleanup
Conditional on terminal state:
| Terminal state | Cleanup behavior |
|---|---|
| Approved | Remove all temp files |
| Maximum rounds reached | Remove all temp files |
| Not verified (fallback conclude) | Remove all temp files |
| Aborted (launch failure, redirect failure, infrastructure error) | LEAVE files in place for diagnostics |
In Claude Code Plan Mode: skip all cleanup (including deferred). rm will trigger a permission prompt. Files will be cleaned up on the next invocation outside Plan Mode.
Outside Plan Mode, on a cleanup-eligible terminal state:
rm -f /tmp/codex-plan-${REVIEW_ID}.md \
/tmp/codex-prompt-${REVIEW_ID}.md \
/tmp/codex-resume-prompt-${REVIEW_ID}.md \
/tmp/codex-review-${REVIEW_ID}.md \
/tmp/codex-stdout-${REVIEW_ID}.jsonl \
/tmp/codex-stderr-${REVIEW_ID}.txt
If the user declined rm — continue without error.
Do NOT delete plan files that existed before the review (only temp files created by this skill). On abort paths, old temp files remain for diagnostics and will be cleaned up by the OS on reboot, or overwritten by the next invocation using the same REVIEW_ID (collision probability is ~10⁻⁸ per same-second run).
Rules
- Claude actively fixes issues based on reviewer feedback — this is NOT just message forwarding.
- Reviewer findings are shown verbatim — do not rephrase or shorten. The Step 5 "YOUR NEXT MESSAGE" instruction is blocking: no edit/fix tool may be called until that message has been sent.
- Auto-detect review mode from context; user arguments take priority.
- With explicit
planargument or in Claude Code Plan Mode: skip git checks and base branch detection. REPO_ROOTis captured at Step 2 viagit rev-parse --show-topleveland substituted as an absolute literal path into every codex command. Never use$(pwd)inside codex commands — cwd drift between Bash calls makes it unreliable.- Resume requires
cd '${REPO_ROOT}' && ...becausecodex exec resumehas no-Cflag; cwd is inherited from the shell. The initial exec uses-C "${REPO_ROOT}"instead. CODEX_SESSION_IDis updated only on full success — ALL of (exit=0 AND stderr has noError:/thread/resume failedline AND review file contains a validVERDICT:line with findings on REVISE). On any failure, leave it unchanged and route to the fallback.- The
--jsonstdout stream is machine-readable JSONL only. The human review exists exclusively in/tmp/codex-review-*.md. Never treat Bash result as review content. - Launch-failure retry is capped at 1 per round and does NOT consume the 5-round counter. The retry counter is per-round; it resets at the start of every new round and is tracked only in that round's reasoning.
- Resume is the primary path for rounds 2-5. Fresh exec is a fallback that runs only when resume fails; it consumes one round from the counter just as a successful resume would.
--lastis never used — cwd filtering is insufficient to distinguish the current skill session from unrelated parallel codex invocations in the same repo.- Fallback after resume failure: interactive → ask the user (fresh exec vs conclude as not-verified); non-interactive → auto fresh exec if max severity is critical/high, auto conclude-as-not-verified if only medium.
- Cleanup is conditional on terminal state: remove temp files on approved/max-reached/not-verified; LEAVE them on abort (diagnostic value). Skip all cleanup in Plan Mode.
- Always read-only sandbox — reviewer never writes files.
- Maximum 5 rounds to protect against infinite loops.
- Show the user reviews and fixes for each round.
- If Codex CLI is not installed or crashed — tell the user:
npm install -g @openai/codex. - If a fix contradicts the user's explicit requirements — skip and explain why.