Guide
Codex CLI hooks: notify when a turn ends, and why your hook does nothing
Codex can run a command at the end of a turn, which is enough to pop up a notification when a long task finishes. The catch that costs people an evening: a hook you just wrote does nothing until you trust it, and the only sign is a warning at startup. This guide follows OpenAI's hooks documentation (checked 2 December 2026).
1. The hook
Hooks are enabled by default. Put this in ~/.codex/hooks.json (on Windows, %USERPROFILE%\.codex\hooks.json; if CODEX_HOME is set, in that directory):
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "notify-send 'Codex' 'Codex finished a turn'",
"commandWindows": "powershell.exe -NoProfile -Command \"[console]::beep(800,200)\"",
"timeout": 5
}
]
}
]
}
}
Notes on that file:
commandis for macOS and Linux.notify-sendis Linux and needs a desktop notification daemon. On macOS useosascript -e 'display notification "Codex finished a turn" with title "Codex"'(escape the double quotes inside the JSON string).commandWindowsis an optional Windows-only override. A beep is the dependency-free choice; a corner notification needs a module you install yourself.- Set a
timeoutin seconds. If you leave it out, most hooks get 600 seconds. - Exit 0 with no output counts as success. Codex parses what a hook prints (JSON fields such as
systemMessage), so keep a notifier quiet.
2. Trust it, or it never runs
Before a hook you wrote yourself can run, Codex requires you to review and trust its exact definition. It records trust against the hook's hash, so a new or changed hook is marked for review and skipped until you trust it. If hooks are waiting for review, Codex prints a warning at startup that tells you to open /hooks.
In the CLI, type /hooks. It lists hook sources, shows the ones that need review, and lets you trust them or disable individual hooks. Two consequences follow:
- Every edit to the command, even a changed word in the message, is a new definition and needs trusting again. "It worked, I tweaked it, now it is silent" is this.
- A scripted setup that rewrites the command on every start (to insert a port or an id, say) never stays trusted.
3. The other ways it goes quiet or noisy
- Hooks switched off.
hooks = falseunder[features]inconfig.tomlturns them off. The old keycodex_hooksstill works as a deprecated alias. - Project hooks. A
.codex/hooks.jsonin a project only loads when the project is trusted. User and system hooks can still load in untrusted projects. - Two places, one hook. If a layer has both
hooks.jsonand inline[hooks]inconfig.toml, Codex loads both and warns at startup. If two files register the same command for an event, it can run twice: two notifications per turn. - A relative path. Commands run with the session's working directory, and Codex may be started from a subfolder. For a script in the repository, resolve it from the git root.
4. Which session was it?
Each hook receives one JSON object on stdin, with fields such as session_id, cwd and hook_event_name. A small script can read cwd and put the folder name in the notification. A fixed message tells you that Codex finished, not where, and with four sessions open you still have to look.
Doing it in Paneherd
Paneherd runs Codex in its own pane and listens to the same hook events, Stop and the permission request among them, to show each pane as working, waiting or done in one sidebar and to notify you when a pane needs you. Codex has no per-session settings flag, so Paneherd passes its hooks as -c overrides, and keeps each hook's text identical in every pane so the trust you give it once stays valid. The one-time review in /hooks is still yours to do. The extension is free, with notifications, the optional sound, review, the merge queue and the permission inbox.
Limit: until a Paneherd hook is trusted, Codex skips it, so a pane's status can lag. Treat a Codex pane that never reports its end as "hooks not trusted yet".
Frequently asked questions
Why does my Codex Stop hook never run?
Almost always because it was never trusted. Open /hooks in the CLI and review it. Editing the command resets the trust.
Where does Codex look for hooks?
The user file hooks.json in $CODEX_HOME (~/.codex by default), .codex/hooks.json in a trusted project, and a system file. You can also write hooks inline under [hooks] in config.toml, but keep each hook in one place.
Why two notifications per turn?
The same command is registered in two files, or in hooks.json and config.toml of one layer. Codex can run it twice.