フィールドガイド / 12 分
codex exec で再現可能な headless 作業を行う
検証済み repository 手順を script 化し、権限と失敗の境界を保ちます。
codex exec は script と CI の非対話入口です。Prompt を引数または stdin から受け取り、repository guidance と sandbox model を共有し、process status を返し、保存済み exec session も再開できます。信頼性は自動化という言葉ではなく、固定 working directory、明示的 authority、隔離 credential、会話の調子に依存しない verification から生まれます。
検証済みターミナル手順
- $
codex exec "Run the affected tests and report evidence" - $
codex exec --ephemeral "Inspect the repository and make no changes" - $
codex exec resume --last "Continue with the failed checks"
作業原則
既知の手順を自動化
Live operator を外す前に prompt、repo context、acceptance checks を監督下で証明します。
Exit status も contract
Non-zero、timeout、malformed output、artifact 欠落は、楽観的な文章があっても失敗です。
Persistence は選択
Session file を残さない時は --ephemeral。Checkout が適合し履歴継続が必要な時だけ resume。
フィールド手順
- 01
Working root を固定
一つの checkout または -C を使い、広い親 directory から複数 repo を探索させません。
- 02
Acceptance evidence を記述
変更可能 files、実行 command、必要な tests/artifacts を指定します。
- 03
Execution を制限
Sandbox、approval posture、timeout、credential scope を選びます。
- 04
Process result を処理
stdout/stderr を分離し、time budget と non-zero failure を強制します。
- 05
Retry を明示
Transient failure だけを再試行し、新規 ephemeral run または exact session を選びます。
PASS / FAIL
受入チェック
- 一つの verified checkout。
- Least-privilege credentials。
- Timeout/non-zero は fail closed。
- Repository tests が通る。
- Retry が外部 side effect を重複しない。
WATCH / REJECT
失敗パターン
- 通常 CI で --yolo。
- Untrusted PR code に write credential。
- Typed contract が必要なのに自然言語を parse。