Codex 的配置文件按用户级、项目级、系统级分层。优先级清楚,定制才稳定。

config.toml:用户级与项目级配置

配置不是越多越好。先理解优先级,再写最小配置。

位置

  • 用户级:~/.codex/config.toml
  • 项目级:<repo>/.codex/config.toml
  • 系统级:/etc/codex/config.toml

优先级(高到低)

  1. CLI flags 和 --config
  2. Profile(已选中的配置组)。
  3. 项目 .codex/config.toml
  4. 用户 ~/.codex/config.toml
  5. 系统 /etc/codex/config.toml
  6. 内置默认值。

常见字段

# ~/.codex/config.toml
model = "gpt-5-codex"
reasoning_effort = "medium"
ask_for_approval = "on-request"
sandbox = ":workspace"

[notifications]
on_completion = true
on_approval_needed = true

Trusted Project

项目级 .codex/ 配置只有在项目被 trust 后才加载。未信任时,项目级 hooks、rules、config 不会生效。

提示:把项目 trust 当作一次性确认动作,不要每个新项目都默认 trust。