hook-development
[Utility] Guide for developing Claude Code hooks - shell commands that execute automatically in response to tool calls and notifications. Use this when users want to create, debug, or optimize hooks for automating workflows like linting, formatting, notifications, or custom validations. Supports PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification events.
When & Why to Use This Skill
This Claude skill provides a comprehensive framework for developing and optimizing Claude Code hooks, enabling developers to build event-driven automation scripts. By leveraging shell commands that trigger during specific lifecycle events—such as tool calls, session transitions, and user prompts—it empowers users to integrate automated linting, formatting, security validations, and custom notifications directly into their AI-assisted coding workflow, significantly enhancing productivity and code consistency.
Use Cases
- Automated Code Quality: Configure PreToolUse or PostToolUse hooks to automatically run linters (ESLint) or formatters (Prettier) whenever Claude modifies files.
- Security Guardrails: Implement deterministic command hooks to intercept and validate shell commands against security policies before they are executed by the agent.
- DevOps Integration: Trigger external CI/CD pipelines or status updates to platforms like Slack or Jira upon 'SessionEnd' or 'Stop' events.
- Environment Setup: Use 'SessionStart' hooks to automatically load project-specific environment variables or inject custom context into the agent's workspace.
- Custom Validations: Create prompt-based hooks to perform complex, context-aware checks on code changes before they are finalized, ensuring architectural compliance.
| name | hook-development |
|---|---|
| description | "[Utility] Guide for developing Claude Code hooks - shell commands that execute automatically in response to tool calls and notifications. Use this when users want to create, debug, or optimize hooks for automating workflows like linting, formatting, notifications, or custom validations. Supports PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification events." |
Hook Development for Claude Code Plugins
Overview
Hooks are event-driven automation scripts that execute in response to Claude Code events. Use hooks to validate operations, enforce policies, add context, and integrate external tools into workflows.
Hook Types
Prompt-Based Hooks (Recommended)
Use LLM-driven decision making for context-aware validation.
Command Hooks
Execute bash commands for deterministic checks.
Hook Events
| Event | When | Use For |
|---|---|---|
| PreToolUse | Before tool | Validation, modification |
| PostToolUse | After tool | Feedback, logging |
| UserPromptSubmit | User input | Context, validation |
| Stop | Agent stopping | Completeness check |
| SubagentStop | Subagent done | Task validation |
| SessionStart | Session begins | Context loading |
| SessionEnd | Session ends | Cleanup, logging |
| PreCompact | Before compact | Preserve context |
| Notification | User notified | Logging, reactions |
Environment Variables
$CLAUDE_PROJECT_DIR- Project root path$CLAUDE_PLUGIN_ROOT- Plugin directory$CLAUDE_ENV_FILE- SessionStart only: persist env vars here
Best Practices
- Use prompt-based hooks for complex logic
- Use ${CLAUDE_PLUGIN_ROOT} for portability
- Validate all inputs in command hooks
- Set appropriate timeouts