The Claude Code PostToolUse hook: what it is and how to use it
Short answerPostToolUse runs your command right after Claude Code finishes a tool. How to set it up, what data it gets, and how it differs from PreToolUse.
PostToolUse is a Claude Code hook that runs your own command right after a tool finishes, for example after Claude edits a file or runs a shell command. It is the usual place to run a formatter, a linter or a logger. This page is based on how we use hooks in Herdbell, checked in November 2026. Details change between versions, so confirm against the Claude Code documentation.
What PostToolUse does
- When it runs: after a tool call has completed. The file is already written and the command has already run.
- What it can do: react. Format the file, run tests, write a log line, send a notification, or tell Claude that something is wrong.
- What it cannot do: stop or undo the action. To stop an action before it happens, use PreToolUse.
How to set it up
- Open
~/.claude/settings.jsonfor every project, or.claude/settings.jsoninside one project. - Under
hooks, add aPostToolUseentry. - Give it a
matcher, the tool names it applies to.Edit|Writematches file edits,Bashmatches shell commands, and an empty matcher matches every tool. - Give it a hook of type
commandwith the command to run. - Start a new Claude Code session so the change is picked up.
You can also type /hooks inside Claude Code to see and edit hooks without opening the file.
What your command receives
Claude Code sends one JSON object to your command on standard input. The fields people use most:
| Field | What it holds |
|---|---|
| tool_name | The tool that ran, such as Edit, Write or Bash |
| tool_input | What the tool was asked to do, such as the file path or the command |
| tool_response | What the tool returned |
| session_id | The chat this happened in |
| cwd | The folder Claude Code is working in |
Sending something back to Claude
- Exit code 0: everything is fine and Claude carries on.
- Exit code 2: the text your command wrote to standard error is shown to Claude, so it can fix the problem. A failing linter is the classic use.
- JSON output: your command can print JSON with a
decisionofblockand areason, which also sends the reason to Claude.
Keep the command fast. Claude waits for it after every matching tool call, so a slow hook makes every edit slow.
PreToolUse vs PostToolUse
| PreToolUse | PostToolUse | |
|---|---|---|
| Runs | Before the tool | After the tool |
| Can stop the action | Yes | No |
| Sees the result | No | Yes |
| Good for | Blocking risky commands | Formatting, linting, logging |
How Herdbell uses it
Herdbell adds its own small PostToolUse command when you connect Claude Code. It only listens: that is how the chat list shows what each agent just did. Permission answers go through a different hook. For the full list of events, see Claude Code hooks, explained.
Common questions
What is PostToolUse in Claude Code?
A hook that runs your command right after a tool finishes. It receives the tool name, its input and its result, and is mostly used for formatting, linting, logging and notifications.
Can a PostToolUse hook block a tool?
No. The tool has already run. It can only report a problem back to Claude, which then decides what to do next. Use PreToolUse to block an action.
Where do I put a PostToolUse hook?
In the hooks section of ~/.claude/settings.json for all projects, or in .claude/settings.json inside one project.
Why is my PostToolUse hook not running?
The most common reasons are a matcher that does not match the tool name, a settings file with a JSON error, or a session that was started before you saved the change.