Codex 使用 config.toml 保存持久设置。环境变量适合 shell 作用域覆盖、自动化 secrets、安装器行为或诊断。
本页列出 Codex 会直接读取的稳定公开环境变量;不列出内部开发变量、测试变量,或你通过 env_key 自行选择的 provider-specific secret 名称。
核心位置
| Variable | Used by | Default | Description |
|---|---|---|---|
| CODEX_HOME | CLI, IDE extension, app-server, installers | ~/.codex | Sets the root for Codex state, including config, auth, logs, sessions, skills, 和 standalone package metadata。如果 you 设置 it, directory must already exist. |
| CODEX_SQLITE_HOME | CLI 和 app-server state | CODEX_HOME | Sets where SQLite-backed state is stored。The sqlite_home config option takes precedence。Relative paths resolve 从 the 当前 working directory. |
关于 CODEX_HOME 下存储的文件,请参见 Config and state locations。
安装器变量
这些变量适用于 https://chatgpt.com/codex/install.sh 和 https://chatgpt.com/codex/install.ps1 提供的 standalone 安装脚本。
| Variable | Default | Description |
|---|---|---|
| CODEX_NON_INTERACTIVE | false | 设置 到 1, true, 或 yes 到 skip installer prompts。Prompts 使用 their 默认 response, so 使用 this for scripted installs 和 updates, not first-run setup. |
| CODEX_INSTALL_DIR | ~/.local/bin on macOS/Linux;%LOCALAPPDATA%\Programs\打开AI\Codex\bin on Windows | Changes where the visible codex command is installed. The standalone package cache still lives under CODEX_HOME/packages/standalone. |
对于无人值守安装,请在运行下载后安装器的 shell 中设置 CODEX_NON_INTERACTIVE=1:
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_NON_INTERACTIVE=1 sh $env:CODEX_NON_INTERACTIVE=1; irm https://chatgpt.com/codex/install.ps1 | iex 认证与网络
| Variable | Used by | Description |
|---|---|---|
| CODEX_API_KEY | codex exec | Provides an API key for a single non-interactive 运行。This is only 支持的 in codex exec;设置 it inline rather than job-wide 当 running repository-controlled code. |
| CODEX_ACCESS_TOKEN | CLI, app-server, trusted automation | Provides a ChatGPT 或 Codex access token for trusted automation。For 持久化ed login, pipe it 到 codex login --with-access-token. |
| CODEX_CA_CERTIFICATE | HTTPS, login, 和 WebSocket clients | Points 到 a PEM CA bundle for environments 使用 corporate TLS interception 或 private root CAs。Takes precedence over SSL_CERT_FILE. |
| SSL_CERT_FILE | HTTPS, login, 和 WebSocket clients | Fallback PEM CA bundle path 当 CODEX_CA_CERTIFICATE is unset. |
对于 provider API keys,请在 model provider 配置中设置 env_key 。Codex 会读取该配置指定名称的变量,因此变量名本身不是固定的 Codex 环境变量。
自动化 secret 处理请参见 Use API key auth。access token 设置请参见 Access tokens 。
诊断
| Variable | Used by | Description |
|---|---|---|
| RUST_LOG | CLI 和 app-server | Controls Rust log filtering 和 verbosity。codex exec defaults to error output unless you set a more verbose value. |
RUST_LOG 接受 error、warn、info、debug、trace 等值,也接受更精确的 Rust logging filters,例如 codex_core=debug,codex_tui=debug。
interactive CLI 默认会把诊断信息记录到有界的本地存储中,但明文 codex-tui.log 是 opt-in。需要用于 troubleshooting 的明文日志时,请显式设置 log_dir:
RUST_LOG=debug codex -c log_dir=./.codex-log
tail -F ./.codex-log/codex-tui.log 在 non-interactive 模式下,codex exec 会内联打印消息,而不是写入单独的 TUI log file。