HookStack
All guides

PreToolUse vs PostToolUse: Which Claude Code Hook to Use

5 min read · Reviewed 2026-06-12

PreToolUse and PostToolUse are the two most-used Claude Code hook events — and the difference between them decides whether you can prevent a bad action or only react to it.

This guide explains exactly what each event does, when to reach for which, and gives you a one-line rule for choosing.

What is the difference between PreToolUse and PostToolUse?

PreToolUse runs before a tool executes. It sees the tool input — the command, the file path, the URL — and it can block the action entirely by returning a block decision. Nothing happens until your hook says yes.

PostToolUse runs after the tool has already completed. It can read the result and react — format the file, run a linter, log the command — but it cannot undo what just happened. By the time it runs, the change exists.

When should you use PreToolUse?

Use PreToolUse whenever the goal is prevention: stopping something dangerous, invalid, or out-of-policy before it lands.

  • Block destructive shell commands (rm -rf, force pushes) before they run.
  • Scan a command or a file write for secrets and refuse if one is found.
  • Refuse writes on the main branch until a feature branch exists.
  • Validate that the agent is using the right package manager.

A PreToolUse hook blocks by writing { "decision": "block", "reason": "…" } to stdout. Always give an actionable reason — the model reads it and can correct course.

When should you use PostToolUse?

Use PostToolUse for reactions — anything that should happen in response to a change, not instead of it.

  • Auto-format a file the moment it is written.
  • Run ESLint or type-checking after an edit and surface problems.
  • Type-check the whole batch after a set of parallel edits.
  • Log every Bash command for an audit trail.

PostToolUse hooks are non-blocking: if the tool they rely on is missing, they exit quietly rather than breaking the session.

Can PostToolUse stop a bad change?

No — by the time PostToolUse runs, the change already exists. What it can do is make the problem visible (a failing lint, a type error) so the next step fixes it. If you genuinely need to prevent the action, that is a PreToolUse job.

A simple decision rule

  • Need to prevent or validate an action? → PreToolUse.
  • Need to react to a completed action? → PostToolUse.

The two compose well: a PreToolUse guard stops dangerous writes, while a PostToolUse formatter cleans up the writes that are allowed.

Frequently asked questions

Is PreToolUse a blocking hook?
Yes. PreToolUse can block the tool from running by returning a block decision on stdout; PostToolUse cannot.
Does PostToolUse slow Claude Code down?
It runs after the tool, so keep it fast: filter by file extension before launching an expensive command, and set a timeout. Missing tools fail silently.
Can I use both events together?
Yes, and it is a common combination — PreToolUse to guard, PostToolUse to format and check.

Related hooks

Sources