posttooluse
4 questions
- AI
Which hook event should I use? The full list, ranked.
Claude Code exposes 28 hook events across five categories: lifecycle, tool execution, turn control, agent teams, and context management. Exit code 2 blocks the action on blocking events. Non-blocking events show stderr but cannot prevent what already happened.
- AI
How do I auto-format files after Claude edits them?
A PostToolUse hook on Edit/Write/MultiEdit reads the JSON envelope from stdin, pulls tool_input.file_path with jq, skips generated paths, and swallows formatter stderr so a syntax error during typing never feeds Claude noise.
- AI
How do I run a hook around an MCP tool call without breaking the session?
Match `mcp__<server>__<tool>` on PreToolUse / PostToolUse, return structured JSON for clean permission decisions, and put logging or telemetry hooks in async mode so they never block the session.
- AI
What does a PostToolUse hook actually do for a multi-file edit?
A captured `claude --print` session against the demo app, with a PostToolUse hook (matcher `Edit|Write`) that runs `npm run typecheck` after every edit. The prompt asked for a multi-file change (add `'parking-permit'` to `ServiceType`, update Finnish labels, update Record-typed consumers). Claude completed the work in eight Edits and also fixed a pre-existing `noUncheckedIndexedAccess` typecheck error that the hook flagged on the way through. The article shows the hook config, the actual fix Claude landed, and a real debugging surprise: the events.jsonl does not surface PostToolUse hook firings the same way SessionStart hooks do, which has consequences for how you verify these hooks are working.