updated codex hooks

This commit is contained in:
Shayan Rais
2026-05-16 23:55:53 +05:00
parent a77e223a6e
commit ac0d87d886
11 changed files with 103 additions and 23 deletions
+44 -12
View File
@@ -3,22 +3,18 @@ Contains all the details, scripts, and instructions for the Codex CLI hooks.
## Hook Events Overview
Codex CLI provides **5 hooks** via hooks.json:
Codex CLI provides **8 hooks** via hooks.json:
| # | Hook | Event Type | Config File | Description |
|:-:|------|------------|-------------|-------------|
| 1 | `SessionStart` | `SessionStart` | `hooks.json` | Runs once at session start — injects context + plays sound |
| 2 | `PreToolUse` | `PreToolUse` | `hooks.json` | Runs before a tool executes — plays sound |
| 3 | `PostToolUse` | `PostToolUse` | `hooks.json` | Runs after a tool completes — plays sound |
| 4 | `Stop` | `stop` | `hooks.json` | Runs when the session ends — plays sound |
| 5 | `UserPromptSubmit` | `UserPromptSubmit` | `hooks.json` | Runs when the user submits a prompt — plays sound |
> Hooks 1 and 4 require **Codex CLI v0.114.0+** with the hooks engine enabled.
> Hooks 2 and 3 require **Codex CLI v0.117.0+** with the hooks engine enabled.
> Hook 5 requires **Codex CLI v0.116.0+** with the hooks engine enabled:
> ```bash
> codex -c features.codex_hooks=true
> ```
| 3 | `PermissionRequest` | `PermissionRequest` | `hooks.json` | Runs when Codex requests approval for a sensitive op — plays sound |
| 4 | `PostToolUse` | `PostToolUse` | `hooks.json` | Runs after a tool completes — plays sound |
| 5 | `Stop` | `stop` | `hooks.json` | Runs when the session ends — plays sound |
| 6 | `UserPromptSubmit` | `UserPromptSubmit` | `hooks.json` | Runs when the user submits a prompt — plays sound |
| 7 | `PreCompact` | `PreCompact` | `hooks.json` | Runs before context compaction — plays sound |
| 8 | `PostCompact` | `PostCompact` | `hooks.json` | Runs after context compaction — plays sound |
### How Hooks Are Called
@@ -26,9 +22,12 @@ All hooks (hooks.json) are called with `--hook` flag:
```
python3 .codex/hooks/scripts/hooks.py --hook SessionStart
python3 .codex/hooks/scripts/hooks.py --hook PreToolUse
python3 .codex/hooks/scripts/hooks.py --hook PermissionRequest
python3 .codex/hooks/scripts/hooks.py --hook PostToolUse
python3 .codex/hooks/scripts/hooks.py --hook Stop
python3 .codex/hooks/scripts/hooks.py --hook UserPromptSubmit
python3 .codex/hooks/scripts/hooks.py --hook PreCompact
python3 .codex/hooks/scripts/hooks.py --hook PostCompact
```
### SessionStart Context Injection
@@ -66,7 +65,7 @@ The hook script automatically detects and uses the appropriate audio player for
There are **two** configuration files:
1. **`.codex/hooks.json`** — Registers `SessionStart`, `PreToolUse`, `PostToolUse`, `Stop`, and `UserPromptSubmit` hooks
1. **`.codex/hooks.json`** — Registers `SessionStart`, `PreToolUse`, `PermissionRequest`, `PostToolUse`, `Stop`, `UserPromptSubmit`, `PreCompact`, and `PostCompact` hooks
2. **`.codex/hooks/config/hooks-config.json`** — Enable/disable individual hooks and logging
#### hooks.json
@@ -90,6 +89,14 @@ There are **two** configuration files:
"timeout": 10
}
],
"PermissionRequest": [
{
"type": "shell",
"command": "python3 .codex/hooks/scripts/hooks.py --hook PermissionRequest",
"statusMessage": "Running permission request hook...",
"timeout": 10
}
],
"PostToolUse": [
{
"type": "shell",
@@ -113,6 +120,22 @@ There are **two** configuration files:
"statusMessage": "Running user prompt submit hook...",
"timeout": 10
}
],
"PreCompact": [
{
"type": "shell",
"command": "python3 .codex/hooks/scripts/hooks.py --hook PreCompact",
"statusMessage": "Running pre-compact hook...",
"timeout": 10
}
],
"PostCompact": [
{
"type": "shell",
"command": "python3 .codex/hooks/scripts/hooks.py --hook PostCompact",
"statusMessage": "Running post-compact hook...",
"timeout": 10
}
]
}
}
@@ -127,9 +150,12 @@ Edit `.codex/hooks/config/hooks-config.json`:
{
"disableSessionStartHook": false,
"disablePreToolUseHook": false,
"disablePermissionRequestHook": false,
"disablePostToolUseHook": false,
"disableStopHook": false,
"disableUserPromptSubmitHook": false,
"disablePreCompactHook": false,
"disablePostCompactHook": false,
"disableLogging": true
}
```
@@ -137,9 +163,12 @@ Edit `.codex/hooks/config/hooks-config.json`:
**Configuration Options:**
- `disableSessionStartHook`: Set to `true` to disable the session start context injection and sound
- `disablePreToolUseHook`: Set to `true` to disable the pre-tool-use sound
- `disablePermissionRequestHook`: Set to `true` to disable the permission request sound
- `disablePostToolUseHook`: Set to `true` to disable the post-tool-use sound
- `disableStopHook`: Set to `true` to disable the session stop sound
- `disableUserPromptSubmitHook`: Set to `true` to disable the user prompt submit sound
- `disablePreCompactHook`: Set to `true` to disable the pre-compact sound
- `disablePostCompactHook`: Set to `true` to disable the post-compact sound
- `disableLogging`: Set to `true` to disable logging hook events to `.codex/hooks/logs/hooks-log.jsonl`
### Configuration Fallback
@@ -159,9 +188,12 @@ Create or edit `.codex/hooks/config/hooks-config.local.json` for personal prefer
{
"disableSessionStartHook": false,
"disablePreToolUseHook": false,
"disablePermissionRequestHook": false,
"disablePostToolUseHook": false,
"disableStopHook": true,
"disableUserPromptSubmitHook": false,
"disablePreCompactHook": false,
"disablePostCompactHook": false,
"disableLogging": true
}
```