# Codex hooks and config.toml: events, examples and trust

Source: https://www.ac-bridge.com/guides/codex-hooks

Last updated 4 December 2026

**The short answer**

OpenAI Codex CLI stores its settings in `~/.codex/config.toml` (including `tui.notifications`, `notify`, `approval_policy` and `[mcp_servers]`) and runs lifecycle hooks from `~/.codex/hooks.json` (or inline `[[hooks.<Event>]]` tables in `config.toml`). New or edited hooks are skipped until you start Codex and trust them once with `/hooks`.

## How config.toml is structured

Most confusion around `~/.codex/config.toml` comes from TOML table ordering: top-level keys such as `approval_policy` and `notify` must appear *before* the first `[table]` header, or TOML attaches them to that table and Codex ignores them.

~/.codex/config.toml

```toml
# Top-level keys MUST come before any [table] header.
approval_policy = "on-request"
notify = ["python3", "/path/to/on_turn_complete.py"]

[tui]
notifications = true
notification_method = "auto"
notification_condition = "unfocused"

[features]
hooks = true

[mcp_servers.example]
command = "node"
args = ["/path/to/server.mjs"]
```

### Top-level keys: approval_policy and notify

- `approval_policy` controls when Codex asks before running commands (for example `"untrusted"`, `"on-request"` or `"never"`).
- `notify` runs one program on `agent-turn-complete` only, passing the event's JSON payload as one final CLI argument. It works in your user config only and is ignored in project configs.
- Keep `notify` above `[tui]` and `[features]` so TOML keeps it at the root level. See the [Codex config docs](https://learn.chatgpt.com/docs/config-file/config-advanced) for the full key list.

### Tables: \[tui\], \[features\] and \[mcp_servers\]

- `[tui]` sets built-in terminal alerts: `tui.notifications` (on by default), `notification_method` and `notification_condition` (default `"unfocused"`).
- `[features]` includes `hooks` (set `hooks = false` to turn hooks off globally without deleting `hooks.json`).
- `[mcp_servers.<name>]` registers local MCP servers with `command`, `args`, optional `env` and per-tool `approval_mode` rows.

- **Built-in terminal alerts:** set `tui.notifications` and `notification_condition` in `[tui]`.
- **Finished-turn script:** set top-level `notify` when you only need `agent-turn-complete`.
- **Approval and stop hooks:** wire `Stop` and `PermissionRequest` in `~/.codex/hooks.json`.
- **Tool lifecycle checks:** inspect or log tool runs with `PreToolUse` and `PostToolUse`.
- **Local MCP servers:** register tools cleanly under `[mcp_servers.<name>]` without hand-wrapping shells.

## Codex hooks.json events and lifecycle

Unlike `notify` (which only sees finished turns), Codex lifecycle hooks in `~/.codex/hooks.json` run across the session, including approval prompts and tool calls. See the [Codex hooks documentation](https://learn.chatgpt.com/docs/hooks) for the official schema.

| Event | When it fires | What to watch for |
| --- | --- | --- |
| `Stop` | Codex finishes a turn and hands control back. | Expects empty stdout or JSON on exit 0; redirect command output to `/dev/null`. |
| `PermissionRequest` | Codex pauses to ask approval for a command or escalation. | Runs only when approval is needed; a quiet notifier should use `"async": true` and print nothing. |
| `PreToolUse` | Right before Codex invokes a tool. | Keep synchronous guards fast so every tool call does not stall. |
| `PostToolUse` | Right after a tool call completes. | Good for background logging or linters; use `"async": true` if the agent does not need the output. |
| `SessionEnd` | The Codex session exits. | Useful for cleanup scripts; Codex has no separate needs-input hook event. |

### hooks.json vs inline config.toml

You can keep hooks in `~/.codex/hooks.json` or declare them inline as `[[hooks.Stop]]` tables in `~/.codex/config.toml`. Keep to one file per layer: if the same layer defines hooks in both places, Codex merges them and prints a warning.

### Async and cross-platform overrides

Set `"async": true` on notification hooks so they run in the background (up to eight concurrent background hooks per session) and cannot block or rewrite tool approvals. Add `"commandWindows"` (or `command_windows` in TOML) beside `command` when sharing one config across macOS, Linux and Windows.

## Trusting new or edited hooks with /hooks

Codex does not run an untrusted user hook automatically. Every new or modified hook definition goes through a one-time review step before it fires.

1. **Save your hook file.** Write your JSON to `~/.codex/hooks.json` (or inline tables in `~/.codex/config.toml`).
2. **Start Codex and watch for the review notice.** Codex prints a startup warning whenever a hook definition is waiting for review and skips it until trusted.
3. **Run `/hooks` and approve it.** Type `/hooks` inside Codex, inspect each command and trust it. If you edit the command string later, open `/hooks` again to re-trust the updated definition.

## Copy-pasteable quiet notification hooks

Every example below uses `"async": true` and suppresses stdout so `Stop` never sees plain text and `PermissionRequest` can never accidentally return an approval decision. For built-in terminal alerts, sounds and phone push, see the [Codex notifications guide](https://www.ac-bridge.com/guides/codex-notifications).

### macOS: desktop alert on Stop and PermissionRequest

~/.codex/hooks.json

```json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "osascript -e 'display notification \"Finished\" with title \"Codex\" sound name \"Glass\"' >/dev/null 2>&1",
            "async": true
          }
        ]
      }
    ],
    "PermissionRequest": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "osascript -e 'display notification \"Needs approval\" with title \"Codex\" sound name \"Funk\"' >/dev/null 2>&1",
            "async": true
          }
        ]
      }
    ]
  }
}
```

### Linux: notify-send on Stop and PermissionRequest

~/.codex/hooks.json

```json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "notify-send 'Codex' 'Finished' >/dev/null 2>&1",
            "async": true
          }
        ]
      }
    ],
    "PermissionRequest": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "notify-send -u critical 'Codex' 'Needs approval' >/dev/null 2>&1",
            "async": true
          }
        ]
      }
    ]
  }
}
```

### Windows: PowerShell toast via commandWindows

Install [BurntToast](https://github.com/Windos/BurntToast) once with `Install-Module -Name BurntToast -Scope CurrentUser`, then add `commandWindows` beside `command`.

~/.codex/hooks.json

```json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "notify-send 'Codex' 'Finished' >/dev/null 2>&1",
            "commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"New-BurntToastNotification -Text 'Codex', 'Finished'\"",
            "async": true
          }
        ]
      }
    ],
    "PermissionRequest": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "notify-send 'Codex' 'Needs approval' >/dev/null 2>&1",
            "commandWindows": "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"New-BurntToastNotification -Text 'Codex', 'Needs approval'\"",
            "async": true
          }
        ]
      }
    ]
  }
}
```

## Questions people ask

### Does Codex have hooks like Claude Code?

Yes. Codex CLI supports lifecycle hooks in `~/.codex/hooks.json` (including `Stop`, `PermissionRequest`, `PreToolUse` and `PostToolUse`) alongside `notify` in `~/.codex/config.toml`. The main differences are that Codex requires trusting new or edited hooks via `/hooks` and has no separate needs-input event. See the [Claude Code hooks reference](https://www.ac-bridge.com/guides/claude-code-hooks) to compare both schemas.

### What are hooks in Codex?

Hooks in Codex are deterministic shell commands attached to session lifecycle events so notifications, checks or logging run automatically whenever Codex finishes a turn, asks for permission or runs a tool, without depending on the model to remember extra instructions.

### Should I put hooks in hooks.json or config.toml?

Use `~/.codex/hooks.json` if you want clean separation from general settings or shared tools that merge JSON entries. Use inline `[[hooks.<Event>]]` in `config.toml` if you prefer one file, but avoid putting hooks in both files at the same layer.

### Why did my Codex hook not run after I edited it?

Codex hashes each non-managed hook definition. Any edit to the command string puts it back into pending review until you open `/hooks` inside Codex and trust the updated entry. Also check that `[features] hooks` is not set to `false` in `~/.codex/config.toml`.

## Or let a light show it

Desktop toasts need you looking at the screen and audio chimes need you at the desk. A smart light in your room shows whether Codex is working, waiting for permission or finished at a glance, with no hook JSON to maintain by hand.

**What it does**

AC Bridge turns the smart lights and plugs you already own (Philips Hue, LIFX, Govee, WiZ, Home Assistant and more) into a status light for Codex and Claude Code. On Codex, setup merges its entries into `~/.codex/hooks.json` while keeping your own hooks intact; type `/hooks` once inside Codex to trust them.

**What it follows**

On Codex, needs permission follows `PermissionRequest` and finished follows `Stop`. Codex drives 19 of the 29 agent states (there is no needs-input state in Codex). Because Codex runs every matching hook concurrently, your own scripts keep running beside it. See [how the Claude Code status light works](https://www.ac-bridge.com/claude-code-status-light) and the [Claude Code and Codex notifications guide](https://www.ac-bridge.com/guides/ai-coding-agent-notifications).

**What it costs**

AC Bridge is free to use: one Claude Code profile and one Codex profile, each lighting one device on one repo at a time, with as many devices as you like switched on or off from the app. Pro is GBP 12.99 once, not a subscription: as many profiles as you want for each agent, several devices in a profile, profiles on every repo at once, and your agent can control your devices. It works with the Claude Code or Codex you already run, on Windows, macOS or Linux, with no model API key to buy.

**What it collects**

LAN devices are driven straight from your machine and their keys never leave it; your account, settings, device list, usage counts and session states sync through our servers. Your prompts, code and session transcripts are never collected. [Privacy policy](https://www.ac-bridge.com/privacy#what-we-collect).

**Try it on your own lights**

Turn the lights you already own into a status light for Claude Code and Codex, and see from across the room when a session needs you. [Get started free](https://www.ac-bridge.com/register), or read the [setup docs](https://www.ac-bridge.com/docs) first. On Pro, ask Claude Code or Codex in plain English to switch, dim or recolour your lights, plugs and more. [How MCP device control works](https://www.ac-bridge.com/mcp)
