Skip to content
← All guides

Codex config.toml: location, precedence and safe settings

Where Codex reads config.toml, which layer wins, how profiles and project trust work, and the keys that control sandbox, approvals and secrets.

4 min read

Your personal Codex defaults live in ~/.codex/config.toml. A repo can add .codex/config.toml, and Codex loads it only when you trust the project. Command-line flags and -c overrides beat every file. The security-relevant keys are sandbox_mode, approval_policy, shell_environment_policy, history.persistence and projects.<path>.trust_level.

Precedence

The config docs list these layers, highest first.

  1. CLI flags and --config overrides
  2. Project .codex/config.toml files, from the project root down to your current directory, with the closest file winning
  3. A profile file chosen with --profile
  4. User config at ~/.codex/config.toml
  5. Cloud-managed config.toml defaults, when delivered for the signed-in workspace
  6. System config at /etc/codex/config.toml on Unix
  7. Built-in defaults

Administrators can also set managed requirements. The docs describe requirements.toml for managed hooks, and forced_login_method restricts sign-in to chatgpt or api.

Profiles

Profiles are separate files. The CLI reference says --profile (short form -p) layers $CODEX_HOME/<name>.config.toml on top of the base user config. Keep shared defaults in config.toml and put only the differences in a profile file, such as a stricter one for client work.

codex -p review

Project trust

The docs say Codex loads project .codex/ layers only when you trust the project. For an untrusted project it skips project config, hooks and rules, while user and system config still load. You can record the decision in config.

[projects."/Users/you/work/repo"]
trust_level = "trusted"

Allowed values are "trusted" and "untrusted". Trusting a repo lets its .codex/ files change how Codex behaves, so trust only code you have read.

Security-relevant keys

KeyValues and meaning
sandbox_moderead-only, workspace-write, danger-full-access
approval_policyon-request, never or a granular table. untrusted is unsupported and on-failure is deprecated
sandbox_workspace_write.network_accessAllows outbound network inside workspace-write
sandbox_workspace_write.writable_rootsExtra writable folders
default_permissionsA named permission profile. Do not combine with sandbox_mode
shell_environment_policy.inheritall, core or none for subprocess environment
shell_environment_policy.ignore_default_excludesKeeps variables containing KEY, SECRET or TOKEN out before other filters when true
history.persistencesave-all or none
cli_auth_credentials_storefile, keyring, auto, ephemeral
allow_login_shellBoolean. When false, login-shell requests are rejected
features.hooksTurns lifecycle hooks on or off

A cautious starting file

sandbox_mode = "workspace-write"
approval_policy = "on-request"
 
[shell_environment_policy]
inherit = "core"
 
[history]
persistence = "save-all"

Setting persistence = "none" stops local transcript saving, which also removes your record of what the agent did. Think about that trade before you use it. The sandbox keys are explained in Codex sandbox.

One-off overrides

Use -c key=value for a single run. The installed help for Codex CLI 0.166.0 says the value is parsed as TOML and falls back to a literal string if it does not parse. The same help lists --strict-config, which errors on fields this version does not recognize. That catches a typo that would otherwise leave a setting silently unset.

codex --strict-config -c 'sandbox_mode="read-only"'

Check the result

Codex 0.166.0 includes codex doctor, which diagnoses local installation, config, auth and runtime health. Run it after editing config, and use /status in a session to see the active directories. Do not commit a user config that contains tokens. Credentials belong in the credential store, as described in Codex API key.

Checked against the vendor documentation on November 25, 2026. Config basics · Config reference · Advanced config · CLI reference

See what the settings allowed

Excellent’s free scan reads supported logs on the Mac and reports findings for review. For a local report without installing an app, run the free scan. See a sample report. Excellent Pro can configure Codex’s native Mac sandbox from your file and folder rules, with a plan to review first. Sandbox setup · Pricing. Pro is US-only for now.

Related guides

View all