# Codex hooks: events, hooks.json and trust

> Codex hooks run your scripts during the agent loop. See where to configure them, the event names, how trust works and what a hook can block.

Codex has a hooks feature. OpenAI describes it as an extensibility framework that lets you run scripts or MCP tools during the agentic loop. You configure hooks in a `hooks.json` file or in a `[hooks]` table in `config.toml`. Hooks are enabled by default, and Codex skips any hook you have not reviewed and trusted. A `PreToolUse` hook can deny a tool call.

## Where Codex looks for hooks

| Layer | Location |
| --- | --- |
| System | `/etc/codex/hooks.json` on macOS and Linux |
| User | `$CODEX_HOME/hooks.json` (the default `CODEX_HOME` is `~/.codex`) |
| Trusted project | `.codex/hooks.json` |

Each directory can also declare hooks inline under `[hooks]` in `config.toml`. Plugins can bundle hooks, and administrators can declare managed hooks in `requirements.toml`. If one layer uses both formats, Codex loads both and warns. The docs advise one format per layer.

Project hooks load only for trusted projects. The config docs say Codex skips project `.codex/` layers, including config, hooks and rules, when the project is untrusted. User and system layers still load.

## Events

The hooks page lists these event names.

`PreToolUse`, `PermissionRequest`, `PostToolUse`, `PreCompact`, `PostCompact`, `UserPromptSubmit`, `SubagentStop`, `Stop`, `PreModelRequest`, `PostModelRequest`, `Interrupt`, `SessionStart`, `SubagentStart`, `SessionEnd`.

A `matcher` is a regex string. It applies to the tool name for `PreToolUse`, `PostToolUse` and `PermissionRequest`. Leaving it out, or using `*` or an empty string, matches every occurrence. `UserPromptSubmit`, `Stop`, `Interrupt` and the model-request events ignore it.

## What a hook receives and returns

Two handler types work, `command` and `mcp_tool`. The docs say `prompt` and `agent` handlers are parsed but skipped. A command hook receives one JSON object on `stdin` with shared fields such as `session_id`, `transcript_path`, `cwd`, `hook_event_name` and `model`.

Exit code `0` with no output counts as success. A hook can print JSON on `stdout` with fields such as `continue`, `stopReason` and `systemMessage`, and support varies by event. Some events accept exit code `2` with a reason on `stderr`. `PreToolUse` can block a call with `permissionDecision: "deny"`.

Timeouts are in seconds and default to 600 for most hooks. `SessionEnd` and `Interrupt` default to 1 second and allow up to 3. Setting `async` runs a command hook in the background.

## Trust

The docs say non-managed hooks must be reviewed and trusted before they run. Codex records trust against each hook’s current hash, so a new or edited hook is skipped until you trust it again. Use `/hooks` in the CLI to review them. Managed hooks are trusted by policy.

The flag `--dangerously-bypass-hook-trust` runs enabled hooks without persisted trust for one invocation. The installed help for Codex CLI 0.166.0 says it is intended only for automation that already vets hook sources.

To turn hooks off, set this in `config.toml`. The docs say `codex_hooks` still works as a deprecated alias.

```toml
[features]
hooks = false
```

## Hooks are not a sandbox

A hook is a script you wrote, so it checks what you thought to check. It does not replace the sandbox. It also does not cover every path. Treat a `PreToolUse` deny rule as one layer and keep the sandbox and approvals on. See [Codex sandbox](https://www.excellent.so/guides/codex-sandbox).

## The older notify setting

Before hooks, Codex had `notify`, an array in `config.toml` that runs an external program on supported events.

```toml
notify = ["python3", "/path/to/notify.py"]
```

The advanced config docs say the only supported event is `agent-turn-complete`. It notifies you. It cannot block anything.

## Review hooks like code

A hook runs with your account’s access. Read a hook before you trust it, especially one that arrives with a cloned repository or a plugin. Hash-based trust helps, because a changed hook needs a fresh review. For a comparison with the other main agent, see [Claude Code and Codex security controls](https://www.excellent.so/guides/claude-code-codex-security-controls).

Checked against the vendor documentation on November 25, 2026. [Hooks](https://learn.chatgpt.com/docs/hooks) · [Config basics](https://learn.chatgpt.com/docs/config-file/config-basic) · [Advanced config](https://learn.chatgpt.com/docs/config-file/config-advanced) · [Config reference](https://learn.chatgpt.com/docs/config-file/config-reference)

## Checks that sit outside the agent

Excellent Pro adds checks before supported actions. With Codex, an Excellent “ask” refuses the action and tells the agent to ask you. Commands sent into an already running Codex shell fall outside that check. [Agent coverage](https://www.excellent.so/agents) · [Pricing](https://www.excellent.so/pricing). Pro is US-only for now. Excellent’s free scan reads supported logs on the Mac and reports findings for review. [Run the free scan](https://www.excellent.so/scan) · [See a sample report](https://www.excellent.so/r/sample).

Source: https://www.excellent.so/guides/codex-hooks
