Codex
Fix each file Codex patches, and the files it patched when a turn ends.
Codex runs a hook only after you trust it with /hooks, and a project hook also needs the project
trusted. An untrusted hook is skipped without a warning, and editing its entry makes it untrusted
again. If your hooks.json already has a hooks object, add these entries to it.
stanza hook runs as two Codex hooks: PostToolUse on apply_patch, and Stop. Put this in ~/.codex/hooks.json for every repository, or in .codex/hooks.json at the root of one:
{
"hooks": {
"PostToolUse": [
{ "matcher": "apply_patch", "hooks": [{ "type": "command", "command": "stanza hook" }] }
],
"Stop": [{ "hooks": [{ "type": "command", "command": "stanza hook" }] }]
}
}On Patch
After apply_patch lands, Stanza runs one --fix pass over the files the patch added, updated or moved. When that changes a file, Codex is told to read it again before editing it. A patch that failed gets no pass.
On Stop
When Codex ends its turn, Stanza reads the session rollout and runs one --fix pass over the changed files Codex patched this session. Files you edited by hand stay untouched. If Stanza does not recognise the rollout, or the rollout names no patched file yet, it falls back to every changed file in the repository. If findings remain that --fix cannot apply, the turn does not end: Codex gets the findings with a line per rule explaining it, fixes them, and replies again.
Flags
--braces, --no-braces and --hunks go in the command, as in stanza hook --hunks. In a repository whose existing code does not follow the rules yet, see Existing Codebases.
Hook Protocol has the full input, output and exit status.