Codex Advanced Configuration
Codex CLI's advanced configuration layer lets us finely control model providers, sandbox permissions, Hooks, telemetry data, and terminal behavior.
If this is your first time using Codex, first read Config basics (configuration fundamentals)to build a general understanding; this article assumes you already know about the existence and role of ~/.codex/config.toml.
Overview of the configuration hierarchy
Codex's configuration is built from multiple stacked layers; understanding this is the foundation of all advanced usage that follows.
From bottom to top: system level → user level (~/.codex/config.toml) → Profile level → project level (.codex/config.toml) → CLI command-line arguments.
Upper layers override same-named settings in lower layers, and the project configuration closest to the current working directory has the highest priority.
The safest way to determine the currently effective configuration is codex --help combined with logs, or explicitly using codex exec "show my current config" to let the model interpret it for you.
The Profiles named configuration layer
Profile is Codex's recommended "scenario switching" approach: save a set of settings as a TOML file and load it on demand via --profile.
Profile files are located in ~/.codex/
Create and use a Profile
Suppose you often do in-depth code reviews and want stronger reasoning:
Example
File path: ~/.codex/deep-review.config.toml
model =
"gpt-5.5"
Use a model with stronger reasoning
model_reasoning_effort =
"xhigh"
Set reasoning effort to the maximum
approval_policy =
"on-request"
Prompt for approval on every tool call
model_catalog_json =
"/Users/me/.codex/model-catalogs/deep-review.json"
Optional: custom model catalog
Start Codex with a Profile:
Example
Start interactive TUI
codex
--profile
deep-review
or use it in non-interactive exec mode
codex
exec
--profile
deep-review
"review this change"
Profile merge semantics
A Profile file is not a complete configuration; it is an incremental overlay on top of the user-level ~/.codex/config.toml.
This means the Profile only needs to contain fields that "differ from the default configuration"; all other fields automatically inherit the user-level settings.
If both the user level and the Profile set model_catalog_json, the Profile's value takes precedence.
Starting from Codex 0.134.0,--profile it no longer reads the config.toml inside [profiles.
] , and no longer supports the top-level profile = "name" selector. All legacy Profile settings must be migrated to separate ~/.codex/.config.toml files.
Migrating from old configuration to Profile
If your previous config.toml looked like this:
Example
Old syntax (deprecated)
profile =
"deep-review"
[
profiles.deep-review
]
model =
"gpt-5.5"
model_reasoning_effort =
"xhigh"
needs to be split into two files:
# File path: ~/.codex/config.toml (keep non-profile part)
# Note: removed profile = "deep-review" selector
# File path: ~/.codex/deep-review.config.toml
model = "gpt-5.5"
model_reasoning_effort = "xhigh"
After migration, the original codex --profile deep-review command-line usage remains unchanged.
One-time command-line overrides
Sometimes you just want to temporarily change one or two fields for a single task without polluting the configuration file. You can use a CLI override:
Prefer dedicated flags
If the official tool provides a dedicated parameter (such as --model), prefer the dedicated flag for the best readability:
Example
Switch models with a dedicated flag
codex
--model
gpt-
5.4
Override any key with --config
For fields without a dedicated flag, use -c or --config to override. The value is in TOML format, not JSON.
Example
String values need nested quotes using double quotes
codex
--config
model
=
'"gpt-5.4"'
Write boolean values directly
codex
--config
sandbox_workspace_write.network_access=
true
Arrays use TOML array syntax
codex
--config
'shell_environment_policy.include_only=["PATH","HOME"]'
A few easy-to-miss rules:
- Use dot syntax to locate nested fields, e.g., mcp_servers.context7.enabled=false
- The value of --config is parsed as TOML; strings containing spaces must be quoted
- When parsing fails, Codex treats the entire value as a string
The fastest way to check whether an override took effect is to follow the command with a simple question: "what model are you using?", letting Codex report its current configuration.
Configuration files and state locations
Codex stores all local state under the CODEX_HOME directory, which defaults to ~/.codex.
Common files and their meanings:
| file | Purpose | Sensitive? |
|---|---|---|
| config.toml | Main local configuration; all custom settings go here | No |
| auth.json | File-based credentials (if the system keychain is not used) | Yes, recommended permission 600 |
| history.jsonl | Session history (can be disabled) | May contain sensitive content |
| logs/、caches/ | Runtime logs and cache | May contain request body fragments |
Just want to change the OpenAI base URL?
Many people use LLM proxies, routers, or data residency projects and only need to modify the base URL of the built-in openai provider.
In that case, set openai_base_url directly and do not create [model_providers.openai], because the built-in ID cannot be overridden:
Example
File path: ~/.codex/config.toml
Point the built-in openai provider's base URL to the proxy
openai_base_url =
"https://us.api.openai.com/v1"
Project-level configuration .codex/config.toml
Project-level configuration is placed in .codex/config.toml at the repository root to share defaults across the team.
Codex searches upward from the working directory; the file closest to the current working directory has the highest priority.
Boundaries of project-level configuration
For security reasons, the project-level .codex/ layer (including config.toml, local hooks, and local rules) is loaded only when the project is marked as "trusted".
In untrusted projects, the sensitive keys listed below are ignored and a startup warning is printed:
| Ignored keys | Reason |
|---|---|
| openai_base_url、chatgpt_base_url | Prevent credential redirection / changing host metadata |
| apps_mcp_product_sku | Affect Codex Apps product identification |
| model_provider、model_providers | Prevent replacement of credentials / provider identity |
| notify | Prevent execution of arbitrary local machine commands |
| profile、profiles | Config profile cannot be selected at the project level |
| experimental_realtime_ws_base_url、otel | Telemetry and real-time channels |
These keys must be placed in the user-level ~/.codex/config.toml.
Relative paths (such as model_instructions_file) are resolved relative to the directory containing their .codex/.
If the project is untrusted and you set model_provider = "proxy", Codex prints a warning at startup and uses the default provider; this is a security design, not a bug.
Hooks lifecycle hooks
Hooks let you insert custom scripts at key points such as tool calls and turn starts, suitable for auditing, sensitive-word filtering, commit checks, and more.
Hooks configuration supports two forms, with identical event structures:
| form | Position | Suitable scenarios |
|---|---|---|
| hooks.json file | In the same directory as config.toml | JSON is toolchain-friendly and easy to reuse |
| Inline [[hooks.*]] tables | Inside config.toml | All configuration managed in one place |
The four most commonly used load locations:
- ~/.codex/hooks.json
- ~/.codex/config.toml
/.codex/hooks.json /.codex/config.toml
Project-level hooks are loaded only when the project is trusted; user-level hooks are always loaded independently.
Inline TOML Hook example
Below is a pre-check hook that runs before Bash tool calls:
Example
File path: ~/.codex/config.toml
Match all Bash tool calls
[
[
hooks.PreToolUse
]
]
matcher =
"^Bash$"
[
[
hooks.PreToolUse.hooks
]
]
type
=
"command"
Call a pre-check script inside the repository (path relative to the directory containing .codex/)
command
=
'/usr/bin/python3 "$(git rev-parse --show-toplevel)/.codex/hooks/pre_tool_use_policy.py"'
timeout =
30
Timeout in seconds; a timeout is treated as a rejection
statusMessage =
"Checking Bash command"
Status bar message
If both a hooks.json file and an inline [hooks] table exist at the same level, Codex loads both and prints a warning. It is recommended to use only one form per level to avoid doubling maintenance cost.
Custom model providers
When you need Codex to connect to non-OpenAI official endpoints such as LLM proxies, Ollama, Mistral, or Azure, model_providers is the entry point.
Built-in provider IDs (openai, ollama, lmstudio) cannot be reused, otherwise conflicts will occur.
Basic definition
Example
File path: ~/.codex/config.toml
model =
"gpt-5.4"
The model name is determined by the selected provider
model_provider =
"proxy"
Points to [model_providers.proxy] below
[
model_providers.proxy
]
name =
"OpenAI using LLM proxy"
Display name
base_url =
"http://proxy.example.com"
env_key =
"OPENAI_API_KEY"
Read the secret from an environment variable
[
model_providers.local_ollama
]
name =
"Ollama"
base_url =
"http://localhost:11434/v1"
[
model_providers.mistral
]
name =
"Mistral"
base_url =
"https://api.mistral.ai/v1"
env_key =
"MISTRAL_API_KEY"
Add HTTP headers
Some proxies require extra headers (such as tenant identifiers or feature flags):
Example
[
model_providers.example
]
Static header: included with every request
http_headers =
{
"X-Example-Header"
=
"example-value"
}
Dynamic header: value read from an environment variable
env_http_headers =
{
"X-Example-Features"
=
"EXAMPLE_FEATURES"
}
Command-backed Auth
When a provider's bearer token needs to be fetched dynamically from an external credential helper, use [model_providers.
Example
[
model_providers.proxy
]
name =
"OpenAI using LLM proxy"
base_url =
"https://proxy.example.com/v1"
wire_api =
"responses"
Use the Responses API protocol
[
model_providers.proxy.auth
]
command
=
"/usr/local/bin/fetch-codex-token"
args =
[
"--audience"
,
"codex"
]
timeout_ms =
5000
Single fetch timeout
refresh_interval_ms =
300000
Proactive refresh interval (5 minutes)
Runtime constraints for the auth command:
- It does not accept stdin; the token must be output to stdout
- Codex automatically trims leading/trailing whitespace; an empty token is treated as an error
- Setting refresh_interval_ms = 0 means refresh only after authentication failure
- Cannot be used together with env_key, experimental_bearer_token, or requires_openai_auth
Amazon Bedrock built-in provider
Codex includes a built-in amazon-bedrock provider that can be referenced directly via model_provider:
Example
File path: ~/.codex/config.toml
model_provider =
"amazon-bedrock"
model =
"
[
model_providers.amazon-bedrock.aws
]
profile =
"default"
AWS profile; if omitted, the standard credential chain is used
region =
"eu-central-1"
Bedrock region
The Bedrock built-in provider only supports nesting .aws profile and region overrides under ; other custom settings should use the standard model_providers.
flow.
OSS local mode
Codex supports connecting to local "open-source" models (such as Ollama and LM Studio) via --oss.
If you pass only --oss without specifying a provider, Codex reads oss_provider to choose the default:
Example
File path: ~/.codex/config.toml
Default local provider; choose ollama or lmstudio
oss_provider =
"ollama"
Usage example:
Example
Use the default oss_provider (ollama)
codex
--oss
Explicitly specify lmstudio for this session
codex
--oss
--oss-provider
lmstudio
Azure provider and fine-tuning
Azure OpenAI integration example demonstrating request-level parameters and retry strategies:
Example
File path: ~/.codex/config.toml
[
model_providers.azure
]
name =
"Azure"
base_url =
"https://YOUR_PROJECT_NAME.openai.azure.com/openai"
env_key =
"AZURE_OPENAI_API_KEY"
Read the key from an environment variable
query_params =
{
api-version =
"2025-04-01-preview"
}
wire_api =
"responses"
Use the Responses API protocol
request_max_retries =
4
Number of retries for normal requests
stream_max_retries =
10
Number of retries for streaming requests
stream_idle_timeout_ms =
300000
Streaming idle timeout (5 minutes)
When you need to modify the base URL of the built-in openai provider, use openai_base_url and do not create [model_providers.openai].
ChatGPT data residency projects
ChatGPT projects with Data Residency enabled need to use a base URL with a region prefix:
Example
File path: ~/.codex/config.toml
model_provider =
"openaidr"
[
model_providers.openaidr
]
name =
"OpenAI Data Residency"
Replace "us" with the prefix required by the data residency documentation (such as eu, jp, etc.)
base_url =
"https://us.api.openai.com/v1"
Not all models support data residency; before choosing, consult the "eligible models" list in the OpenAI data residency documentation.
Model reasoning, verbosity, and context
The four most commonly used controls for model behavior:
Example
File path: ~/.codex/config.toml
model_reasoning_summary =
"none"
Disable the reasoning summary
model_verbosity =
"low"
Shorten response length
model_supports_reasoning_summaries =
true
Force the model to output reasoning
model_context_window =
128000
Override the context window size
Among these, model_verbosity takes effect only on providers using the Responses API; Chat Completions providers ignore this setting.
Approval policy and sandbox mode
approval_policy controls when Codex stops to request human confirmation, and sandbox_mode controls which files and networks it can access.
The two dimensions combine independently; here is a typical configuration:
Example
File path: ~/.codex/config.toml
approval_policy =
"untrusted"
Other options: on-request, never, or { granular = { ... } }
approvals_reviewer =
"user"
"auto_review" uses automatic review
sandbox_mode =
"workspace-write"
allow_login_shell =
false
Disable the login shell (hardening measure)
Fine-grained approval policy example (by prompt category)
approval_policy = { granular = {
sandbox_approval = true,
rules = true,
mcp_elicitations = true,
request_permissions = false, # permission-request class fails closed directly
skill_approval = false # skill script class fails closed directly
} }
[
sandbox_workspace_write
]
exclude_tmpdir_env_var =
false
Allow writes to $TMPDIR
exclude_slash_tmp =
false
Allow writes to /tmp
writable_roots =
[
"/Users/YOU/.pyenv/shims"
]
Additional writable directories
network_access =
false
Deny external network by default
[
auto_review
]
policy =
""
"
Use your organization's automatic review policy.
"
""
]
Quick reference for common combinations
| Scenario | approval_policy | sandbox_mode | Description |
|---|---|---|---|
| Daily local development | on-request | workspace-write | Prompt before every tool call, most secure |
| CI automation | never | workspace-write | No human intervention; must be tested in a sandbox |
| Fully trusted environment | never | danger-full-access | Disable the sandbox; use only in isolated environments |
| Strict audit scenarios | untrusted | workspace-write | All write operations require secondary confirmation |
Disable the sandbox (use with caution)
When your environment already provides process-level isolation, you can disable the Codex sandbox:
Example
File path: ~/.codex/config.toml
sandbox_mode =
"danger-full-access"
in workspace-write In this mode, some environments will keep .git/ The difference between .codex/ read-only. This means git commit commands such as these still require approval when executed outside the sandbox. To commit directly inside the sandbox, use rules explicit permission.
Shell environment variable policy
shell_environment_policy controls which environment variables are passed through when Codex starts subprocesses. The default goal is "leak fewer secrets + preserve paths needed for the task".
Example
File path: ~/.codex/config.toml
[
shell_environment_policy
]
inherit =
"none"
Clean start (recommended)
set
=
{
PATH =
"/usr/bin"
, MY_FLAG =
"1"
}
Explicitly set variables
ignore_default_excludes =
false
Keep the default KEY/SECRET/TOKEN filtering
exclude =
[
"AWS_*"
,
"AZURE_*"
]
Then additionally exclude variables matching the globs
include_only =
[
"PATH"
,
"HOME"
]
Pass through only the whitelist (overrides exclude)
Pattern syntax: case-insensitive globs, * matches any characters, ? matches a single character, [A-Z] is a character class.
ignore_default_excludes = false keeps Codex's built-in KEY/SECRET/TOKEN filters, which take effect before include/exclude.
MCP servers
MCP (Model Context Protocol) servers let Codex connect to external tool sets.
For complete MCP configuration details, see the official MCP documentation; they are not covered here. Common patterns:
Example
File path: ~/.codex/config.toml
[
mcp_servers.context7
]
command
=
"npx"
args =
[
"-y"
,
"@upstash/context7-mcp"
]
enabled =
true
Temporarily disable an MCP server with --config
codex --config mcp_servers.context7.enabled=false
Observability and telemetry (OTel)
Codex supports exporting runtime logs via OpenTelemetry, disabled by default. To enable:
Example
File path: ~/.codex/config.toml
[
otel
]
environment =
"staging"
default dev
exporter =
"none"
options: otlp-http or otlp-grpc
log_user_prompt =
false
Do not export user prompt content (recommended)
Select the HTTP exporter
Example
[
otel
]
exporter =
{
otlp-http =
{
endpoint =
"https://otel.example.com/v1/logs"
,
protocol =
"binary"
,
headers =
{
"x-otlp-api-key"
=
"${OTLP_TOKEN}"
}
}
}
Select the gRPC exporter
Example
[
otel
]
exporter =
{
otlp-grpc =
{
endpoint =
"https://otel.example.com:4317"
,
headers =
{
"x-otlp-meta"
=
"abc123"
}
}
}
Exported event types
Codex emits structured events, including but not limited to:
| Events | Meaning |
|---|---|
| codex.conversation_starts | Model, reasoning settings, sandbox/approval policies |
| codex.api_request | API request attempts, status, duration, errors |
| codex.sse_event | SSE stream events, token counts (at response.completed) |
| codex.websocket_request、codex.websocket_event | WebSocket requests and messages |
| codex.user_prompt | User prompt length; content redacted by default |
| codex.tool_decision | Tool call decisions: approved/rejected, whether the source is config or user |
| codex.tool_result | Tool execution duration, success status, output snippets |
When exporter = "none", Codex still records events in memory but does not send them. Even when disabled, async batching is still triggered by events, with a flush on process exit.
Anonymous metrics (enabled by default)
By default, Codex periodically reports a small amount of anonymous usage and health data to detect anomalies. No PII is included.
To disable completely:
Example
File path: ~/.codex/config.toml
[
analytics
]
enabled =
false
Hiding and showing reasoning events
In CI logs, reasoning output can be "noisy" and can be disabled globally:
Example
File path: ~/.codex/config.toml
hide_agent_reasoning =
true
Conversely, when you need to see the model's raw reasoning content:
Example
File path: ~/.codex/config.toml
show_raw_agent_reasoning =
true
Only enable this after confirming your workflow allows exposing raw reasoning. Some models (such as gpt-oss) do not output raw reasoning at all, in which case this setting has no effect.
External notifications (notify)
When Codex completes a turn, it can trigger an external script to implement desktop notifications, chat webhooks, CI status updates, and more.
Example
File path: ~/.codex/config.toml
notify =
[
"python3"
,
"/path/to/notify.py"
]
The script receives a JSON argument with common fields:
| Field | Meaning |
|---|---|
| type | currently only agent-turn-complete |
| thread-id | Session ID |
| turn-id | Turn ID |
| cwd | Working directory |
| input-messages | List of user messages |
| last-assistant-message | The last assistant message |
A simple example script that calls terminal-notifier:
Example
File path: /path/to/notify.py
#!/usr/bin/env python3
import
json
,
subprocess
,
sys
def
main
(
)
int
:
notification
=
json.
loads
(
sys
.
argv
[
1
]
)
Only handle turn-completion events
if
notification.
get
(
"type"
)
!=
"agent-turn-complete"
:
return
0
title
=
f
"Codex: {notification.get('last-assistant-message', 'Turn Complete!')}"
message
=
" "
.
join
(
notification.
get
(
"input-messages"
,
[
]
)
)
subprocess
.
check_output
(
[
"terminal-notifier"
,
"-title"
,
title
,
"-message"
,
message
,
"-group"
,
"codex-"
- notification.
get
(
"thread-id"
,
""
)
,
"-activate"
,
"com.googlecode.iterm2"
,
]
)
return
0
if
name
==
"main"
:
sys
.
exit
(
main
(
)
)
The difference between notify and tui.notifications
| Mechanism | Suitable scenarios | Key configuration |
|---|---|---|
| notify | webhooks, desktop notifications, CI hooks | External programs |
| tui.notifications | Built-in TUI notifications | Supports filtering by event type |
| tui.notification_method | Terminal notification methods | auto / osc9 / bel |
| tui.notification_condition | Trigger conditions | unfocused / always |
In auto mode, Codex prefers the OSC 9 terminal escape sequence, which some terminals treat as a desktop notification; if unsupported, it falls back to BEL (\x07).
Feedback and history
Disable feedback collection
By default, Codex provides the /feedback command in the TUI. To disable it:
Example
File path: ~/.codex/config.toml
[
feedback
]
enabled =
false
Once disabled, /feedback shows a disabled message and Codex refuses to submit feedback.
History (history.jsonl)
By default, Codex writes local session transcripts to ~/.codex/history.jsonl. To disable:
Example
File path: ~/.codex/config.toml
[
history
]
persistence =
"none"
Limit file size (when exceeded, discard the oldest entries and compact):
Example
File path: ~/.codex/config.toml
[
history
]
max_bytes =
104857600
100 MiB
Clickable citations
When supported by the terminal or editor, Codex can render file references as clickable links.
Example
File path: ~/.codex/config.toml
Options: vscode, cursor, windsurf, vscode-insiders, none
file_opener =
"vscode"
Once set, a reference like /home/runoob/project/main.py:42 is rewritten as vscode://file/.../main.py:42, which you can click to jump to in VS Code.
Project instruction discovery (AGENTS.md)
Codex reads AGENTS.md (and related files), automatically bringing project conventions into the "first turn" of the session.
Two core knobs:
| Configuration key | Purpose | Typical Value |
|---|---|---|
| project_doc_max_bytes | Maximum number of bytes to read from each AGENTS.md | About 32 KiB by default |
| project_doc_fallback_filenames | Fallback filename when AGENTS.md is missing | such as CLAUDE.md |
Terminal user interface (TUI) options
Running codex without a subcommand enters the interactive TUI. Common keys under the [tui] table:
| Key | Purpose | Optional values |
|---|---|---|
| tui.notifications | Enable/disable TUI notifications, optionally filtered by event type | Boolean / array of event types |
| tui.notification_method | Terminal notification methods | auto、osc9、bel |
| tui.notification_condition | Trigger conditions | unfocused、always |
| tui.animations | ASCII animation and shimmer effects | true / false |
| tui.alternate_screen | Whether to use the alternate screen (set to never to preserve scrollback history) | auto、always、never |
| tui.show_tooltips | Whether to show beginner tips on the welcome screen | true / false |
Common configuration quick reference
Treat this section as a "look it up when you forget" cheat sheet:
| Requirements | Configuration location / command |
|---|---|
| Switching models | --model gpt-5.4 or model = "..." |
| Scenario-based configuration | --profile
|
| Temporarily change any field | --config key=value (TOML syntax) |
| Change the OpenAI endpoint | openai_base_url |
| Connect to a proxy or self-hosted provider | [model_providers. |
| Local Ollama | --oss + oss_provider |
| Disable the sandbox (use with caution) | sandbox_mode = "danger-full-access" |
| Disable anonymous metrics | [analytics] enabled = false |
| Disable history | [history] persistence = "none" |
| Disable feedback | [feedback] enabled = false |
| Desktop notifications | notify = ["python3", "/path/to/notify.py"] |
Common questions
model_provider set in project-level config not taking effect?
For security reasons, sensitive keys such as model_provider, model_providers, profile, and notify are ignored in project-level .codex/config.toml, and a warning is printed at startup.
Simply move these keys to the user-level ~/.codex/config.toml.
Wrote --config but nothing changed?
Check three things: whether the value follows TOML syntax (arrays use [], strings use "", nesting uses dots); whether the shell split multiple values on spaces; and whether the key name is spelled correctly. Open the latest log under ~/.codex/logs/ to see the raw string that failed to parse.
Still the default model after launching a Profile?
Most common cause: the Profile file still uses the old [profiles.
After disabling the sandbox, does git commit still require approval?
Disabling sandbox_mode does not affect the approval policy. Commands like git commit may still trigger a prompt because of approval_policy = "on-request"; for fully automatic commits, you need to also set the approval policy to never.
Can custom models select the gpt-5 series?
It depends on whether the service pointed to by base_url supports it. Codex itself does not strictly validate the model field; the key is that your provider can recognize and respond to it.