HerdbellBlog

Guide

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

By the Herdbell team · Published · Updated

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

  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:

FieldWhat it holds
tool_nameThe tool that ran, such as Edit, Write or Bash
tool_inputWhat the tool was asked to do, such as the file path or the command
tool_responseWhat the tool returned
session_idThe chat this happened in
cwdThe 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

PreToolUsePostToolUse
RunsBefore the toolAfter the tool
Can stop the actionYesNo
Sees the resultNoYes
Good forBlocking risky commandsFormatting, 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.