PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use PreToolUse when a check must inspect or stop a proposed tool call before it runs. Use PostToolUse when the check needs the result of a successful call or should do follow-up work, such as logging, formatting, or reviewing output. A post-tool hook cannot undo or prevent an operation that has already completed.
How to choose between PreToolUse and PostToolUse
Pick the event according to when the check needs to take effect—not simply what the check is called. Anthropic describes PreToolUse as running before a tool call and PostToolUse as running after a successful call. See the Hooks reference and the hook configuration guide.
| Question | Use PreToolUse | Use PostToolUse |
|---|---|---|
| Must the check stop a proposed operation before it runs? | Yes. Inspect the tool and proposed input, then deny when the policy requires it. | No. The tool has already completed successfully. |
| Does the check need the tool’s returned result? | No; the result is not available yet. | Yes. The callback receives tool_response. |
| Typical work | Validate a planned file path, inspect a command, or intervene in proposed input. | Review output, log a completed call, format or lint after a write, or add context. |
What the Python SDK gives each hook
The Python Agent SDK passes different data depending on the event. Both hook inputs include an event name, tool name, and tool-use ID; subagent identifiers such as agent_id and agent_type are optional.
Recommended Free Tools
PreToolUse: includes the proposedtool_input. Use it to examine what the tool is about to do.PostToolUse: includes the input used andtool_response. Use the response when the check depends on the outcome.
Callbacks are asynchronous and receive (input, tool_use_id, context), returning a hook output. In the Python reference, the documented default timeout is 600 seconds for most events and 30 seconds for UserPromptSubmit; these are reference defaults and may change between SDK versions. Consult the Python Agent SDK reference for the version you use.
#1 Best Overall
Register hooks and match the tools they should handle
In Python, configure hooks through ClaudeAgentOptions.hooks. A HookMatcher lets you limit a callback to matching tool names; for example, match Bash before execution and Write|Edit afterward.
options = ClaudeAgentOptions(
hooks={
"PreToolUse": [
HookMatcher(matcher="Bash", hooks=[validate_bash_command]),
],
"PostToolUse": [
HookMatcher(matcher="Write|Edit", hooks=[post_write_handler]),
],
}
)
The matcher prevents unrelated tools from invoking that callback. Anthropic’s Python SDK hooks example shows callback registration and examples for both event types. Adjust the event and matcher to the tools and SDK version in your application.
Rank #2
Examples: preventive checks and post-call work
Block a command before it runs
Register a PreToolUse handler for Bash, inspect the proposed command in tool_input, and return a permissionDecision of deny when it matches a prohibited pattern. This is the appropriate point for a policy that must prevent the command from executing.
Free tools Windows power users keep installed
One-click scans. No signup required.
Validate a planned file path
Use PreToolUse with a Write matcher to check a destination before the write occurs. Anthropic’s hook configuration guide documents this path-validation pattern.
Rank #3
Review a result or add context
Use PostToolUse when the callback needs the returned response. The SDK example checks tool_response for an error string and can return a reason, system message, and additional context.
Format or lint after a write
For a formatter, linter, audit log, or notification that should run after a successful write or edit, register a PostToolUse handler matched to Write|Edit. This is follow-up processing, not a way to prevent the write.
Rank #4
Handle failed calls with the failure event
PostToolUse is the successful-execution event. The Python SDK reference lists PostToolUseFailure separately for tool execution failures, with an error field in its input. If your requirement includes handling failed calls, evaluate that event rather than assuming a success hook covers them. Check the SDK reference for the event support and behavior in your installed version.
Quick Recap
Best Value
Implementation checklist
- Decide whether the check must act before execution or needs a successful result.
- For prevention, register
PreToolUse; inspecttool_nameandtool_input, and return a deny decision when appropriate. - For result-dependent work, register
PostToolUseand inspecttool_response. - Add a matcher such as
Bash,Write, orWrite|Editto limit which tools invoke the callback. - If failures need their own handling, assess
PostToolUseFailure. - Verify callback signatures and event availability against the language SDK and version you have installed. The Python reference notes that the TypeScript SDK supports additional events not yet available in Python.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

