PostToolUse is the default for most “do something after the agent
edits a file” hooks. Pair it with a matcher like Edit|Write to filter
to file mutations.
For the full event list, JSON schemas, return-value semantics, and
advanced configuration, see the Claude Agent SDK hooks
reference. Anything
the SDK supports works in DocWriter.
Matching on tool name
PreToolUse, PostToolUse, and PostToolUseFailure are scoped to a
particular tool. Use the matcher field (a regex, case-insensitive) to
narrow which tools the hook applies to:
For non-tool events (
Stop, UserPromptSubmit, Session*,
Notification), the matcher is ignored.
Common patterns
Rebuild on every edit
Commit at the end of a turn
Lint before the agent writes
PreToolUse hook exits non-zero, the SDK blocks the tool call.
The agent sees the failure and can adapt.