Skip to content
BENIBIX Learn

PostToolUse Hook

AI⌨️ Claude CodeConfiguration

Also known as PostToolUse, post tool use hook

The event right after a tool works. It is often used to tidy code.

Think of it like

It is like a teacher who checks your work. She does it as soon as you hand it in.

Example

After each edit, Emma's hook runs the linter. When it finds an error, Claude sees the message and fixes it at once.

Why it matters

It catches mistakes the moment they are made, while Claude still has the file in mind.

Definition

PostToolUse is the hook event that fires right after a tool call works. It is the usual place to tidy code, lint it or run a quick test after Claude edits a file. The tool has already run, so the hook cannot undo it. It can send Claude a note to act on. It does that by exiting 2, or with a block decision and a reason.

Example code

json
{
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "npm run lint" }] }
    ]
  }
}
Lint after each edit.
It fires on the way out of each tool call.

Common mistake

Expecting it to fire when a shell command rewrites a file. It matches the tool, not the file. Use FileChanged for that.

Key takeaways

  1. 1
    After success. Tool already ran.
  2. 2
    Format, lint, test. Common uses.
  3. 3
    Exit 2 tells Claude. Cannot undo.

Compare