# PostToolUse Hook

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** PostToolUse, post tool use hook

## Think of it like

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

## 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

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

## Example code

```json
{
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit|Write", "hooks": [{ "type": "command", "command": "npm run lint" }] }
    ]
  }
}
```

Lint after each edit.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [PreToolUse Hook](https://learn.benibix.com/term/ai/pretooluse-hook)
- [PostToolUseFailure Hook](https://learn.benibix.com/term/ai/posttoolusefailure-hook)
- [Claude Code Hook](https://learn.benibix.com/term/ai/claude-code-hook)

## Told apart from

- [PreToolUse vs PostToolUse](https://learn.benibix.com/compare/pretooluse-hook-vs-posttooluse-hook): People think both hooks can stop a bad tool call. Only one can. PreToolUse fires before the tool runs, so it can allow, deny or ask. PostToolUse fires after the tool has run, so the change is already made. It can only tell Claude what went wrong. Guard in the first, check and tidy in the second.
- [FileChanged vs PostToolUse](https://learn.benibix.com/compare/filechanged-hook-vs-posttooluse-hook): People think a PostToolUse hook on Edit sees every change made to a file in the project. It sees only Claude's own tool calls. A script Claude runs, or your own editor, can change the file and it never fires. FileChanged watches the file itself, so it fires whatever wrote it. But only PostToolUse knows which tool call did it.

![The order hook events fire in: a session, each turn, and each tool call inside it.](https://learn.benibix.com/diagrams/hook-lifecycle.svg)

---

Source: https://learn.benibix.com/term/ai/posttooluse-hook
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
