GPT WORLD / INDEPENDENT CODEX FIELD MANUAL 來源檢視 · 2026-07-26

實作指南 / 15 分鐘

用 AGENTS.md 保存 repository 知識

分層放置個人偏好、團隊規則與 directory-specific instructions。

軌道
Codex CLI 核心
程度
Repository 設定
成熟度
Stable

Codex 工作前會組成 instruction chain:global guidance,再由 repo root 走到 cwd。越近的 guidance 越晚出現並覆蓋廣泛規則;同一層 AGENTS.override.md 優先,combined project guidance 有預設 size limit。

CLI

已驗證 Terminal Sequence

TERMINAL / 刻意複製
  1. /init
  2. $codex --ask-for-approval never "Summarize the current instructions."
  3. $codex -C services/payments --ask-for-approval never "List the instruction sources you loaded."
A

工作原則

01

規則靠近 scope

Repo-wide command 放 root,service-specific constraint 放 service 附近。

02

記錄 recurring friction

重複 mistake/review comment 才加入,不塞入所有偏好。

03

驗證 discovery

從目標 cwd 要求列出 loaded sources,不假設 precedence。

B

實地程序

  1. 01

    產生 scaffold

    用 /init 起步,再換成真實 command/constraint。

  2. 02

    寫 root contract

    記錄 layout、build、tests、lint、architecture boundary、done。

  3. 03

    加入窄 override

    只有行為真的不同才使用 nested AGENTS 或 override。

  4. 04

    保持 chain 精簡

    預設 combined limit 32 KiB;深層說明改連結。

  5. 05

    從不同 directory 測試

    在 root 與 specialized subtree 驗證 sources。

PASS / FAIL

驗收清單

  • Commands 可執行且最新。
  • Constraint 在最近正確 scope。
  • Loaded sources 已驗證。
  • 沒有 secrets/personal volatile data。

WATCH / REJECT

失敗模式

  • 把 AGENTS.md 當完整 security enforcement。
  • 只寫抽象價值不寫 command。
  • 忘記 override 遮蔽 base。