Auto-logging every file Claude edits with a PostToolUse hook, tested live
Instead of asking every time, wire a hook that fires automatically — built & verified live.
Stop asking "format this" every time
A `PostToolUse` hook runs a fixed shell command right after a tool call (like Edit/Write) succeeds — no need to ask in plain language each time.
PostToolUse vs the other hook events
Unlike `PreToolUse` (blocks before execution) or `SessionStart`/`SubagentStop` (session lifecycle, covered in other articles), `PostToolUse` fires after a tool succeeds.
The minimal setup we built and tested
A `PostToolUse` hook matching `Edit|Write`, whose script extracts the edited file path from stdin JSON and appends it to a log:
// .claude/settings.json
{ "hooks": { "PostToolUse": [ { "matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/format-log.sh" }] } ] } }The real result
Asking Claude to create `hello.txt` triggered the hook, and `.claude/format.log` really did gain this line:
[2026-07-29 06:27:16] formatted: <project>/hello.txtSwapping in a real formatter (untested extension)
Replacing the log line with `npx prettier --write "$file"` should work — the file-path extraction is verified, but we didn't test the prettier call itself. Verify in your own setup first.
Scoping to specific extensions
Add a branch checking the file's extension inside the same tested script to narrow what gets processed.