AI
Codex Hooks: Run Scripts in the Agent Lifecycle
What Codex hooks are, when they run, where hooks.json lives, and how you review and trust them before they run.
Last reviewed:
What they are
Hooks are an extensibility framework for Codex that run scripts or MCP tools during the agentic loop. OpenAI lists examples: sending chats to a logging engine, scanning team prompts to block pasted API keys, summarizing chats into persistent memories, a custom check when a turn stops, and custom prompting in a given directory.
When they run
- During a turn: PreToolUse, PermissionRequest, PostToolUse, PreCompact, PostCompact, UserPromptSubmit, SubagentStop and Stop.
- For each model request attempt: PreModelRequest and PostModelRequest.
- When you interrupt a turn: Interrupt (not run for subagents).
- When a session or subagent starts: SessionStart and SubagentStart.
- When the main thread ends: SessionEnd (not run for subagents).
How they run
All matching hooks from multiple files run. Matching command hooks for the same event launch concurrently, so one cannot stop another from starting. If two files register the same command, it can run twice.
Where hooks are defined
- System on macOS and Linux: /etc/codex/hooks.json.
- System on Windows: %ProgramData%\OpenAI\Codex\hooks.json.
- User: $CODEX_HOME/hooks.json, or ~/.codex/hooks.json on macOS and Linux when unset.
- Trusted project: .codex/hooks.json.
- Inline under [hooks] in config.toml also works, but prefer one format per layer.
Review and trust
- Codex lists configured hooks before deciding which can run.
- Review the exact definition and trust it. A new or changed hook is skipped until trusted.
- Use /hooks in the CLI to inspect sources, review new hooks and disable a non-managed one.
- Managed hooks (system, MDM, cloud or requirements.toml) are trusted by policy and cannot be disabled from the user browser.
- --dangerously-bypass-hook-trust runs enabled hooks without persisted trust, for automation that already vets sources outside Codex.
Common mistakes
- Trusting a hook whose script you did not read.
- Registering the same command in two files so it runs twice.
- Using the trust-bypass flag in an ordinary setup. (Our tip)
What we did not cover
This page covers the overview, locations and trust as the official page states them. We did not reproduce per-event input and output schemas, so use the official page for those.
Next steps
- For settings and precedence: config basics.
- For plugins that carry hooks: plugins overview.
Latest updates
No dated update on this topic was found on the official page read on 2026-11-30. We add updates when they appear.
Similar tools
Standalone pages for similar items are added after their official sources are read. We name nothing without a full page.
Related pages
Sources
- OpenAI Developers: Hooks · read on
Wording is ours, from the official source. Images and video belong to their owners and are credited with a link to the official page.