$npx -y skills add softspark/ai-toolkit --skill hook-creatorCreate new Claude Code lifecycle hook (PreToolUse/PostToolUse/Stop/SessionStart) with bash + hooks.json. Triggers: create hook, lifecycle hook, PreToolUse, PostToolUse, hook event.
| 1 | # Hook Creator |
| 2 | |
| 3 | $ARGUMENTS |
| 4 | |
| 5 | Create a new Claude Code hook following ai-toolkit conventions. |
| 6 | |
| 7 | ## Supported Hook Events |
| 8 | |
| 9 | ### Core lifecycle |
| 10 | |
| 11 | | Event | Fires When | Matcher | Typical Use | |
| 12 | |-------|-----------|---------|-------------| |
| 13 | | `SessionStart` | Session begins, resumes, or clears | `startup\|resume\|clear` | Context injection, rules reminder | |
| 14 | | `SessionEnd` | Session is closing | any | Flush logs, save transcripts | |
| 15 | | `UserPromptSubmit` | User submits a prompt | any | Prompt governance, usage tracking | |
| 16 | | `Notification` | Claude sends a notification | any | OS alerts, Slack pings | |
| 17 | | `MessageDisplay` | Assistant message is about to be shown to the user | any | Transform or hide assistant message text before display | |
| 18 | |
| 19 | ### Tool lifecycle |
| 20 | |
| 21 | | Event | Fires When | Matcher | Typical Use | |
| 22 | |-------|-----------|---------|-------------| |
| 23 | | `PreToolUse` | Before a tool executes | tool name (e.g. `Bash`) or `if:` rule | Safety guards, validation, `"defer"` for headless | |
| 24 | | `PostToolUse` | After a tool executes | tool name | Feedback loops, logging, format-on-save | |
| 25 | | `PostToolUseFailure` | After a tool fails | tool name | Failure telemetry, recovery hints | |
| 26 | | `PostToolBatch` | After a batch of tool calls completes | any | Batch summaries, aggregate validation | |
| 27 | |
| 28 | ### Turn lifecycle |
| 29 | |
| 30 | | Event | Fires When | Matcher | Typical Use | |
| 31 | |-------|-----------|---------|-------------| |
| 32 | | `Stop` | Claude finishes responding | any | Quality checks, session save | |
| 33 | | `StopFailure` | Turn ends due to an API error (rate limit, auth) | any | Alerting, fallback behavior | |
| 34 | | `UserPromptExpansion` | Claude expands or rewrites a submitted prompt | any | Prompt policy and context shaping | |
| 35 | |
| 36 | ### Subagent lifecycle |
| 37 | |
| 38 | | Event | Fires When | Matcher | Typical Use | |
| 39 | |-------|-----------|---------|-------------| |
| 40 | | `SubagentStart` | Subagent launches | any | Observability | |
| 41 | | `SubagentStop` | Subagent completes | any | Result validation | |
| 42 | |
| 43 | ### Compaction |
| 44 | |
| 45 | | Event | Fires When | Matcher | Typical Use | |
| 46 | |-------|-----------|---------|-------------| |
| 47 | | `PreCompact` | Before context compaction; can block with exit 2 or `{"decision":"block"}` | any | Context preservation | |
| 48 | | `PostCompact` | After compaction completes | any | Re-inject state that was summarized away | |
| 49 | |
| 50 | ### Permissions & elicitation |
| 51 | |
| 52 | | Event | Fires When | Matcher | Typical Use | |
| 53 | |-------|-----------|---------|-------------| |
| 54 | | `PermissionRequest` | Tool awaiting permission; can return `updatedInput` | any | Headless approval flows | |
| 55 | | `PermissionDenied` | Auto-mode classifier denied a tool call; return `{retry: true}` to allow retry | any | Coach the model, log denials | |
| 56 | | `Elicitation` | MCP `elicitation/create` request arrives | any | Intercept / override MCP UI prompts | |
| 57 | | `ElicitationResult` | Elicitation response ready to be sent back | any | Validate / transform elicitation replies | |
| 58 | |
| 59 | ### Agent Teams |
| 60 | |
| 61 | | Event | Fires When | Matcher | Typical Use | |
| 62 | |-------|-----------|---------|-------------| |
| 63 | | `TaskCreated` | New task registered via `TaskCreate` | any | Audit, assignment routing | |
| 64 | | `TaskCompleted` | Agent Teams task finished | any | Lint, type check, notify | |
| 65 | | `TeammateIdle` | Agent Teams member idle | any | Completeness reminder | |
| 66 | |
| 67 | ### Worktrees & environment |
| 68 | |
| 69 | | Event | Fires When | Matcher | Typical Use | |
| 70 | |-------|-----------|---------|-------------| |
| 71 | | `WorktreeCreate` | Worktree is being created; `type: "http"` can return `hookSpecificOutput.worktreePath` | any | Provision worktree dirs | |
| 72 | | `WorktreeRemove` | Worktree is being removed | any | Cleanup | |
| 73 | | `CwdChanged` | Working directory changes during a session | any | Reactive env management (e.g., direnv) | |
| 74 | | `FileChanged` | Tracked file is modified on disk | any | Re-lint, reload config | |
| 75 | | `ConfigChange` | Settings / config file changed | any | Re-validate, warn on drift | |
| 76 | |
| 77 | ### Setup / bootstrap |
| 78 | |
| 79 | | Event | Fires When | Matcher | Typical Use | |
| 80 | |-------|-----------|---------|-------------| |
| 81 | | `Setup` | First-run / initialization | any | Project bootstrap | |
| 82 | | `InstructionsLoaded` | CLAUDE.md / AGENTS.md loaded into context | any | Verify presence of mandatory rules | |
| 83 | |
| 84 | ## Hook Handler Types |
| 85 | |
| 86 | Claude Code supports five handler `type` values in `hooks.json`: |
| 87 | |
| 88 | | Type | Purpose | Required fields | |
| 89 | |------|---------|-----------------| |
| 90 | | `command` | Run a shell script / binary | `command` (path + args) | |
| 91 | | `http` | Call a local or remote HTTP endpoint | `url` | |
| 92 | | `prompt` | Inject a prompt to the fast inline model and use its verdict | `prompt` | |
| 93 | | `agent` | Spawn a full subagent to evaluate the event (must target `Stop` / `SubagentStop`) | `agent` (agent name) | |
| 94 | | `mcp_tool |