Skip to content
Draft
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
97 changes: 91 additions & 6 deletions assets/prompts/skills/agent-customization/references/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,108 @@ 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 hook input field names use **snake_case** (e.g., `tool_name`, `tool_input`, `tool_use_id`), not camelCase.

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

Tool-based hooks (`PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `PermissionRequest`) receive:
- `tool_name` (string) - The name of the tool being invoked
- `tool_input` (object) - The input parameters for the tool
- `tool_use_id` (string) - Unique identifier for this tool invocation
- `cwd` (string) - Current working directory

`PostToolUse` additionally receives:
- `tool_response` (string) - The output from the tool execution

`PostToolUseFailure` receives `error` and `is_interrupt` instead of `tool_response`.

### Common Output Fields

All hooks can return:
- `continue` (boolean) - Whether to continue execution (default: true)
- `stopReason` (string) - Reason for stopping (if continue is false)
- `hookSpecificOutput` (object) - Hook-specific output fields (see below)

### Hook-Specific Output

**PreToolUse** hook returns permissions via `hookSpecificOutput`:
```json
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "ask",
"permissionDecisionReason": "Needs user confirmation"
"permissionDecisionReason": "Needs user confirmation",
"updatedInput": { "path": "/safe/path" },
"additionalContext": "Remember to validate the path"
}
}
```

**PostToolUse** hook returns additional context via `hookSpecificOutput`:
```json
{
"hookSpecificOutput": {
"hookEventName": "PostToolUse",
"additionalContext": "Tool completed successfully. Next steps: verify the output."
}
}
```

Exit codes:
### Complete Examples

**PreToolUse Input Example:**
```json
{
"tool_name": "Bash",
"tool_input": { "command": "npm install", "mode": "sync" },
"tool_use_id": "toolu_01abc123",
"cwd": "/workspace/project"
}
```

**PostToolUse Input Example:**
```json
{
"tool_name": "Edit",
"tool_input": { "file_path": "/workspace/src/app.ts", "old_str": "const x = 1;", "new_str": "const x = 2;" },
"tool_use_id": "toolu_01xyz789",
"tool_response": "File /workspace/src/app.ts updated successfully",
"cwd": "/workspace/project"
}
```

### Common Tool Names

When filtering tool-based hooks by `tool_name`, use these values:

**File Operations:**
- `Edit` - Edit existing files
- `MultiEdit` - Edit multiple files
- `Write` - Create new files
- `Read` - Read file contents
- `NotebookEdit` - Edit Jupyter notebooks

**Code Search & Navigation:**
- `Grep` - Search file contents
- `Glob` - Find files by pattern
- `LS` - List directory contents

**Execution:**
- `Bash` - Run shell commands
- `BashOutput` - Get shell command output
- `KillBash` - Stop shell command
- `Task` - Run sub-agent task

**Special:**
- `EnterPlanMode` - Enter planning mode
- `ExitPlanMode` - Exit planning mode
- `TodoWrite` - Write to-do items
- `WebFetch` - Fetch web pages
- `WebSearch` - Search the web
- `AskUserQuestion` - Ask the user a question

### Exit Codes

- `0` success
- `2` blocking error
- Other values produce non-blocking warnings
Expand Down
Loading