agentsclimarketplace

Codex secondary review

Skill maee-co/cc-autoship/skills/codex-secondary-review

Opt-in second review after Claude's /review. Sends the PR diff to Codex to cover external API contracts, least privilege, unhandled promises, and refactor consistency. Runs from a hook or on demand.From its SKILL.md

Install
npx -y skills add maee-co/cc-autoship --skill codex-secondary-review

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

23.2 KB, as published. Nobody here has run it

/codex-secondary-review

As a complement to Claude's primary review (/review), have Codex review the same PR and post the result as a PR comment with a marker.

Design principles

  • Claude is authoritative: Codex findings are not counted in the Critical/Major tally used by /auto-merge. Codex is reference information
  • Opt-in launch: only PRs meeting the criteria launch it automatically (via a hook). It can also be called by hand
  • No double posting: the <!-- codex-secondary-review:PR#{n} --> marker at the top of the comment prevents a repeat post
  • Fail quietly: an unauthenticated Codex CLI or an API error never drags the /auto-merge flow down with it
  • Observability of silent failures: the availability check (step 3.5) can pass and the runtime (task) still fail. Step 4.5 classifies the return value and prints the reason locally, and step 4.7 adds runtime diagnostics (never posted to the PR — "fail quietly" is preserved, and only the material for diagnosis is left behind)
  • Do not pin the model: normally use the default model from the user's ~/.codex/config.toml (that is, their best model). Only when the failure is model-related does step 4.6 drop to a fallback model, once. A permanent pin would cap review quality even after the CLI has caught up

See the "Codex secondary review" section of rules/dev-flow.md for details.

Usage

# Give the PR number explicitly
/codex-secondary-review 283

# Infer it from the current branch
/codex-secondary-review

Arguments

ArgumentDescriptionDefault
<PR number>The target PR numberInferred from the current branch

Launch criteria (already evaluated by the hook)

By the time this skill is invoked, the evaluation in scripts/claude-hooks/src/codex-trigger-criteria.ts has found at least one of:

  1. The PR diff changes a file matching an external-API keyword: discord / slack / notion / openai / anthropic / webhook / mcp
  2. The PR is ≥ 500 lines or ≥ 10 files
  3. The PR body carries the [codex-review] tag (explicit opt-in)
  4. It is a security fix: the PR title or body contains a security-intent keyword. The list matches both English and Japanese (vulnerabilit / security / sanitiz / privilege escalation / command injection / SQL injection and their Japanese equivalents), plus the acronyms XSS / CSRF / SSRF / RCE / RLS / OWASP / SQLi / CVE-XXXX

Opt-out: the [no-codex] tag in the PR body suppresses it at the hook (this takes priority over criterion 4).

Procedure

Step 1: Resolve the PR number

Take the PR number from the argument. If not given, infer it from the current branch:

PR_NUM="$1"
if [ -z "$PR_NUM" ]; then
  PR_NUM=$(gh pr view --json number -q .number 2>/dev/null)
fi
if [ -z "$PR_NUM" ]; then
  echo "No PR is linked to the current branch. Specify a PR number"
  exit 1
fi

Step 2: Check for a duplicate post

Do not post again if the marker already exists in the comments:

EXISTING=$(gh pr view "$PR_NUM" --json comments \
  --jq ".comments[].body" \
  | grep -c "<!-- codex-secondary-review:PR#${PR_NUM} -->" || true)

if [ "${EXISTING:-0}" -gt 0 ]; then
  echo "A Codex secondary review has already been posted on PR #${PR_NUM}. Skipping"
  exit 0
fi

Step 3: Fetch the PR metadata

Get the title, branch, and size (used to build the prompt):

PR_META=$(gh pr view "$PR_NUM" --json title,headRefName,additions,deletions,changedFiles,body)
PR_TITLE=$(printf '%s' "$PR_META" | jq -r '.title')
PR_BRANCH=$(printf '%s' "$PR_META" | jq -r '.headRefName')
PR_ADDS=$(printf '%s' "$PR_META" | jq -r '.additions')
PR_DELS=$(printf '%s' "$PR_META" | jq -r '.deletions')
PR_FILES=$(printf '%s' "$PR_META" | jq -r '.changedFiles')

Step 3.5: Check Codex availability up front (skip quietly without spawning, {ISSUE-ID})

In an environment without the codex:codex-rescue agent (no Codex installed — the vast majority of public users), attempting an Agent spawn flashes "Agent type 'codex:codex-rescue' not found" before falling through to a graceful skip. Decide availability before the spawn, without any network call and deterministically, so no error is ever shown:

The check is factored into pure functions in lib/codex-availability.sh (tests: __tests__/test-codex-availability.sh):

# Do not emit a source-failure line even when CLAUDE_PLUGIN_ROOT is unset (drop-in use),
# which would defeat the purpose of this skill
CSR_LIB="${CLAUDE_PLUGIN_ROOT:-.claude}/skills/codex-secondary-review/lib/codex-availability.sh"
CODEX_AVAILABLE=0
if [ -f "$CSR_LIB" ] && . "$CSR_LIB" 2>/dev/null && csr_codex_available_default; then
  CODEX_AVAILABLE=1
fi
echo "CODEX_AVAILABLE=${CODEX_AVAILABLE}"
  • If CODEX_AVAILABLE=0, do not make the step 4 Agent call. Report one line — "Codex is not available in this environment, so the secondary review was skipped" — and finish (no comment posted, auto-merge not blocked: the same outcome as the existing "fail quietly", without the error display)
  • The check is the AND of three conditions (all non-network and deterministic):
    1. The CLI exists (command -v codex)
    2. The plugin is enabled in enabledPlugins (added in {ISSUE-ID}) — take the first explicit value in the order .claude/settings.local.json → .claude/settings.json → ~/.claude/settings.json, and treat absence everywhere as disabled. The search scope is worktree → main repository → user, in that order ({ISSUE-ID}, below)
    3. The agent definition file exists (either the plugin cache's agents/codex-rescue.md or one directly in the project)
  • If the check wrongly reports available (the definition file exists but was not loaded into the session, for instance), it falls back to the old behaviour: the step 4 spawn fails and the skill fails quietly (a two-layer safety net)
  • This check answers "can it launch", not "does it actually work once launched". Diagnosing a silent runtime failure (exit 1, empty output) after the check has passed is the job of the runtime diagnostics in step 4.5 ({ISSUE-ID}: availability check = before, diagnostics = after)
  • An indeterminate result (no jq, corrupted settings JSON) falls to unavailable — a secondary review is supplementary and skipping it never blocks /auto-merge, so avoiding a spurious error display matters more than avoiding a missed run

Why condition 2 is needed: with only conditions 1 and 3, the state "the plugin cache is still there but the plugin is not enabled" (installed ≠ enabled) is misread as available. Agent type 'codex:codex-rescue' not found recurred in practice because of it. Do not read "absent" as "enabled by default" — measurements show a plugin with no entry in enabledPlugins is not loaded.

Why the worktree scope is needed: the .claude/settings.local.json that records the enablement is gitignored and therefore does not exist in a worktree. Since dev-flow requires implementation to happen in a worktree, looking only at the worktree makes condition 2 always resolve to "no explicit value → disabled", and the secondary review is silently skipped on nearly every real PR (the hook fires correctly and the skill bows out on its own). csr_repo_root reads the worktree's .git file (gitdir: <main>/.git/worktrees/<name>) to resolve the main repository root and includes its .claude/settings.local.json in the search order. This is not "inherit only the true direction" — an explicit false in the main repo disables it in the worktree too (an explicit value in the worktree itself wins). It does not depend on the git binary (pure file I/O, keeping this check non-network and deterministic).

Step 4: Ask Codex for the secondary review

This step runs by Claude calling the Agent tool (it is not executed automatically from bash). Pass codex:codex-rescue as subagent_type along with a prompt of the structure below.

Agent call parameters:

  • description: Codex secondary review PR #${PR_NUM}
  • subagent_type: "codex:codex-rescue"
  • prompt: the template below with the variables from step 3 substituted in

Prompt template (substitute the real values obtained in step 3):

Please perform a secondary review of GitHub PR #${PR_NUM} (${PR_TITLE}, branch: ${PR_BRANCH}, ${PR_ADDS} additions / ${PR_DELS} deletions / ${PR_FILES} files).

Repository: (the current repository)
Fetching the PR: `gh pr view ${PR_NUM} --json title,body,files` and `gh pr diff ${PR_NUM}`.

This is a secondary review that complements Claude's /review. **Concentrate on the following, which Claude tends to miss**:
1. Shaping input to external API contracts (length limits, URL validation, schemas)
2. Web API lifecycles (user activation, transient state, session expiry)
3. Least privilege and permission scope (especially Chrome extensions / OAuth / webhooks)
4. Uncaught exceptions in Promises and async code, missing try-catch
5. Consistency after a refactor (allowed-tools, referencing tests, documentation left behind)

Also cover the six checklist categories of rules/code-review.md (type safety / security / test coverage / performance / code quality / dependencies & scope).

Output format:
- Classify each item as Critical / Major / Minor / Nit, with file_path:line_number, the basis, and a recommended fix
- Overall impression (the merge decision is left to Claude's primary review, so this is optional)

${REPLY_LANG_LINE}

Fill ${REPLY_LANG_LINE} according to the language of the current session (English session → Respond in English. / Japanese session → 日本語で返答。). Codex does not inherit the caller's language setting, so without stating it in the prompt, the secondary review body alone comes back in the wrong language. The classification words Critical / Major / Minor / Nit are fixed regardless of language (see "Language-invariant tokens" in docs/rules/output-language.md).

The Agent tool's return value (Codex's review text) is used to format the comment in step 5.

Step 4.5: Classify the response (surfacing silent failures, {ISSUE-ID})

Do not treat the step 4 return value as review text directly — classify it first. By design, codex:codex-rescue returns stdout as is, so when the runtime returns a 400, the error JSON arrives in the return value (or it comes back empty). Going straight to step 5 without classifying means either posting an error body to the PR as a review, or swallowing it silently.

CSR_OUTCOME="${CLAUDE_PLUGIN_ROOT:-.claude}/skills/codex-secondary-review/lib/codex-outcome.sh"
# Put the Agent return value in CODEX_OUTPUT, then classify
CLASS=$(. "$CSR_OUTCOME" 2>/dev/null && csr_classify_agent_output "$CODEX_OUTPUT")
echo "CODEX_CLASS=${CLASS}"
ClassMeaningNext action
okIt holds up as review textGo to step 5 (post)
model-unsupportedThe runtime cannot handle the configured model (400)Go to the fallback retry in step 4.6
emptyNo review text was obtained — an empty response, or the agent reporting in prose that it could not launchGo to the fallback retry in step 4.6
errorA runtime error unrelated to the model surfaced explicitlyStep 4.7 (diagnostics) → finish without posting
  • The classification lives in pure functions in lib/codex-outcome.sh (tests: __tests__/test-codex-outcome.sh). To avoid misclassifying a review that merely quotes an error string as a failure, it first checks whether the text holds up as a review, and only then matches failure markers anchored at the start of a line
  • The classifier is a guard against known failure shapes, not a validator of review quality. ok means only "does not match a known failure shape", so the final call on whether the return value makes sense as a review is still Claude's (treat an obviously irrelevant or contentless response like empty: send it to step 4.7 and do not post)
  • On error / empty, print the one line from csr_agent_error_message locally (never post it to the PR). Without it, the investigation ends at "Codex quietly returned nothing"
  • empty does not mean only "the empty string" (learned from one real run in {ISSUE-ID}). The spec of codex:codex-rescue is "return nothing if you could not launch", but in practice it reports the failure in prose, e.g. Codex could not be invoked (the companion script returned status 1 with empty output ...). That shape contains neither the 400 JSON nor a marker, so a naive check turns it into ok and the failure report gets posted to the PR as the review. _csr_is_agent_failure_report detects it by requiring both a mention of codex and a failure phrase, and falls to empty

Step 4.6: If it is model-related, retry once with the fallback model

model-unsupported appears when the codex CLI the plugin launches cannot yet handle the model pin in the user's ~/.codex/config.toml. Measured 2026-07-25:

{"type":"error","status":400,"error":{"type":"invalid_request_error",
 "message":"The 'gpt-5.6-terra' model requires a newer version of Codex.
 Please upgrade to the latest app or CLI and try again."}}

Include empty in the retry cases too. Because codex:codex-rescue discards the runtime's stderr, the 400 above can be swallowed so that only an empty response or a failure report comes back (confirmed in a real run). The skill cannot tell from the outside whether it was model-related, and precisely because it cannot tell, trying the fallback once is the only recovery path. Do not retry on error (a non-model runtime error surfaced explicitly) — changing the model will not fix it.

When it applies, redo step 4 exactly once with the fallback model stated explicitly:

# APPLIED_MODEL is empty on the first attempt; after a fallback it holds the fallback model name
. "$CSR_OUTCOME" 2>/dev/null || true
if csr_should_retry_with_fallback "$CLASS" "${APPLIED_MODEL:-}"; then
  FALLBACK=$(csr_fallback_model)                          # default gpt-5.5
  REJECTED=$(csr_rejected_model "$CODEX_OUTPUT")
  echo "codex model '${REJECTED}' is unsupported by the runtime; retrying with '${FALLBACK}'"
else
  echo "Not retrying (class=${CLASS} / model already applied=${APPLIED_MODEL:-none})"
fi

On the retry, put --model ${FALLBACK} on its own line at the very top of the step 4 prompt. codex-rescue specifies "if given a concrete model name, pass it via --model; those are routing flags and must not be included in the task body", so that single line becomes the runtime's --model directly.

  • At most one retry (csr_should_retry_with_fallback blocks further attempts with the applied flag, preventing an infinite loop)
  • If the retry also fails, go to step 4.7 (diagnostics) and finish without posting
  • Why not to pin the model permanently: a pin keeps you on the old model even after the CLI catches up to newer ones, capping review quality. The fallback only drops down when something fails, so it stops firing on its own once the CLI catches up
  • The fallback target can be overridden with the CODEX_REVIEW_FALLBACK_MODEL environment variable

Step 4.7: Runtime diagnostics (liveness, {ISSUE-ID})

When the class is error or empty, or the step 4.6 retry also failed, print the runtime diagnostics locally to leave material for diagnosis (never posted to the PR — "fail quietly" is preserved):

CSR_DIAG="${CLAUDE_PLUGIN_ROOT:-.claude}/skills/codex-secondary-review/lib/codex-diagnostics.sh"
if [ -f "$CSR_DIAG" ] && . "$CSR_DIAG" 2>/dev/null; then
  echo "codex-secondary-review runtime diagnostics:"
  csr_runtime_diagnostics_default
fi

Diagnostics alone left a gap (the lesson of {ISSUE-ID}): the diagnostics only go as far as liveness, so a model-unsupported 400 — where codex --version responds perfectly well — is impossible to catch in principle (measured: version_exit=0, auth present, plugin_cache present, all green, and it still failed). The classification in step 4.5 was added to fill that layer. Diagnostics (is the environment alive) and classification (what did it return) are different layers; never skip either.

How to read the six keys the diagnostics print:

KeyWhat to look at
codex_binThe resolved real path of codex. Is it holding an unexpected codex, such as a cmux shim (/var/folders/.../cmux-cli-shims/<uuid>/codex)? (foothold 2 of this issue)
version / version_exitThe liveness of codex --version. A non-zero exit or empty output means the binary itself is unhealthy (the PATH resolves to something broken)
version_stderrThe first line of stderr on a non-zero exit. A hint about shim or runtime launch failures
auth_jsonOnly whether ~/.codex/auth.json exists (its contents are never read). missing strongly suggests unauthenticated → !codex login
plugin_cacheWhether the plugin cache exists. missing means the plugin is not installed
  • The diagnostics stop at liveness (codex --version: no network, no billing). A full reproduction that actually runs task (codex exec and the like: billed API calls, network round trips) is kept as a manual deep-dive procedure for when the diagnostics give no lead (never taken automatically)
  • Printing diagnostics does not block /auto-merge (the secondary review is reference information). The purpose of this step is to leave "why did it fail" in the log
  • If the version value disagrees with a report from another path (e.g. codex.detail in the companion's setup --json), that is a strong signal that PATH resolves a different codex (measured: 0.144.5 on the skill side versus 0.135.0 on the companion side)

Step 5: Post the Codex output as a PR comment

Take Codex's output and format it with the marker.

Output language: the heading and the surrounding boilerplate (the explanation after the heading, the <sub> notes) are written in the language of the session (the sample below is English). docs/rules/output-language.md is the SSoT for the fixed label translations.

Always emit regardless of language (never translate or omit): the duplicate-post marker <!-- codex-secondary-review:PR#<N> --> on the first line. The duplicate check in step 2 looks only at this marker, so translating or omitting it causes the same review to be posted twice.

<!-- codex-secondary-review:PR#${PR_NUM} -->
## 🤖 Codex secondary review

As a complement to Claude's `/review`, a secondary review was run with Codex. Codex tends to catch what Claude misses around external API contracts, least privilege, uncaught Promises, and refactor consistency.

{Codex's output verbatim}

---

<sub>
- Claude's `/review` is authoritative — Codex findings are **not** counted in the Critical/Major tally used by `/auto-merge`
- Launch criteria: a change matching an external API keyword / a large PR (≥500 lines or ≥10 files) / the `[codex-review]` tag
- Suppression: put `[no-codex]` on its own line in the PR body
</sub>

If the result came from the step 4.6 fallback retry, add this line just above the <sub> block:

> ℹ️ The runtime could not handle the configured model `{REJECTED}`, so the review ran with the fallback model `{FALLBACK}`.

Post it:

gh pr comment "$PR_NUM" --body "$BODY"

Step 6: Report

Report to the maintainer:

  • The PR number and where it was posted
  • Codex's Critical / Major counts (for reference)
  • If it was skipped (an existing marker and the like), say so

Key rules

  • Suppress double posting: the marker check in step 2 is mandatory. Do not regenerate the Codex output every time
  • No effect on /auto-merge: the comment's Markdown heading is the Codex secondary-review heading, which by design does not match the auto-merge-after-review hook's detection patterns (レビュー結果 / レビュー指摘修正結果 / 一次レビュー, plus the <!-- review-verdict: --> marker). It never triggers itself recursively
  • The marker string: follow the <!-- codex-secondary-review:PR#{n} --> form exactly. The hook uses the same marker to exclude its own post
  • Strip personal information: if the Codex output should ever contain a token or API key, replace it with [REDACTED] before posting
  • Never post without classifying: if the step 4.5 class is anything but ok, do not post to the PR. This prevents the accident of posting error JSON as a review
  • Never let a failure end in silence: on error, on empty, or on a failed fallback retry, always print locally the one line from csr_agent_error_message and the step 4.7 diagnostics (never to the PR). "Fail quietly" is a contract toward the PR and the merge flow, not silence toward the operator

Edge cases

CaseResponse
No PR number given and no PR on the current branchExit with an error, prompt for <PR number>
A comment with the marker already existsSkip (do not post again)
Codex not installed (no CLI / no agent definition)The up-front check in step 3.5 skips quietly without spawning (zero error display, {ISSUE-ID})
Codex installed but not enabled (absent from enabledPlugins, or false)Same as above (added in {ISSUE-ID}: a disabled plugin with a leftover cache is not misread as available)
Run in a worktree (no .claude/settings.local.json)csr_repo_root resolves the main repository root and looks at its settings.local.json too. Previously this always resolved to unavailable and skipped silently
Codex CLI unauthenticated / fails to launchFail quietly (no PR comment, exit 0). No effect on the /auto-merge flow
Silent runtime failure after the availability check passed (exit 1 with empty output, or the agent reporting failure in prose)Step 4.5 classifies it as empty → step 4.6 retries with the fallback → if it still fails, step 4.7 prints runtime diagnostics locally (codex_bin real path / version liveness / auth existence / cache). Nothing is posted to the PR, auto-merge is not blocked, and the diagnostic material remains
The runtime cannot handle the configured model (400 The '<model>' model requires a newer version of Codex)Step 4.5 classifies it as model-unsupported → step 4.6 retries exactly once with the fallback model (default gpt-5.5)
The fallback retry also failsPrint the step 4.7 diagnostics plus the one-line error locally and exit 0. Nothing posted, auto-merge not blocked
Codex output empty or malformedClassify in step 4.5, print the step 4.7 diagnostics, exit 0, post no comment
A non-PR-number string in the argumentsReject with a numeric check and exit with an error

Callers in the chain

  • scripts/claude-hooks/dist/post-tool-use-codex-secondary-review.mjs: called automatically after Claude's /review completes (on the review-verdict-post.mjs run, the canonical path, or when a review-result comment is detected from gh pr comment) for PRs meeting the launch criteria
  • Manually: the maintainer or Claude can run /codex-secondary-review <PR#> at any time

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.