codex-first

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Codex First

优先使用Codex

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.
Private runtime override: invoke
$codex-next
before evaluating this gate when that skill is available. On Peter-managed Macs it may replace the generic model-family gate for both coding and exploratory/subagent work. Follow its resolved current-model decision; do not continue through the generic gate after it has selected an execution surface.
For direct hands-on delegation without a private override, use this skill only when the active agent is Claude Code and the session is running on a native Claude model.
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 from the system prompt's environment section ("You are powered by the model …"). 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
    .
  2. 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.
  3. 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.
Codex, ChatGPT, Pi, and every other harness: 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.
Rationale: Claude (Fable/Opus) tokens metered + expensive; Codex flat-rate. GPT-5.5+ is usually the better and faster model at writing/implementing code; Claude wins at ergonomics — judgment, design, spec-writing, review, orchestration. So Codex types, Claude thinks and verifies.
自动审核例外规则: 无论
ANTHROPIC_BASE_URL
、路由状态或工具环境如何,始终优先采用Codex支持的
$autoreview
。审核冻结的代码包不属于手动自委托范畴。不要仅因为父会话是路由托管的就切换审核引擎。此例外规则优先级高于下方的网关规则。
私有运行时覆盖:
$codex-next
技能可用时,在评估本网关前先调用它。在Peter管理的Mac设备上,它可能会替代通用模型系列网关,适用于编码和探索性/子Agent工作。遵循其解析后的当前模型决策;一旦它选定了执行载体,请勿继续使用通用网关。
对于无私有覆盖的直接手动委托,仅当当前Agent为Claude Code 会话运行在原生Claude模型上时,才可使用本技能。
模型检查(主要规则)。网关的核心目的是模型成本优化:Claude令牌按使用量计费且价格高昂,因此手动工作应转移到Codex;但如果会话已路由到更便宜的其他模型,委托工作则无收益。根据会话实际运行的模型而非传输方式来决策:
  1. 从系统提示的环境部分读取模型ID("You are powered by the model …")。路由包装的ID可能不透明(
    claude-ccr-<hex>
    );十六进制后缀通常是ASCII编码——解码它(
    echo <hex> | xxd -r -p
    )即可揭示底层路由,例如
    Gorilla CCP/native-claude-fable-5
  2. 如果解析后的模型是原生Claude模型(包含
    claude
    fable
    opus
    sonnet
    haiku
    ,包括
    native-claude-*
    路由):将手动工作委托给Codex。即使
    ANTHROPIC_BASE_URL
    是环回地址或本地路由(Gorilla Claw、Clawdex)也适用——原生Claude模型前的路由仍属于高成本的Claude服务。
  3. 如果解析后的模型明确非Claude(GPT或其他供应商路由):会话已处于固定费率/低成本环境;无需自委托,直接处理工作。
Base-URL回退(仅当无法识别模型时)。如果无法看到模型ID且无法解码十六进制/路由,则回退到旧的传输启发式规则:如果
ANTHROPIC_BASE_URL
的主机是
gorillaclaw.sheep-coho.ts.net
localhost
、以
.localhost
结尾、属于
127.0.0.0/8
网段,或是IPv6环回地址
::1
,则假设会话可能路由到非Claude模型,直接处理工作。如果既无法检查模型也无法检查Base URL,则默认直接处理工作。
Codex、ChatGPT、Pi及其他所有工具环境:请勿调用Codex CLI进行手动自委托。直接继续任务。本网关规则会覆盖仅提及
$codex-first
的仓库指令;但不会覆盖上述自动审核例外规则。
原理:Claude(Fable/Opus)令牌按使用量计费且价格高昂;Codex采用固定费率。GPT-5.5+通常在代码编写/实现方面更优、更快;Claude则在人机工程学——判断、设计、规范编写、审核、编排——方面更胜一筹。因此Codex负责编码,Claude负责思考和验证。

Route

任务路由

Delegate to Codex (default for hands-on work):
  • implementation from a frozen spec; refactors; mechanical migrations
  • fixing: bug fixes (known repro, or diagnose-then-fix), CI/lint/type failures; test writing; coverage fills
  • dependency bumps, scripts/tooling
  • exploration + exploratory subagents: fan out Codex for read-heavy discovery instead of Claude Explore/Task subagents whenever raw reading ≫ the answer (parallel
    -o
    files, one per thread)
  • git mechanics — ALWAYS Codex, never Claude directly:
    git rebase
    , merge-conflict 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.
  • work-order CI waits: precheck PR mergeable (CONFLICTING = pull_request CI 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
    ).
  • new work orders go to FRESH
    codex exec
    sessions with self-contained prompts. Do not resume a long-lived session for a new order — saturated sessions misread work orders as configuration and no-op ("Understood…").
  • repo instruction files: NEVER create or edit
    CLAUDE.md
    .
    AGENTS.md
    is 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:
  • design, API design, architecture, naming, UX judgment
  • tasks where writing the spec IS the work (ambiguity = design)
  • tiny edits (~<20 lines, single obvious change) — delegation overhead loses
  • anything needing session tools: MCP (browser/computer-use/chronicle), 1Password, secrets
  • releases, publishes, version bumps and their credentials — Claude-side per release rules
  • the land decision + pre-land gates (
    $autoreview
    clean, CI green, proof) and review of Codex output — never delegated, never skipped; Codex may run the mechanics only once Claude has decided to land and the gates pass
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.
委托给Codex(手动工作的默认选择):
  • 基于冻结规范的实现;重构;机械迁移
  • 修复:bug修复(已知复现步骤,或先诊断后修复)、CI/语法检查/类型错误;测试编写;覆盖率补充
  • 依赖版本升级、脚本/工具开发
  • 探索+探索性子Agent:当原始阅读量远大于答案时,使用Codex进行读密集型探索,替代Claude Explore/Task子Agent(并行使用
    -o
    文件,每个线程对应一个文件)
  • Git操作——必须始终使用Codex,绝不能直接使用Claude:
    git rebase
    、合并冲突解决、仓库落地流程(如
    scripts/pr
    )属于强制委托任务。发布一个独立的工作指令,涵盖变基→解决冲突→推送→CI附加+验证通过→落地的完整流程,避免流程中途回调到Claude;落地决策、网关检查和下方的审核仍由Claude负责。
  • 工作指令CI等待:预检查PR是否可合并(CONFLICTING状态表示pull_request CI无法附加——无合并引用),并确认运行已附加到确切的头部SHA后再轮询;每次等待都会输出所有终端状态并限制迭代次数;优先使用仓库自带的监控脚本(openclaw:
    node scripts/watch-pr-ci.mjs
    )。
  • 新工作指令应发送到全新的
    codex exec
    会话,使用独立的提示。请勿为新指令恢复长期会话——饱和会话会误将工作指令视为配置而无操作("Understood…")。
  • 仓库指令文件:绝不要创建或编辑
    CLAUDE.md
    AGENTS.md
    是所有仓库的标准文件;
    CLAUDE.md
    仅作为其符号链接存在。请将Codex工作指令指向
    AGENTS.md
    ,且仅编辑
    AGENTS.md
保留给Claude处理:
  • 设计、API设计、架构、命名、UX判断
  • 编写规范本身就是工作的任务(模糊性=设计)
  • 微小编辑(约<20行,单一明显修改)——委托开销得不偿失
  • 任何需要会话工具的任务:MCP(浏览器/计算机使用/记录)、1Password、密钥
  • 发布、推送、版本升级及其凭证——遵循Claude端的发布规则
  • 落地决策+落地前网关检查(
    $autoreview
    无问题、CI验证通过、验证证明)以及Codex输出的审核——绝不委托,绝不跳过;只有当Claude决定落地且网关检查通过后,Codex才可执行机械操作
混合任务:Claude先完成设计,冻结规范,再委托实现。 启发式规则:提示内容为工作指令→委托;编写提示需要做出决策→设计,由Claude处理。 多仓库组合工作:使用
$maintainer-orchestrator
替代。

Invoke

调用方式

Before every Codex CLI call, invoke
$codex-next
when that private skill is available. Its machine-specific launch, review, model, and context policy overrides the generic examples below. On a Peter-managed Mac, fail closed and report a missing
codex-next
skill instead of guessing or silently falling back.
If
codex-next
selects the
openai_api_direct
million-token route, run
ruby ~/.codex/skills/agent-scripts/codex-huge-context/scripts/preflight.rb
before the first fresh or resumed launch in the batch. Fail closed if it cannot deliver the Keychain credential; never work around it by overriding the provider or using ordinary Codex authentication.
Prompt via temp file, never inline quoting:
bash
P=$(mktemp); cat >"$P" <<'EOF'
<goal, repo + key paths, constraints ("don't touch X"), non-goals, proof expected, output shape>
EOF
command codex exec --yolo -C <repo> \
  -m gpt-5.6-sol \
  -c model_reasoning_effort="high" \
  --enable fast_mode \
  -o /tmp/codex-last.md - <"$P" 2>/dev/null
  • Model default:
    gpt-5.6-sol
    , effort
    high
    , fast mode on — pin all three explicitly; don't rely on user config.
  • --yolo
    is the house default; Codex may run commands/tests freely. Keep prompts scoped to the target repo.
  • If
    --yolo
    is unavailable—either the CLI rejects the flag or the selected model/backend rejects unrestricted execution—replace it with
    --approve-for-me
    and retry once. Never pass both. Preserve every other argument and constraint.
  • command codex
    bypasses any interactive shell alias. If codex isn't on PATH, it depends on how it was installed:
    • node/standalone install:
      fnm exec --using default -- codex
    • ChatGPT desktop app: the CLI ships bundled at
      /Applications/ChatGPT.app/Contents/Resources/codex
      . Expose that binary with an exec-wrapper, not a symlink. Ensure
      ~/.local/bin
      stays on PATH (for zsh, persist the export in
      ~/.zshrc
      ), then:
      sh
      mkdir -p "$HOME/.local/bin"
      export PATH="$HOME/.local/bin:$PATH"
      if [ -e "$HOME/.local/bin/codex" ] || [ -L "$HOME/.local/bin/codex" ]; then
        printf '%s\n' 'codex launcher already exists; leaving it unchanged' >&2
      else
        printf '#!/bin/sh\nexec "/Applications/ChatGPT.app/Contents/Resources/codex" "$@"\n' > "$HOME/.local/bin/codex" && chmod +x "$HOME/.local/bin/codex"
      fi
      Or install the self-contained CLI via
      curl -fsSL https://chatgpt.com/codex/install.sh | sh
      , which needs no wrapper.
  • stderr suppressed (thinking noise bloats context); drop
    2>/dev/null
    only to debug a failing run
  • read
    -o
    file for the result; don't parse the JSONL stream
  • long runs: Bash run_in_background, read
    -o
    file on exit; don't kill quiet runs <30 min
  • Harness visibility (Claude Code): every codex run gets its own harness-tracked 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.
  • parallel independent tasks OK: separate repos/dirs, separate
    -o
    files, one tracked background command per worker
  • outside a git repo add
    --skip-git-repo-check
每次调用Codex CLI前,若私有
$codex-next
技能可用,请先调用它。其针对特定机器的启动、审核、模型和上下文策略会覆盖以下通用示例。在Peter管理的Mac设备上,若缺少
codex-next
技能,请终止操作并报告,不要猜测或静默回退到默认方式。
如果
codex-next
选择
openai_api_direct
百万令牌路由,请在批次中首次启动或恢复会话前运行
ruby ~/.codex/skills/agent-scripts/codex-huge-context/scripts/preflight.rb
。如果无法获取Keychain凭证,请终止操作;绝不要通过覆盖供应商或使用普通Codex认证来规避此问题。
通过临时文件传递提示,绝不要使用内联引用:
bash
P=$(mktemp); cat >"$P" <<'EOF'
<目标,仓库+关键路径,约束条件("不要修改X"),非目标,预期验证方式,输出格式>
EOF
command codex exec --yolo -C <repo> \
  -m gpt-5.6-sol \
  -c model_reasoning_effort="high" \
  --enable fast_mode \
  -o /tmp/codex-last.md - <"$P" 2>/dev/null
  • 默认模型:
    gpt-5.6-sol
    ,推理强度
    high
    ,启用快速模式——请明确固定这三项设置;不要依赖用户配置。
  • --yolo
    是默认设置;Codex可自由运行命令/测试。请将提示范围限定在目标仓库内。
  • 如果
    --yolo
    不可用——CLI拒绝该标志或所选模型/后端拒绝无限制执行——请替换为
    --approve-for-me
    并重试一次。绝不要同时传递两个标志。保留所有其他参数和约束条件。
  • command codex
    会绕过任何交互式shell别名。如果codex不在PATH中,取决于其安装方式:
    • node/独立安装:
      fnm exec --using default -- codex
    • ChatGPT桌面应用:CLI捆绑在
      /Applications/ChatGPT.app/Contents/Resources/codex
      。请通过执行包装器而非符号链接暴露该二进制文件。确保
      ~/.local/bin
      在PATH中(对于zsh,请在
      ~/.zshrc
      中持久化导出),然后:
      sh
      mkdir -p "$HOME/.local/bin"
      export PATH="$HOME/.local/bin:$PATH"
      if [ -e "$HOME/.local/bin/codex" ] || [ -L "$HOME/.local/bin/codex" ]; then
        printf '%s\n' 'codex启动器已存在;保持不变' >&2
      else
        printf '#!/bin/sh\nexec "/Applications/ChatGPT.app/Contents/Resources/codex" "$@"\n' > "$HOME/.local/bin/codex" && chmod +x "$HOME/.local/bin/codex"
      fi
      或者通过
      curl -fsSL https://chatgpt.com/codex/install.sh | sh
      安装独立CLI,无需包装器。
  • 抑制stderr输出(思考过程会占用过多上下文);仅在调试失败运行时移除
    2>/dev/null
  • 读取
    -o
    文件获取结果;不要解析JSONL流
  • 长时间运行:使用Bash后台运行,退出时读取
    -o
    文件;不要终止运行时间<30分钟的静默进程
  • 工具可见性(Claude Code):每个codex运行都应拥有自己的工具跟踪后台命令(
    run_in_background: true
    )——每个工作进程对应一个侧边栏芯片,包含完成通知。将设置步骤(安装、工作树准备)整合到该跟踪命令内。绝不要从共享启动器通过
    &
    派生工作进程:启动器的芯片会在派生时退出,工作进程会变成仅由PID文件监控的不可见孤儿进程。
  • 并行独立任务允许:独立仓库/目录,独立
    -o
    文件,每个工作进程对应一个跟踪后台命令
  • 在Git仓库外运行时添加
    --skip-git-repo-check

When the worker dies instantly

工作进程立即终止时的处理

A run that exits in seconds having produced nothing is almost never the task — it is the model route. Read the log tail before relaunching; the error names the cause, and relaunching unchanged just repeats it:
  • 401 Invalid API key
    — the configured bearer is not valid at that endpoint.
  • 502 / All target providers failed
    with a
    target_providers
    list — the request reached a router but the model id did not match its catalogue, so it fell through to the wrong upstream. Routers commonly expose aliased model ids that differ from the underlying model's real name; pass the id the router publishes, not the one you think you are using.
  • stream disconnected
    /
    Reconnecting… 5/5
    against a loopback URL — nothing is listening there.
  • requires a sandbox with reviewed escalations
    --yolo
    is unsupported for that route. Retry once with
    --approve-for-me
    , which selects workspace-write, on-request approvals, and automatic review.
Diagnose the route directly rather than by retrying the agent. One request settles it, and it is far cheaper than another failed run:
bash
curl -s -o /dev/null -w '%{http_code}\n' -m 8 <base_url>/models
A local config pointing at a loopback port proves nothing about that port being served: config files outlive the services they were written for, and a machine-managed provider block can reference an instance that no longer runs. Check what is actually listening before trusting it.
Never pass a credential through
-c key=value
— it lands in argv, process listings, and shell history. When a run needs different provider settings, write a private overlay instead and point
CODEX_HOME
at it: a mode-0700 directory holding a mode-0600
config.toml
(copy
auth.json
across if the provider needs it). That keeps the secret in a file, leaves the user's global config untouched, and is trivially disposable.
If the environment's own Codex config is broken, say so rather than silently working around it every invocation — the next task will hit the same wall.
Follow-up fixes — cheaper than fresh runs, keeps context.
resume
has no
-C
/
--yolo
: run from the repo dir, spell the long flag:
bash
(cd <repo> && command codex exec resume --last \
  --dangerously-bypass-approvals-and-sandbox \
  -o /tmp/codex-last.md - <"$P2" 2>/dev/null)
几秒内退出且未产生任何输出的运行几乎与任务无关——问题出在模型路由。重新启动前读取日志尾部;错误信息会指明原因,无修改的重新启动只会重复失败:
  • 401 Invalid API key
    ——配置的Bearer令牌在该端点无效。
  • 502 / All target providers failed
    并附带
    target_providers
    列表——请求已到达路由,但模型ID与其目录不匹配,因此被转发到错误的上游。路由通常会暴露与底层模型真实名称不同的别名模型ID;请传递路由发布的ID,而非你认为正在使用的ID。
  • stream disconnected
    /
    Reconnecting… 5/5
    针对环回URL——该端口无服务监听。
  • requires a sandbox with reviewed escalations
    ——该路由不支持
    --yolo
    。请使用
    --approve-for-me
    重试一次,该选项会选择工作区写入、按需审批和自动审核。
直接诊断路由而非通过重试Agent。一次请求即可解决问题,比再次失败的运行成本低得多:
bash
curl -s -o /dev/null -w '%{http_code}\n' -m 8 <base_url>/models
指向环回端口的本地配置无法证明该端口正在提供服务:配置文件的生命周期可能长于其对应的服务,且机器管理的供应商块可能引用已停止运行的实例。在信任它之前,请检查实际监听的服务。
绝不要通过
-c key=value
传递凭证
——它会出现在argv、进程列表和shell历史中。当运行需要不同的供应商设置时,请编写私有覆盖配置并将
CODEX_HOME
指向它:一个权限为0700的目录,包含权限为0600的
config.toml
(如果供应商需要,复制
auth.json
到该目录)。这样可将密钥保存在文件中,不修改用户的全局配置,且可轻松删除。
如果环境自身的Codex配置损坏,请告知用户,不要在每次调用时静默规避——下一个任务仍会遇到相同问题。
后续修复——比全新运行成本更低,可保留上下文。
resume
-C
/
--yolo
选项:请从仓库目录运行,使用完整标志:
bash
(cd <repo> && command codex exec resume --last \
  --dangerously-bypass-approvals-and-sandbox \
  -o /tmp/codex-last.md - <"$P2" 2>/dev/null)

Liveness watchdog (long monitored runs)

活跃度监控(长时间监控运行)

For runs you must not babysit, trade the stderr suppression for a log and watch its mtime; read only the
-o
file into context, never the log body.
bash
command codex exec --yolo -C <repo> -m gpt-5.6-sol \
  -c model_reasoning_effort="high" --enable fast_mode \
  -o "$OUT" - <"$P" > "$LOG" 2>&1
对于无需人工值守的运行,请取消stderr抑制并记录到日志,监控其修改时间;仅将
-o
文件内容读入上下文,绝不要读取日志正文。
bash
command codex exec --yolo -C <repo> -m gpt-5.6-sol \
  -c model_reasoning_effort="high" --enable fast_mode \
  -o "$OUT" - <"$P" > "$LOG" 2>&1

Claude Code: run the line above as its own Bash run_in_background call

Claude Code:将上述命令作为独立的Bash run_in_background调用

(tracked chip + completion notification). Append
&
+ a PID file ONLY in

environments without tracked backgrounding.


- Capture the session id immediately: `grep -m1 "session id:" "$LOG"`. `resume --last` is cwd-filtered but races with any parallel Codex on the machine — with the id saved, recovery is deterministic.
- Watchdog loop (Claude Code: `Monitor` tool; else a bg shell): every 60s, if the codex process is alive but `$LOG` mtime is older than ~300s, treat it as hung. Because stderr (thinking stream) is in the log, mtime stays fresh during long reasoning — 5 min of true silence is a real hang, not thinking.
- Recovery: kill the pid, then resume the SAME session with an explicit id so no context is lost:

```bash
(cd <repo> && command codex exec resume <session-id> \
  --dangerously-bypass-approvals-and-sandbox \
  -o "$OUT" - <<< "You were interrupted. Continue exactly where you left off; finish the task and produce the required final report.")
  • Exit watchdog silently when the process ends normally (the run's own completion signal covers it); emit only on staleness.
  • Verified on codex-cli 0.144.4:
    codex exec resume [SESSION_ID] [PROMPT]
    ,
    --last
    , cwd-filtering,
    --all
    .
#(跟踪芯片+完成通知)。仅在无跟踪后台功能的环境中添加
&
+PID文件。

- 立即捕获会话ID:`grep -m1 "session id:" "$LOG"`。`resume --last`按当前目录过滤,但会与机器上的任何并行Codex进程竞争——保存ID后,恢复操作是确定性的。
- 监控循环(Claude Code:使用`Monitor`工具;其他环境:后台shell):每60秒检查一次,如果codex进程仍存活但`$LOG`的修改时间早于约300秒,则视为挂起。由于stderr(思考流)记录在日志中,长时间推理时修改时间会保持更新——5分钟的真正静默表示确实挂起,而非正在思考。
- 恢复:终止进程PID,然后使用明确的ID恢复同一会话,避免丢失上下文:

```bash
(cd <repo> && command codex exec resume <session-id> \
  --dangerously-bypass-approvals-and-sandbox \
  -o "$OUT" - <<< "You were interrupted. Continue exactly where you left off; finish the task and produce the required final report.")
  • 当进程正常结束时,监控程序静默退出(运行自身的完成信号会覆盖此情况);仅在进程停滞时发出通知。
  • 在codex-cli 0.144.4上验证:
    codex exec resume [SESSION_ID] [PROMPT]
    --last
    、按当前目录过滤、
    --all

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.
  • Every hard prohibition needs an escape hatch. A cornered worker satisfies the letter of the 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).
  • Multi-PR series: same spec skeleton every PR; cite prior landed PR numbers and name their 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.
  • End every series work order with an explicit stop: "Do exactly this; do not start PR N+1."
Codex启动时无任何会话上下文。每个提示必须包含:目标、确切的仓库/路径、约束条件、非目标、预期验证方式(确切的测试命令)、输出格式("报告修改的文件+测试输出")。规范质量决定任务成败。
  • 每个严格禁止项都需要一个逃生通道。陷入困境的工作进程会严格遵循网关规则:被告知"绝不要提高大小预算"但设计导致包体积增大时,Codex会将源标识符手动压缩为单个字母——且会通过所有网关检查,包括自动审核。请为每个严格约束配对批准的退出方式:"如果经过诚实尝试后网关X仍失败:停止,报告确切数字/诊断结果,不要规避。"将停止报告视为成功运行(这是协调者的决策点,工作进程一旦知晓此规则就会正确执行)。
  • 多PR系列:每个PR使用相同的规范框架;引用之前已落地的PR编号并说明其惯用模式("具有窄主机接口的控制器,#NNN格式")——工作进程模仿已落地的先例比遵循抽象风格规则更可靠。将每一轮的新陷阱整合到下一个规范中。
  • 每个系列工作指令的结尾必须明确停止:"仅执行此项;不要启动PR N+1。"

Coordinator verification (beyond the diff)

协调者验证(超出代码差异)

Worker reports are accurate but incomplete — pathologies live in the code, not the summary. After every landed PR, verify against merged origin/main, not the report:
  • read the actual merged surface (types, interfaces, naming) — the minification incident was invisible in a green report and obvious in 10 lines of code
  • squash history: any commit message you didn't commission ("add startup margin") is a lead
  • diff-stat the guard/budget/baseline files the spec forbade touching; if a limit number in the report changed, find out who moved it (may be main advancing, may be the worker)
  • test-helper edits are a red-flag class of their own (defineProperty shims re-exposing moved fields keep suites green while hiding the migration)
工作进程的报告准确但不完整——问题隐藏在代码中,而非摘要里。每个PR落地后,请针对合并后的origin/main进行验证,而非仅依赖报告:
  • 读取实际合并的代码表面(类型、接口、命名)——压缩事件在绿色报告中不可见,但在10行代码中一目了然
  • 压缩历史:任何你未委托的提交消息("添加启动余量")都是线索
  • 统计规范禁止修改的防护/预算/基准文件的差异;如果报告中的限制数字发生变化,请查明是谁修改的(可能是main分支更新,也可能是工作进程修改)
  • 测试辅助工具编辑属于一类红色标志(defineProperty垫片重新暴露已移动的字段,保持测试套件通过但隐藏迁移问题)

Parallel workers, one repo

并行工作进程,单个仓库

Disjoint-file tasks parallelize cleanly: one worktree + unique branch per worker (fresh from origin/main; distinctive branch names — generic ones attach to old PRs), one tracked background command each, shared spec body + per-target header. Landing serializes on the repo's land workflow lock: tell each worker a held lock means a sibling owns it — back off 5-10 min, retry from the failed step, NEVER lock-recover a lock it didn't create, and don't chase main with fresh gates as siblings land under it. Sequential series instead reuse ONE worktree, rebranching from origin/main per PR.
无交叉文件的任务可清晰并行化:每个工作进程对应一个工作树+唯一分支(从origin/main新建;使用独特的分支名称——通用名称会关联到旧PR),每个工作进程对应一个跟踪后台命令,共享规范主体+每个目标的头部信息。落地流程会在仓库的落地工作流锁上序列化:告知每个工作进程,持有锁表示其他工作进程拥有它——退避5-10分钟,从失败步骤重试,绝不要恢复非自身创建的锁,且不要在其他工作进程落地时追逐main分支的新网关。连续系列任务则重用一个工作树,每个PR从origin/main重新分支。

Verify (Claude, always)

验证(始终由Claude执行)

  • git status -sb
    + read the full diff; judge like a contributor PR
  • run focused tests yourself or demand proof output; Codex claims are advisory
  • iterate via resume; after 2 failed rounds, take over and do it directly
  • normal closeout still applies:
    $autoreview
    before ship
  • check for a live worker in the repo before you edit or commit:
    pgrep -fl "codex exec"
    . A run whose deliverable is already in the tree can keep looping for hours and overwrite your fixes mid-review. Stop it once you have verified its output rather than racing it.
  • a genuinely independent review pass earns its keep: reviewing the working tree after a Codex build found a currency value being fed to a percentage helper that clamped at 100, which typechecked, passed every test, and was invisible in the worker's own report.
  • 运行
    git status -sb
    + 读取完整差异;像审核贡献者PR一样判断
  • 自行运行聚焦测试或要求提供验证输出;Codex的声明仅供参考
  • 通过resume进行迭代;经过2次失败尝试后,接管并直接处理
  • 正常收尾仍适用:交付前执行
    $autoreview
  • 在编辑或提交前,请检查仓库中是否有活跃的工作进程
    pgrep -fl "codex exec"
    。交付物已在代码树中的运行可能会持续循环数小时,并在你审核期间覆盖你的修复。验证其输出后请立即停止它。
  • 真正独立的审核环节至关重要:在Codex构建后审核工作树时,发现一个货币值被输入到一个上限为100的百分比工具中,这通过了类型检查、所有测试,且在工作进程的报告中不可见。

Economics

成本优化

Win = generation + exploration tokens moved to Codex; Claude spends only on spec + diff review. Don't ping-pong trivia through delegation; don't re-read what Codex already summarized.
成功 = 将生成+探索令牌转移到Codex;Claude仅在规范+差异审核上花费令牌。不要通过委托来回传递琐碎内容;不要重新读取Codex已总结的内容。