23| When | Hooks |23| When | Hooks |
24| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |24| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
25| During a turn | `PreToolUse`, `PermissionRequest`, `PostToolUse`, `PreCompact`, `PostCompact`, `UserPromptSubmit`, `SubagentStop`, `Stop` |25| During a turn | `PreToolUse`, `PermissionRequest`, `PostToolUse`, `PreCompact`, `PostCompact`, `UserPromptSubmit`, `SubagentStop`, `Stop` |
26| When you interrupt an active turn | `Interrupt` (doesn't run for subagents) |
26| When a session or subagent starts | `SessionStart`, `SubagentStart` |27| When a session or subagent starts | `SessionStart`, `SubagentStart` |
27| When the main thread ends | `SessionEnd` (doesn't run for subagents) |28| When the main thread ends | `SessionEnd` (doesn't run for subagents) |
28 29
180 doesn't change which hooks run.181 doesn't change which hooks run.
181- `timeout` is in seconds.182- `timeout` is in seconds.
182- If `timeout` is omitted, Codex uses `600` seconds for most hooks.183- If `timeout` is omitted, Codex uses `600` seconds for most hooks.
183 - `SessionEnd` uses `1` second by default and supports up to `3` seconds.184 - `SessionEnd` and `Interrupt` use `1` second by default and support up to `3` seconds.
184- `statusMessage` is optional.185- `statusMessage` is optional.
185- `additionalContextLimit` sets how much `additionalContext` a command hook can186- `additionalContextLimit` sets how much `additionalContext` a command hook can
186 send to the model before Codex saves the full text to disk and sends a shorter187 send to the model before Codex saves the full text to disk and sends a shorter
420| `SubagentStop` | subagent type | Values depend on the subagent that stops |421| `SubagentStop` | subagent type | Values depend on the subagent that stops |
421| `UserPromptSubmit` | not supported | Any configured `matcher` is ignored for this event |422| `UserPromptSubmit` | not supported | Any configured `matcher` is ignored for this event |
422| `Stop` | not supported | Any configured `matcher` is ignored for this event |423| `Stop` | not supported | Any configured `matcher` is ignored for this event |
424| `Interrupt` | not supported | Any configured `matcher` is ignored for this event |
423 425
424\*For `apply_patch`, `matcher` values can also use `Edit` or `Write`.426\*For `apply_patch`, `matcher` values can also use `Edit` or `Write`.
425 427
473event-specific tables.475event-specific tables.
474 476
475`SessionStart`, `PreToolUse`, `PermissionRequest`, `PostToolUse`,477`SessionStart`, `PreToolUse`, `PermissionRequest`, `PostToolUse`,
476`UserPromptSubmit`, `SubagentStart`, `SubagentStop`, and `Stop` also include478`UserPromptSubmit`, `SubagentStart`, `SubagentStop`, `Stop`, and `Interrupt` also include
477`permission_mode`, which describes the current permission mode as `default`,479`permission_mode`, which describes the current permission mode as `default`,
478`acceptEdits`, `plan`, `dontAsk`, or `bypassPermissions`.480`acceptEdits`, `plan`, `dontAsk`, or `bypassPermissions`.
479 481
602Background hooks use the same input, matcher, trust review, timeout, and604Background hooks use the same input, matcher, trust review, timeout, and
603[large-output handling](#large-hook-output) as synchronous command hooks. As605[large-output handling](#large-hook-output) as synchronous command hooks. As
604with other command hooks, `timeout` is measured in seconds and defaults to606with other command hooks, `timeout` is measured in seconds and defaults to
605`600`.607`600`. `Interrupt` hooks use a one-second default and a three-second maximum,
608including when they run in the background.
606 609
607### How background hooks run610### How background hooks run
608 611
1086If any matching `Stop` hook returns `continue: false`, that takes precedence1089If any matching `Stop` hook returns `continue: false`, that takes precedence
1087over continuation decisions from other matching `Stop` hooks.1090over continuation decisions from other matching `Stop` hooks.
1088 1091
1092### Interrupt
1093
1094`Interrupt` runs when you interrupt an active turn on the main thread. Use it
1095to record the interruption or clean up work started by a hook. It doesn't run
1096for idle threads or subagents, and any configured `matcher` is ignored.
1097
1098In addition to [Common input fields](#common-input-fields), the event includes
1099`turn_id`, the interrupted turn's id, and `permission_mode`.
1100
1101Command hooks default to a one-second timeout. Configured timeouts are
1102limited to one through three seconds. Hook output can't prevent the
1103interruption or restart the turn. Exit `0` with no output, or return JSON with
1104an optional `systemMessage` to surface a warning. Plain text output is invalid
1105for this event.
1106
1107```json
1108{ "systemMessage": "Saved the interrupted turn to the local audit log." }
1109```
1110
1089## Schemas1111## Schemas
1090 1112
1091The linked `main` branch schemas may include hook fields that are not in the1113The linked `main` branch schemas may include hook fields that are not in the