# The Claude Code PostToolUse hook: what it is and how to use it

> PostToolUse 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.

Canonical: https://herdbell.com/blog/claude-code-posttooluse-hook
Author: Herdbell team
Published: 2026-11-12
Last updated: 2026-11-12

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

1. Open `~/.claude/settings.json` for every project, or `.claude/settings.json` inside one project.
2. Under `hooks`, add a `PostToolUse` entry.
3. Give it a `matcher`, the tool names it applies to. `Edit|Write` matches file edits, `Bash` matches shell commands, and an empty matcher matches every tool.
4. Give it a hook of type `command` with the command to run.
5. 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 `decision` of `block` and a `reason`, 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](https://herdbell.com/blog/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.

## Related
- [Herdbell: pricing](https://herdbell.com/#pricing)
- [All posts](https://herdbell.com/blog)
- [Claude Code hooks, explained: what they are and what you can build](https://herdbell.com/blog/claude-code-hooks-explained)
- [How to approve Claude Code permissions without switching windows](https://herdbell.com/blog/approve-claude-code-permissions)
- [How to get notified when Claude Code finishes or needs your approval](https://herdbell.com/blog/get-notified-when-claude-code-finishes)
- [AI coding agent safety checklist: 10 rules before you let it run commands](https://herdbell.com/blog/ai-coding-agent-safety-checklist)
