Configuration

环境变量

环境变量适合机器或会话级配置,不适合承载敏感信息的明文分发。

Codex 使用 config.toml 保存持久设置。环境变量适合 shell 作用域覆盖、自动化 secrets、安装器行为或诊断。

本页列出 Codex 会直接读取的稳定公开环境变量;不列出内部开发变量、测试变量,或你通过 env_key 自行选择的 provider-specific secret 名称。

核心位置

VariableUsed byDefaultDescription
CODEX_HOMECLI, IDE extension, app-server, installers~/.codexSets the root for Codex state, including config, auth, logs, sessions, skills, 和 standalone package metadata。如果 you 设置 it, directory must already exist.
CODEX_SQLITE_HOMECLI 和 app-server stateCODEX_HOMESets 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 安装脚本。

VariableDefaultDescription
CODEX_NON_INTERACTIVEfalse设置 到 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 WindowsChanges 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

认证与网络

VariableUsed byDescription
CODEX_API_KEYcodex execProvides 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_TOKENCLI, app-server, trusted automationProvides a ChatGPT 或 Codex access token for trusted automation。For 持久化ed login, pipe it 到 codex login --with-access-token.
CODEX_CA_CERTIFICATEHTTPS, login, 和 WebSocket clientsPoints 到 a PEM CA bundle for environments 使用 corporate TLS interception 或 private root CAs。Takes precedence over SSL_CERT_FILE.
SSL_CERT_FILEHTTPS, login, 和 WebSocket clientsFallback 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

诊断

VariableUsed byDescription
RUST_LOGCLI 和 app-serverControls 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。

站内延伸阅读