.claude/settings.local.json fragment:
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|MultiEdit|Write",
"hooks": [
{
"type": "command",
"command": "jq -r '.tool_input.file_path' | xargs bin/save-hook.sh"
}
]
}
]
}
I jumped at this HN post, because Claude Code Opus 4 has this stupid habit of never terminating files with a return.To test a new hook one needs to restart claude. Better to run the actual processing through a script one can continually edit in one session. This script uses formatters on C files and shell scripts, and just fixes missing returns on other files.
As usual claude and other AI is poor at breaking problems into small steps, and makes up ways to do things. The above hook receives a json file, which I first saved to disk, then extracted the file path and saved that to disk, then instead called save-hook.sh on that path. Now we're home after a couple of edits to save-hook.sh
This was all ten minutes. I wasted far more time letting it flail attempting bigger steps at once.