Claude Code
Run Stanza on every Claude Code Write and Edit, and at the end of each turn.
Using Codex? See Codex.
If .claude/settings.json already has a hooks object, merge the three entries below into it.
stanza hook runs as three Claude Code hooks: PreToolUse on Write, PostToolUse on Edit and MultiEdit, and Stop. Add all three to .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{ "matcher": "Write", "hooks": [{ "type": "command", "command": "stanza hook" }] }
],
"PostToolUse": [
{ "matcher": "Edit|MultiEdit", "hooks": [{ "type": "command", "command": "stanza hook" }] }
],
"Stop": [{ "hooks": [{ "type": "command", "command": "stanza hook" }] }]
}
}On Write
Before a Write lands, Stanza formats its content, so the file reaches disk already formatted. When that changes anything, the agent is told to read the formatted file before editing it, so its next Edit matches what is on disk.
On Edit
After an Edit or MultiEdit lands, Stanza runs one --fix pass over the file it edited. When that changes the file, the agent is told to read it again before editing it.
On Stop
When the agent ends its turn, Stanza runs one --fix pass over the changed files the agent created or edited, read from the session transcript and the transcripts of its subagents and Workflow agents. Files you left dirty stay untouched.
If the files come out clean, the agent sees nothing. If findings remain that --fix cannot apply, the turn does not end: the agent gets the findings with a line per rule explaining it, fixes them, and replies again. If a file Stanza rewrote still has a finding, the agent is told to read that file again first.
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.
To turn the hooks off for one session, start Claude Code with AGENT_HOOKS=0 in its environment.
Errors
A bad flag or a git failure shows as a notice in Claude Code and never blocks the agent. On Write, the file then lands unformatted. Hook Protocol has the full input, output and exit status of each event.