Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions assets/prompts/skills/agent-customization/references/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,85 @@ Each hook command supports:

Hooks receive JSON on stdin and can return JSON on stdout.

- Common output: `continue`, `stopReason`, `systemMessage`
- `PreToolUse` permissions are read from `hookSpecificOutput.permissionDecision` (`allow` | `ask` | `deny`)
- `PostToolUse` output can block further processing with `decision: block`
**IMPORTANT:** All field names use **snake_case** (e.g., `tool_name`, `tool_input`, `tool_use_id`), not camelCase.

`PreToolUse` example output:
### Common Input Fields

All hook events receive these common fields:
- `timestamp` (string): ISO 8601 timestamp
- `hookEventName` (string): Event type (e.g., "PreToolUse", "PostToolUse")
- `sessionId` (string, optional): Session identifier
- `transcript_path` (string, optional): Path to session transcript file
- `cwd` (string, optional): Working directory for the hook command

### PreToolUse Hook

**Input fields:**
- `tool_name` (string): Name of the tool being invoked
- `tool_input` (object): Tool input parameters
- `tool_use_id` (string): Unique identifier for this tool invocation

**Output format:**
```json
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "ask",
"permissionDecisionReason": "Needs user confirmation"
"permissionDecisionReason": "Needs user confirmation",
"updatedInput": { ... },
"additionalContext": "Extra context for the agent"
}
}
```

Fields in `hookSpecificOutput`:
- `permissionDecision`: `allow` | `ask` | `deny` (controls tool execution)
- `permissionDecisionReason`: Human-readable explanation
- `updatedInput`: Modified tool input to use instead
- `additionalContext`: Extra context injected into agent's prompt

### PostToolUse Hook

**Input fields:**
- `tool_name` (string): Name of the tool that was invoked
- `tool_input` (object): Tool input parameters
- `tool_use_id` (string): Unique identifier for this tool invocation
- `tool_response` (string): The output returned by the tool

**Output format:**
```json
{
"decision": "block",
"reason": "Tool output violates policy",
"hookSpecificOutput": {
"hookEventName": "PostToolUse",
"additionalContext": "Filtered result: ..."
}
}
```

Fields in output:
- `decision`: Set to `"block"` to prevent tool result from reaching the agent
- `reason`: Human-readable explanation for blocking
- `hookSpecificOutput.additionalContext`: Context injected into agent's prompt (replaces or augments tool response)

### Common Output Fields

All hook types support:
- `continue` (boolean): Set to `false` to stop processing remaining hooks
- `stopReason` (string): Message to display when stopping execution
- `systemMessage` (string): Warning message shown to user (deprecated for PostToolUse, use `additionalContext` instead)

### Common Tool Names

Common `tool_name` values VS Code emits:
- **File Operations**: `Read`, `Edit`, `MultiEdit`, `Write`, `NotebookEdit`
- **Search**: `Glob`, `Grep`, `LS`
- **Execution**: `Bash`, `BashOutput`, `KillBash`, `Task`
- **Network**: `WebFetch`, `WebSearch`
- **Planning**: `EnterPlanMode`, `ExitPlanMode`, `TodoWrite`
- **User Interaction**: `AskUserQuestion`

Exit codes:
- `0` success
- `2` blocking error
Expand Down