# 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.

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.

```bash
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.

```toml
[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

| Key | Values and meaning |
| --- | --- |
| `sandbox_mode` | `read-only`, `workspace-write`, `danger-full-access` |
| `approval_policy` | `on-request`, `never` or a granular table. `untrusted` is unsupported and `on-failure` is deprecated |
| `sandbox_workspace_write.network_access` | Allows outbound network inside `workspace-write` |
| `sandbox_workspace_write.writable_roots` | Extra writable folders |
| `default_permissions` | A named permission profile. Do not combine with `sandbox_mode` |
| `shell_environment_policy.inherit` | `all`, `core` or `none` for subprocess environment |
| `shell_environment_policy.ignore_default_excludes` | Keeps variables containing KEY, SECRET or TOKEN out before other filters when `true` |
| `history.persistence` | `save-all` or `none` |
| `cli_auth_credentials_store` | `file`, `keyring`, `auto`, `ephemeral` |
| `allow_login_shell` | Boolean. When `false`, login-shell requests are rejected |
| `features.hooks` | Turns lifecycle hooks on or off |

## A cautious starting file

```toml
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](https://www.excellent.so/guides/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.

```bash
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](https://www.excellent.so/guides/codex-api-key).

Checked against the vendor documentation on November 25, 2026. [Config basics](https://learn.chatgpt.com/docs/config-file/config-basic) · [Config reference](https://learn.chatgpt.com/docs/config-file/config-reference) · [Advanced config](https://learn.chatgpt.com/docs/config-file/config-advanced) · [CLI reference](https://learn.chatgpt.com/docs/developer-commands?surface=cli)

## 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](https://www.excellent.so/scan). [See a sample report](https://www.excellent.so/r/sample). Excellent Pro can configure Codex’s native Mac sandbox from your file and folder rules, with a plan to review first. [Sandbox setup](https://www.excellent.so/docs/sandbox) · [Pricing](https://www.excellent.so/pricing). Pro is US-only for now.

Source: https://www.excellent.so/guides/codex-config-toml
