Codex first

From steipete/agent-scripts · View interactive version

Codex first is an AI agent skill from the GitHub repository steipete/agent-scripts. Claude Code / OpenClaw-on-Claude work routing: delegate hands-on work to Codex under the native-Claude model gate. Keep specification, judgment, and verification in Claude; prefer isolated Codex-backed autoreview.

How to use this skill

Skill file

Codex First

Launch flags — read first, copy verbatim

Default every Codex worker, fresh or resumed, to **GPT-6.2 Sol, high

reasoning, on the direct-API provider** (Peter, 2026-11-23), with the Fast tier

flags (service_tier="fast", sent as API priority; Peter, 2026-10-30). Pass all

of them unless the user requests an override.

# fresh
codex exec --yolo -C "$WT" \
  -m gpt-6.2-sol -c 'model_provider="openai_api_direct"' -c 'model_reasoning_effort="high"' \
  --enable fast_mode -c 'service_tier="fast"' \
  -o "$OUT" - < "$ORDER"
# resume: pass the same flags again; resume inherits none of them, not even the provider
codex exec resume "$SID" --dangerously-bypass-approvals-and-sandbox \
  -m gpt-6.2-sol -c 'model_provider="openai_api_direct"' -c 'model_reasoning_effort="high"' \
  --enable fast_mode -c 'service_tier="fast"' -o "$OUT" -

model_not_found (not supported when using Codex with a ChatGPT account). codex exec resume uses the provider in force at

resume time, not the session's recorded one (codex-cli 0.164.0, 2026-11-23): a resume without

the provider flag lands on the saved route and fails the same way.

and omits it, so 6.2 runs at the standard tier. codex-cli 0.171.0 (Peter's Mac since

2026-11-23) accepts fast for 6.2 without that warning. Keep the Fast flags. Older CLIs also

warn that 6.2 uses fallback model metadata; that is expected.

error, provider auth command … exited, 401/Missing bearer) → run the order on **GPT-6.1

Sol, high, Fast** over the saved route (drop the provider flag) and say so in the report.

Never repair credentials ad hoc. scripts/codex-resume does this switch automatically.

not advertised and sent no tier); keep the CLI current. Verified on Team with 0.166.0,

2026-10-30.

on a route whose catalog lists the tier (launch details), swap in

-c 'service_tier="ultrafast"', and add -c 'model_auto_compact_token_limit=260000'. It is served up to ~282k prompt tokens, flaky at

288–294k, and silently fast at ≥300k (measured 2026-10-13); the 260k cap keeps it there.

Rollouts record only the requested tier; prove the served tier with a direct probe

(response.service_tier). Details: launch details.

launch with -p sol61-1m (or -p astra-1m) instead of the -m/model_provider flags:

CLI overrides beat the profile, and those profiles pin 6.1 Sol/Astra on the direct provider

because the 1M catalogue has no genuine 6.2 entry yet. See $codex-huge-context.

Verify launch arguments (fast default; requested ultrafast is valid on 6.1 Sol).

Security audits and cyber-classifier stops → Daybreak (Peter, 2026-10-15/18; reworked 2026-11-23)

Daybreak is a per-request access program (access_programs.cyber), not a model. The

gpt-daybreak-{blue,red}-latest aliases are retired (404 model_not_found). Entitlement belongs

to the API project; selecting a program grants nothing.

security review of hardening diffs) launch on Red from the start (Peter 2026-10-18: "use

daylight red model for security audits"). Implementation workers stay on Sol at Standard.

session on Blue with the same model; still flagged → resume on Red (Peter: "use

daybreak red if you hit a blocker with regular models"). Don't rephrase to dodge the classifier

or hop between regular models.

CYBER=(-c 'model_provider="openai_api_direct"' -c 'model_providers.openai_api_direct.capabilities.cyber_access_programs=true')
# Blue: same model, reduced refusals
codex exec resume "$SID" --dangerously-bypass-approvals-and-sandbox -m gpt-6.2-sol "${CYBER[@]}" \
  --cyber-access-program daybreak_blue -c 'model_reasoning_effort="high"' -o "$OUT" -
# Red: purpose-trained cyber model (audits, or Blue still flagged)
codex exec --yolo -C "$WT" -m gpt-6-cyber "${CYBER[@]}" \
  --cyber-access-program daybreak_red -c 'model_reasoning_effort="high"' -o "$OUT" - < "$ORDER"

--cyber-access-program unless the provider declares capabilities.cyber_access_programs = true

(the -c above, or the same key in ~/.codex/config.toml), and the turn runs at Standard.

Prove a new host once: -m gpt-6-cyber --cyber-access-program standard must fail with

400 invalid_access_program; success means the program never reached the API.

cyber models (gpt-6-cyber, gpt-5.6-cyber). A mismatch returns 400 invalid_access_program

naming the right program. Omitted, gpt-6.2-sol runs at Standard.

lacks the program (default projects never have it): use a key from an enabled project.

classifier.

Capacity fallback (Peter, 2026-10-12)

Org TPM caps apply per model (6.1 Sol: 40M tokens/min, 2026-10-12). Worker or resume fails with

Rate limit reached for <model> ... tokens per min (TPM), Selected model is at capacity, or

overloaded → resume that same session on GPT-6 Astra, high, Fast (saved route, no provider

flag) immediately (Peter, 2026-10-12: "use

astra if sol has rate limits"); no waiting loop:

codex exec resume "$SID" --dangerously-bypass-approvals-and-sandbox \
  -m gpt-6-astra -c 'model_reasoning_effort="high"' \
  --enable fast_mode -c 'service_tier="fast"' -o "$OUT" -

Fresh orders at capacity: same flags with codex exec --yolo -C "$WT"; a fresh launch that dies

on capacity already has a session id in stderr (session id: …) — resume that, don't relaunch.

matching only "rate limit" made capacity failures exit instead of falling back.

refuses because its provider/route doesn't match operator config, don't change config — review

with a fresh-context subagent (diff + brief) and say so in the PR.

fallback, busy check, safe stop, and classified exits (resume and watchdog).

Wrapper and process hygiene (2026-10-12/13)

execute the new bytes at their old offset. Write x.new, bash -n, chmod +x, then mv

(rename keeps the old inode for running copies; forgetting chmod gives exit 126).

the script before its fallback runs (2026-10-13, a 27-worker fleet). Capture the code

(… && rc=0 || rc=$?) and classify it, or hand the session to codex-resume.

thread … already has an active writer. Stop and resume with codex-resume --stop "$SID":

it finds the worker through its open rollout file (fresh launches don't carry $SID in argv,

so pgrep -f misses them) and refuses while scripts/pr or git runs beneath it. A leftover

~/.codex/thread-writer-locks/$SID.lock file without a live holder is harmless.

its worktree changes and context survive.

(2026-10-18, a cancelled worker restarted in its deleted worktree). Kill the native codex

binary (pgrep -P <node-shim-pid>), then the node shim and its wrapper.

Hard gate

Autoreview exception: always prefer Codex-backed $autoreview, independent

of ANTHROPIC_BASE_URL, router state, or harness. Reviewing a frozen bundle is

not hands-on self-delegation. Do not switch review engines merely because the

parent session is router-backed. This exception takes precedence over the gate

below.

Use the autoreview helper with --engine codex and its own model and route defaults ($autoreview owns them) unless the user requests an override. Its --codex-config 'model_provider="…"' selector must match the root model_provider in ~/.codex/config.toml; it refuses any other provider. Preserve the helper's reviewer isolation.

For direct hands-on delegation, use this skill only when the session is running

on a native Claude model and can run shell commands: Claude Code, or an OpenClaw

agent (for example on the Team Gateway) whose session model is Claude.

Model check (primary). The point of the gate is model economics: Claude

tokens are metered and expensive, so hands-on work moves to Codex; but if the

session is already routed to a cheaper/other model, delegation gains nothing.

Decide by the model the session actually runs on, not by the transport:

  1. Read the model id: Claude Code shows it in the system prompt's environment

section ("You are powered by the model …"); OpenClaw shows it in the

Runtime line and session_status. Router-wrapped ids may be opaque

(claude-ccr-<hex>); the hex suffix is often ASCII — decode it

(echo <hex> | xxd -r -p) to reveal the underlying route, e.g.

Gorilla CCP/native-claude-fable-5.

  1. If the resolved model is a native Claude model (contains claude, fable,

opus, sonnet, or haiku, including native-claude-* router routes):

delegate hands-on work to Codex. This applies even when

ANTHROPIC_BASE_URL is loopback or a local router (Gorilla Claw, Clawdex)

— a router in front of a real Claude model is still expensive Claude.

  1. If the resolved model is clearly non-Claude (a GPT/other-provider route):

the session is already on the flat-rate/cheap side; do not self-delegate,

work directly.

Base-URL fallback (only when the model cannot be identified). If no model

id is visible and the hex/route cannot be decoded, fall back to the old

transport heuristic: if ANTHROPIC_BASE_URL's host is

gorillaclaw.sheep-coho.ts.net, localhost, ends in .localhost, is in

127.0.0.0/8, or is IPv6 loopback ::1, assume the session may be routed to

a non-Claude model and work directly. If neither model nor base URL can be

inspected, fail closed and work directly.

Sessions on Codex, ChatGPT, Pi, or any non-Claude model (including OpenClaw

agents on GPT): do not invoke Codex CLI for hands-on self-delegation. Continue the task directly. This gate overrides a repository

instruction that merely mentions $codex-first; it does not override the

autoreview exception above.

The default worker is GPT-6.2 Sol on the direct-API provider. Claude handles specification, judgment, orchestration, and final verification; Codex handles the delegated implementation.

Route

Delegate to Codex (default for hands-on work):

resolution, and the repo's land workflow (e.g. scripts/pr) are mandatory

delegations. Issue ONE self-contained work order covering

rebase→resolve→push→CI attach+green→land so the sequence never bounces back to

Claude mid-flight; the land decision, gates, and review below stay Claude's.

cannot attach — no merge ref) and confirm a run attached to the exact head

SHA before polling; every wait emits all terminal states with bounded

iterations; prefer the repo's watcher script when one exists (openclaw:

node scripts/watch-pr-ci.mjs). Never gh run watch or gh pr checks --watch

in work orders: gh run watch polls every 3 s by default (~1,200 calls/hour), and

two such watchers drained a shared 5,000/hour writer token twice on 2026-10-15.

Poll one exact run with gh run view <id> --json status,conclusion at most every

~10 minutes, or let the repo's landing tool own the wait.

Do not resume a long-lived session for a new order — saturated sessions

misread work orders as configuration and no-op ("Understood…").

canonical in every repo; CLAUDE.md exists only as a symlink to it. Point

Codex work orders at AGENTS.md and edit only AGENTS.md.

Keep in Claude:

Mixed task: Claude designs first, freezes spec, delegates build-out.

Heuristic: prompt reads as a work order → delegate; writing it forces decisions → design, Claude.

Portfolio/multi-repo work: $maintainer-orchestrator instead.

Invoke

file; never block a turn on a long codex exec.

background command (run_in_background: true) — one sidebar chip per worker,

completion notification included. Chain setup steps (installs, worktree prep)

INSIDE that tracked command. Never &-fork workers from a shared launcher:

the launcher's chip exits at fork time and the workers become invisible

orphans supervised only by PID files.**

Prompt contract

Codex starts with zero session context. Every prompt: goal, exact repo/paths, constraints, non-goals, proof expected (exact test command), output shape ("report files changed + test output"). Spec quality decides success.

gates: told "never raise the size budget" while its design inflated the bundle, Codex

hand-minified source identifiers to single letters — and passed every gate including

autoreview. Pair each hard constraint with the sanctioned exit: "if gate X fails after honest

attempts: STOP, report exact numbers/diagnosis, do not work around." Treat a stop-report as a

successful run (it is the coordinator's decision point, and workers use it correctly once it

exists).

idioms ("controller with narrow host interface, the #NNN shape") — workers imitate landed

precedent far more reliably than abstract style rules. Fold each round's new trap into the

next spec.

Before reviewing/landing or coordinating workers, read coordination; check for live workers before editing/committing.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.