|
1 | 1 | --- |
2 | 2 | name: hook-development |
3 | | -description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PermissionRequest, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API. |
| 3 | +description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PermissionRequest, PostToolUse, PostToolUseFailure, Stop, SubagentStop, SubagentStart, Setup, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Hook Development for Claude Code Plugins |
@@ -235,6 +235,33 @@ Execute after tool completes. Use to react to results, provide feedback, or log. |
235 | 235 | - Exit 2: stderr fed back to Claude |
236 | 236 | - systemMessage included in context |
237 | 237 |
|
| 238 | +### PostToolUseFailure |
| 239 | + |
| 240 | +Execute when a tool fails after PostToolUse hooks have run. Use to handle errors or provide fallback actions. |
| 241 | + |
| 242 | +**Example:** |
| 243 | + |
| 244 | +```json |
| 245 | +{ |
| 246 | + "PostToolUseFailure": [ |
| 247 | + { |
| 248 | + "matcher": "Edit", |
| 249 | + "hooks": [ |
| 250 | + { |
| 251 | + "type": "prompt", |
| 252 | + "prompt": "Error occurred during edit. Provide fallback action or ask for user input." |
| 253 | + } |
| 254 | + ] |
| 255 | + } |
| 256 | + ] |
| 257 | +} |
| 258 | +``` |
| 259 | + |
| 260 | +**Output behavior:** |
| 261 | + |
| 262 | +- Exit 2: stderr fed back to Claude |
| 263 | +- systemMessage included in context |
| 264 | + |
238 | 265 | ### Stop |
239 | 266 |
|
240 | 267 | Execute when main agent considers stopping. Use to validate completeness. |
@@ -273,6 +300,50 @@ Execute when subagent considers stopping. Use to ensure subagent completed its t |
273 | 300 |
|
274 | 301 | Similar to Stop hook, but for subagents. |
275 | 302 |
|
| 303 | +### SubagentStart |
| 304 | + |
| 305 | +Execute when a subagent is started. Use to initialize subagent state or perform setup. |
| 306 | + |
| 307 | +**Example:** |
| 308 | + |
| 309 | +```json |
| 310 | +{ |
| 311 | + "SubagentStart": [ |
| 312 | + { |
| 313 | + "matcher": "mcp__subagent_name", |
| 314 | + "hooks": [ |
| 315 | + { |
| 316 | + "type": "command", |
| 317 | + "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/subagent-init.sh" |
| 318 | + } |
| 319 | + ] |
| 320 | + } |
| 321 | + ] |
| 322 | +} |
| 323 | +``` |
| 324 | + |
| 325 | +### Setup |
| 326 | + |
| 327 | +Execute once at session start to perform global setup or initialize resources. |
| 328 | + |
| 329 | +**Example:** |
| 330 | + |
| 331 | +```json |
| 332 | +{ |
| 333 | + "Setup": [ |
| 334 | + { |
| 335 | + "matcher": "*", |
| 336 | + "hooks": [ |
| 337 | + { |
| 338 | + "type": "command", |
| 339 | + "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/session-setup.sh" |
| 340 | + } |
| 341 | + ] |
| 342 | + } |
| 343 | + ] |
| 344 | +} |
| 345 | +``` |
| 346 | + |
276 | 347 | ### UserPromptSubmit |
277 | 348 |
|
278 | 349 | Execute when user submits a prompt. Use to add context, validate, or block prompts. |
@@ -647,18 +718,21 @@ echo "$output" | jq . |
647 | 718 |
|
648 | 719 | ### Hook Events Summary |
649 | 720 |
|
650 | | -| Event | When | Use For | |
651 | | -| ----------------- | ----------------- | ------------------------ | |
652 | | -| PreToolUse | Before tool | Validation, modification | |
653 | | -| PermissionRequest | Permission dialog | Auto-allow/deny | |
654 | | -| PostToolUse | After tool | Feedback, logging | |
655 | | -| UserPromptSubmit | User input | Context, validation | |
656 | | -| Stop | Agent stopping | Completeness check | |
657 | | -| SubagentStop | Subagent done | Task validation | |
658 | | -| SessionStart | Session begins | Context loading | |
659 | | -| SessionEnd | Session ends | Cleanup, logging | |
660 | | -| PreCompact | Before compact | Preserve context | |
661 | | -| Notification | User notified | Logging, reactions | |
| 721 | +| Event | When | Use For | |
| 722 | +| ------------------ | ------------------ | ------------------------ | |
| 723 | +| Setup | Session init | Global initialization | |
| 724 | +| PreToolUse | Before tool | Validation, modification | |
| 725 | +| PermissionRequest | Permission dialog | Auto-allow/deny | |
| 726 | +| PostToolUse | After tool success | Feedback, logging | |
| 727 | +| PostToolUseFailure | After tool fails | Error handling | |
| 728 | +| UserPromptSubmit | User input | Context, validation | |
| 729 | +| Stop | Agent stopping | Completeness check | |
| 730 | +| SubagentStart | Subagent begins | Subagent setup | |
| 731 | +| SubagentStop | Subagent done | Task validation | |
| 732 | +| SessionStart | Session begins | Context loading | |
| 733 | +| SessionEnd | Session ends | Cleanup, logging | |
| 734 | +| PreCompact | Before compact | Preserve context | |
| 735 | +| Notification | User notified | Logging, reactions | |
662 | 736 |
|
663 | 737 | ### Best Practices |
664 | 738 |
|
|
0 commit comments