Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.
| Moment | Codex CLIHook commands |
|---|---|
| Hook types |
|
| Session and workspace | |
| Session starts | SessionStartadd context, stop |
| Session ends | |
| Prompt and turn | |
| User submits a prompt | UserPromptSubmitblock, add context |
| Turn is interrupted | Interruptobserve only Runs when you interrupt an active turn on the main thread; not for subagents. The matcher is ignored. Can only emit a system message; it cannot prevent or reverse the interruption. |
| Agent finishes its turn | Stopqueue follow-up, stop decision: "block" queues a continuation prompt; continue: false from any hook takes precedence. |
| Tools | |
| Before a tool runs | PreToolUsedeny, modify, add context permissionDecision ask, and allow without updatedInput, fail the hook run; the tool call proceeds. Covers shell, apply_patch, MCP and local function tools, not hosted tools such as web search. 0.166.0: for local `exec_command` calls, the `cwd` in PreToolUse input is the directory the command will run in, not the session directory. PermissionRequest and PostToolUse input also carry the command cwd where known. Hooks still run in the session directory, and commands on a remote executor still report the host cwd. |
| After a tool succeeds | PostToolUsereplace, add context decision: "block" or continue: false replaces the tool result with the feedback and continues; side effects are not undone. Also runs after shell commands that exit non-zero. |
| Permissions and questions | |
| Permission is requested | PermissionRequestallow, deny Any deny wins. updatedInput, updatedPermissions and interrupt fail closed. |
| Subagents | |
| Subagent starts | SubagentStartadd context |
| Subagent finishes | SubagentStopqueue follow-up, stop |
| Context and compaction | |
| Before context is compacted | |
| After context is compacted | |
Notes and sources
Codex CLI
- Matching hooks are launched concurrently, so one hook cannot stop another from starting.
- Project hooks load only in a trusted project, and every non-managed hook must also be reviewed and trusted by its hash.
- Background (async) hooks cannot block, approve or rewrite the triggering operation.
- OpenAI describes tool hooks as a guardrail, not a complete enforcement boundary.
- Since 0.165.0 an execution environment can bring its own managed hooks from its requirements; they are always required, run on that environment's executor and appear as
<environment:ID>/requirements.toml. In 0.166.0, App Serverhooks/listwith athreadIdincludes them and marks each withenvironmentId. The App Server's own environment selection supplies none, so these come only from an environment owner that provides its configuration. - 0.167.0 managed prompt-user checkpoint, traced at 0.167.2: requirements.toml prefix rules can require fresh human approval for every execution attempt. Hooks and automatic review cannot satisfy it; approval cache/rule amendments do not replace it. A never/rejecting approval policy or enforced automatic-only review rejects the command instead. This is a managed-rule decision, not a fourth approval_policy mode. No runtime probe.
- November 16 plugin-format audit at Codex 0.169.0: the local loader parses OpenAI overlay hooks but explicitly skips hook sources for Agent Plugins packages; legacy compatibility packages use the hook loader. Executor-owned inline hooks have a separate cleanup admission policy. This updates the package-loading boundary without redating the older event/handler traces; no runtime probe ran.
- Codex hooks, Documentation, checked 2026-10-15
- Codex CLI 0.162.1 hook event names, Source code, checked 2026-10-14
- Codex CLI 0.162.1 hook output parsing, Source code, checked 2026-10-14
- Codex CLI 0.162.1 hook handler discovery, Source code, checked 2026-10-14
- Codex 0.166.0: codex-rs/core/src/tools/registry.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/core/src/tools/registry.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/hooks/src/events/common.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/hooks/src/events/pre_tool_use.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/hooks/src/events/permission_request.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/hooks/src/events/post_tool_use.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/protocol/src/environment.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/core/src/hook_environment_executor.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/hooks/src/engine/discovery.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/core/src/codex_thread.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/app-server-protocol/src/protocol/v2/plugin.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/app-server-protocol/src/protocol/v2/plugin.rs, Source code, checked 2026-10-30
- Codex 0.166.0: codex-rs/app-server/src/request_processors.rs, Source code, checked 2026-10-30
- codex rust-v0.167.2: codex-rs/core/src/tools/approvals.rs, Source code, checked 2026-11-12
- codex rust-v0.167.2: codex-rs/core/src/tools/approvals.rs, Source code, checked 2026-11-12
- Plugin formats: codex loader, Source code, checked 2026-11-16
- Plugin formats: codex component defaults, Source code, checked 2026-11-16
- Plugin formats: codex executor hooks, Source code, checked 2026-11-16