GPT WORLD / INDEPENDENT CODEX FIELD MANUAL 出典レビュー · 2026-07-31

フィールドガイド / 12 分

codex exec で再現可能な headless 作業を行う

検証済み repository 手順を script 化し、権限と失敗の境界を保ちます。

トラック
Codex CLI コア
レベル
Automation
成熟度
Runtime-confirmed in Codex 0.147.0

codex exec は script と CI の非対話入口です。Prompt を引数または stdin から受け取り、repository guidance と sandbox model を共有し、process status を返し、保存済み exec session も再開できます。信頼性は自動化という言葉ではなく、固定 working directory、明示的 authority、隔離 credential、会話の調子に依存しない verification から生まれます。

CLI

検証済みターミナル手順

TERMINAL / 意図を持ってコピー
  1. $codex exec "Run the affected tests and report evidence"
  2. $codex exec --ephemeral "Inspect the repository and make no changes"
  3. $codex exec resume --last "Continue with the failed checks"
A

作業原則

01

既知の手順を自動化

Live operator を外す前に prompt、repo context、acceptance checks を監督下で証明します。

02

Exit status も contract

Non-zero、timeout、malformed output、artifact 欠落は、楽観的な文章があっても失敗です。

03

Persistence は選択

Session file を残さない時は --ephemeral。Checkout が適合し履歴継続が必要な時だけ resume。

B

フィールド手順

  1. 01

    Working root を固定

    一つの checkout または -C を使い、広い親 directory から複数 repo を探索させません。

  2. 02

    Acceptance evidence を記述

    変更可能 files、実行 command、必要な tests/artifacts を指定します。

  3. 03

    Execution を制限

    Sandbox、approval posture、timeout、credential scope を選びます。

  4. 04

    Process result を処理

    stdout/stderr を分離し、time budget と non-zero failure を強制します。

  5. 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。