PostToolUse
PostToolUse is triggered immediately after a tool is successfully executed. Supports the same matcher values as PreToolUse.
Common Matchers
Task- Subagent tasksBash- Shell commandsGlob- File pattern matchingGrep- Content searchRead- File readingEdit- File editingWrite- File writingWebFetch,WebSearch- Web operations
Configuration Methods
Configure Hooks in the settings file:
~/.hcode/settings.json- User-level settings.hcode/settings.json- Project-level settings
Basic Structure
{ |
matcher: Pattern used to match tool names, case-sensitive
- Simple string: Exact match, e.g.,
Writeonly matches the Write tool - Regular expression: Supports patterns like
Edit|WriteorNotebook.* - Wildcard: Use
*to match all tools, or use empty string""or omitmatcher
hooks: Array of hooks to execute when the pattern matches
type: Hook execution type,"command"means execute bash commandcommand: The bash command to executetimeout: (Optional) Hook execution timeout in seconds
PostToolUse in Plugin Hooks
Example plugin hook configuration:
{ |
Input Parameters
The specific format of tool_input and tool_response depends on the tool type.
{ |
Field Descriptions
| Field | Type | Description |
|---|---|---|
session_id |
string | Session unique identifier |
transcript_path |
string | Full path to the conversation JSON file |
cwd |
string | Current working directory when the hook is called |
permission_mode |
string | Current permission mode: "default", "plan", "acceptEdits", "dontAsk" or "bypassPermissions" |
hook_event_name |
string | Fixed as "PostToolUse" |
tool_name |
string | Name of the executed tool (e.g., Write, Edit, Bash, etc.) |
tool_input |
object | Tool’s input parameters (varies by tool) |
tool_response |
object | Tool’s response result (varies by tool) |
tool_use_id |
string | Unique identifier for the tool call |
Note: The specific format of
tool_inputandtool_responsedepends on the tool type.
Output Parameters / Decision Control
PostToolUse hooks can provide feedback to Hawa Code after tool execution.
"block": Block subsequent operations and prompt Hawa Code withreasonundefined: Do nothing,reasonis ignored"hookSpecificOutput.additionalContext": Add extra context for Hawa Code
{ |
Field Descriptions
| Field | Type | Description |
|---|---|---|
decision |
string | undefined | "block" means block and prompt with reason, undefined means do nothing |
reason |
string | Explanation of the decision |
hookSpecificOutput |
object | Hook-specific output information |
hookSpecificOutput.hookEventName |
string | Fixed as "PostToolUse" |
hookSpecificOutput.additionalContext |
string | Additional context information added for Hawa Code |
Exit Code Behavior
Simple Exit Codes
Hooks communicate status through exit codes, stdout, and stderr:
- Exit code 0: Success,
stdoutis displayed to the user - Exit code 2: Blocking error, stderr is displayed to Hawa Code (tool has been executed), format is
[command]: {stderr} - Other exit codes: Non-blocking error, displayed in
stderr
PostToolUse Specific Exit Code 2 Behavior
| Hook Event | Behavior |
|---|---|
PostToolUse |
Display stderr to Hawa Code (tool has been executed) |