---
name: consult-codex
description: Spawn a second-opinion agent (Codex) with fresh context to review local changes before committing, evaluate feature specs before implementation, or get an independent view when stuck. Invoke when the user says /consult-codex or asks to "get a second opinion", "ask Codex", or "consult Codex" on current changes, a spec file, or an implementation question.
---

# Consult Codex

Spin up a fresh sub-agent with no prior conversation context so it can review the work independently and surface issues the primary agent may have missed.

## When to use

- **Before committing** — after local changes look complete but before `git commit`; catch correctness, security, and standards issues from a fresh perspective.
- **Before implementing a spec** — after a feature spec has been written or read; check for gaps, ambiguities, contradictions, and missing done-criteria.
- **When stuck** — when debugging has gone in circles; a second agent re-reads the relevant code cold and may spot the root cause faster.

## Workflow

1. Determine the review target:
   - If the user says "before committing" or provides no target: the target is local changes (`git diff HEAD` + untracked files).
   - If the user names a spec or doc file: the target is that file plus any referenced source files.
   - If the user describes a problem or question: the target is the question plus relevant source files identified from context.

2. Collect the necessary context compactly:
   - For local-change reviews: run `git diff HEAD --stat` and `git diff HEAD` to get the full patch.
   - For spec reviews: read the spec file in full; also read the main source files the spec describes (e.g., `src/lib/ai-gateway.ts`, `src/db/schema/tenants.ts`).
   - For stuck-debugging: read the file(s) containing the bug, the relevant test, and the last error message.

3. Spawn the Codex agent using `Agent` with `subagent_type: "general-purpose"`. Write a self-contained prompt that includes:
   - The full diff or file contents (do not say "see the attached diff" — paste it inline so Codex starts cold with everything it needs).
   - A clear review mandate (correctness, security, spec completeness, or debugging hypothesis).
   - The project rules that apply: `.claude/claude.md` key rules (type-check + tests must pass, Conventional Commits, no curly quotes in schemas, American English, no unnecessary abstractions).
   - The output format expected (see below).

4. Wait for the Codex agent to return, then relay its findings to the user verbatim or lightly reformatted. Do not filter or soften findings.

## Prompt template for Codex

```
You are a second-opinion code reviewer for a Next.js 16 / React 19 / Drizzle ORM / Inngest project.
You have no prior context from any ongoing conversation.

## Project rules (abridged)
- After any logic change, `pnpm type-check && pnpm test` must pass.
- Conventional Commits: feat: fix: docs: refactor: test: chore:
- Curly apostrophes in Drizzle schema strings break esbuild — use straight quotes only.
- American English throughout (organization, behavior, color, canceled, customize, analyze).
- No abstractions beyond what the task requires. No unnecessary comments. No half-finished implementations.
- Do not add error handling for scenarios that can't happen. Trust framework guarantees.

## Review target
<PASTE TARGET HERE>

## Your task
<ONE OF:
  "Review these local changes before commit. Check for correctness, security/auth/RBAC, missing tests, standards violations, and operational risk. Do not fix anything."
  "Review this feature spec before implementation starts. Check for gaps, ambiguities, missing done-criteria, contradictions, and whether the phasing is coherent."
  "Debug this problem: <describe problem>. Read the code cold and propose hypotheses for the root cause."
>

## Output format
Findings — ordered by severity (High / Medium / Low).
Open Questions — things that need the author's input.
Tests/Verification — what to run or check.
If nothing is wrong, say so clearly and note any residual risk.
```

## Output to the user

Relay Codex's findings directly. If Codex raises a High finding, flag it clearly before summarizing the rest. If Codex says everything looks good, report that and note any caveats it mentioned.

Do not editorialize or second-guess Codex's findings without saying so explicitly.
