Comprehensive guide to integrating skills with Claude Code's 12 hook events. Use when creating hook-aware skills for harnesses like Clausitron, or when needing hook response schemas and patterns.
Provides comprehensive patterns for integrating skills with Claude Code's 12 hook events. Use when creating hook-aware skills for harnesses like Clausitron, or when needing hook response schemas and validation patterns.
/plugin marketplace add mgd34msu/goodvibes-plugin/plugin install goodvibes@goodvibes-marketThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Skills can be designed to work with Claude Code's 12 hook events, enabling deep integration with harnesses like Clausitron.
| Hook Event | When It Fires | Skill Integration Opportunity |
|---|---|---|
PreToolUse | Before any tool executes | Validation skills, policy enforcement |
PostToolUse | After tool execution | Logging skills, result enrichment |
PostToolUseFailure | When a tool fails | Error analysis skills, recovery suggestions |
UserPromptSubmit | When user sends prompt | Context injection, prompt enhancement |
SessionStart | Session begins | Environment setup, context loading |
SessionEnd | Session ends | Summary generation, cleanup |
SubagentStart | Subagent spawns | Budget allocation, tracking |
SubagentStop | Subagent completes | Result aggregation, cost tracking |
Stop | Agent stops | State persistence, handoff notes |
PreCompact | Before context compaction | Archive important context |
PermissionRequest | Permission dialog triggered | Policy-based auto-decisions |
Notification | Agent status messages | External notifications (Slack, etc.) |
Skills that validate operations before they execute:
---
name: security-validator
description: Validates file operations for security compliance. Use with PreToolUse hook.
---
# Security Validator
## Hook Integration
This skill provides validation logic for PreToolUse hooks.
## Validation Rules
### File Write Validation
When `tool_name` is `Write` or `Edit`:
1. Check `file_path` against blocked patterns:
- `*.env*` - Environment files with secrets
- `*credentials*` - Credential files
- `**/config/production/**` - Production configs
2. Return `permissionDecision: 'deny'` if blocked
### Bash Command Validation
When `tool_name` is `Bash`:
1. Parse `command` for dangerous patterns:
- `rm -rf /` or `rm -rf ~`
- `curl | bash` or `wget | sh`
- Commands with `--force` on production paths
2. Return `permissionDecision: 'ask'` for review
Skills that enrich context at key moments:
---
name: project-context
description: Injects project-specific context at session start. Use with SessionStart hook.
---
# Project Context Injector
## Hook Integration
Responds to SessionStart and UserPromptSubmit hooks.
## Context Injection
### On SessionStart
Read and inject:
- Active sprint goals from `docs/SPRINT.md`
- Recent changes from `git log --oneline -10`
- Known issues from `docs/KNOWN_ISSUES.md`
### On UserPromptSubmit
Analyze prompt for keywords and inject relevant:
- API documentation for mentioned endpoints
- Schema definitions for mentioned models
- Test patterns for mentioned components
Skills that generate summaries when sessions end:
---
name: session-summarizer
description: Generates session summaries on completion. Use with SessionEnd hook.
---
# Session Summarizer
## Hook Integration
Responds to SessionEnd and Stop hooks.
## Summary Generation
### Session Summary Format
```json
{
"session_id": "{from hook input}",
"duration_minutes": "{calculated}",
"files_modified": ["{list from git status}"],
"key_accomplishments": ["{extracted from conversation}"],
"open_questions": ["{unresolved items}"],
"next_steps": ["{suggested follow-ups}"]
}
Write summaries to:
.claude/session-summaries/{session_id}.json.claude/HANDOFF.md with latest summary
### Pattern 4: Cost Tracking Skill (SubagentStart/SubagentStop)
Skills that monitor resource usage:
```markdown
---
name: cost-tracker
description: Tracks token usage and costs across subagents. Use with Subagent hooks.
---
# Cost Tracker
## Hook Integration
Responds to SubagentStart and SubagentStop hooks.
## Tracking Logic
### On SubagentStart
Record:
- `agent_id` from hook input
- `agent_type` for categorization
- Start timestamp
- Allocated budget (if applicable)
### On SubagentStop
Calculate:
- Token usage from result message
- Cost based on model pricing
- Duration
- Update running totals
### Budget Enforcement
If cumulative cost exceeds threshold:
- Log warning
- Can trigger `permissionDecision: 'deny'` on next PreToolUse
Skills that integrate with hooks should understand the response format:
// PreToolUse can return permission decisions
{
hookSpecificOutput: {
hookEventName: 'PreToolUse',
permissionDecision: 'allow' | 'deny' | 'ask',
permissionDecisionReason: 'Explanation shown to Claude',
updatedInput: { /* modified tool input */ }
}
}
// UserPromptSubmit can add context
{
hookSpecificOutput: {
hookEventName: 'UserPromptSubmit',
additionalContext: 'Context injected into conversation'
}
}
// SessionStart can add context
{
hookSpecificOutput: {
hookEventName: 'SessionStart',
additionalContext: 'Startup context for Claude'
}
}
// PostToolUse can add context
{
hookSpecificOutput: {
hookEventName: 'PostToolUse',
additionalContext: 'Context after tool execution'
}
}
// Any hook can inject system messages
{
systemMessage: 'Message visible to Claude in conversation'
}
// Any hook can stop execution
{
continue: false,
stopReason: 'Why execution stopped'
}
Each hook receives specific input data:
{
hook_event_name: 'PreToolUse',
session_id: string,
tool_name: string, // 'Bash', 'Write', 'Edit', etc.
tool_input: { // Tool-specific parameters
command?: string, // For Bash
file_path?: string, // For Write/Edit/Read
content?: string, // For Write
// ... other tool params
},
cwd: string,
transcript_path: string
}
{
hook_event_name: 'SessionStart',
session_id: string,
source: 'startup' | 'resume' | 'clear' | 'compact',
cwd: string,
transcript_path: string
}
{
hook_event_name: 'SessionEnd',
session_id: string,
reason: string, // 'clear', 'logout', 'prompt_input_exit', etc.
cwd: string,
transcript_path: string
}
{
hook_event_name: 'SubagentStart',
session_id: string,
agent_id: string,
agent_type: string,
cwd: string,
transcript_path: string
}
{
hook_event_name: 'SubagentStop',
session_id: string,
stop_hook_active: boolean,
cwd: string,
transcript_path: string
}
When creating hook-aware skills:
{} to allow operations by defaultThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
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, 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.