hooks-system
БесплатноБез исполняемых скриптовНе проверенComprehensive lifecycle hook patterns for Claude Code workflows. Use when configuring PreToolUse, PostToolUse, UserPromptSubmit, Stop, or SubagentStop hooks…
от MadAppGang★ 290 звёзд на GitHubОб этом скилле
Hooks System
Version: 1.0.0 Purpose: Lifecycle hook patterns for validation, automation, security, and metrics in Claude Code workflows Status: Production Ready
Overview
Hooks are lifecycle callbacks that execute at specific points in the Claude Code workflow. They enable:
- Validation (block dangerous operations before execution)
- Automation (auto-format code after file changes)
- Security (enforce safety policies on commands and tools)
- Metrics (track tool usage, performance, costs)
- Quality Control (run tests after implementation changes)
- Context Injection (load project-specific context at session start)
Hooks transform Claude Code from a reactive assistant into a proactive, policy-enforced development environment.
Hook Types Reference
Claude Code provides 7 hook types that fire at different lifecycle stages:
| Hook Type | When It Fires | Receives | Can Modify | Use Cases |
|---|---|---|---|---|
| PreToolUse | Before tool execution | Tool name, input | Tool input, can block | Validation, security checks, permission gates |
| PostToolUse | After tool completion | Tool name, input, output | Nothing (read-only) | Auto-format, metrics, notifications |
| UserPromptSubmit | User submits prompt | Prompt text | Nothing (read-only) | Complexity analysis, model routing, context injection |
| SessionStart | Session begins | Session metadata | Nothing (read-only) | Load project context, initialize environment |
| Stop | Main session stops | Session metadata | Nothing (read-only) | Completion validation, cleanup, final reports |
| SubagentStop | Sub-agent (Task) completes | Task metadata, output | Nothing (read-only) | Task metrics, result validation |
| Notification | System notification | Notification data | Nothing (read-only) | Alert logging, external integrations |
| PermissionRequest | Tool needs permission | Tool name, action | Nothing (read-only) | Custom approval workflows |
Key Concepts:
- PreToolUse: Only hook that can block or modify execution
- PostToolUse: Cannot modify output, but can trigger follow-up actions
- Matcher: Regex pattern to filter which tools trigger the hook
- Hooks Array: Commands to execute when hook fires (can run multiple)
Hook Configuration in settings.json
Hooks are configured in .claude/settings.json under the "hooks" key:
Basic Structure
{
"hooks": {
"PreToolUse": [
{
"matcher": "^(Write|Edit)$",
"hooks": ["echo 'File change detected'"]
}
],
"PostToolUse": [
{
"matcher": "^(Write|Edit)$",
"hooks": ["bun run format"]
}
]
}
}
Configuration Properties
matcher (required):
- Regex pattern to match tool names
- Uses JavaScript regex syntax
- Examples:
"^Write$"- Matches only Write tool"^(Write|Edit)$"- Matches Write or Edit".*"- Matches all tools (use sparingly)"^Bash$"- Matches Bash tool
hooks (required):
- Array of commands to execute
- Commands run sequentially
- Can be shell commands or custom scripts
- Each command runs in its own shell context
continueOnError (optional, default: true):
true: Continue workflow if hook failsfalse: Stop workflow on hook failure- Use
falsefor critical validation hooks
timeout (optional, default: 30000ms):
- Maximum execution time for hook command
- In milliseconds (30000 = 30 seconds)
- Hook is killed if timeout exceeded
Advanced Configuration Example
{
"hooks": {
"PreToolUse": [
{
"matcher": "^Write$",
"hooks": [
"node scripts/validate-file.js",
"node scripts/check-secrets.js"
],
"continueOnError": false,
"timeout": 10000
}
],
"PostToolUse": [
{
"matcher": "^(Write|Edit)$",
"hooks": ["bun run format", "bun run lint --fix"],
"continueOnError": true,
"timeout": 60000
}
],
"UserPromptSubmit": [
{
"matcher": ".*",
"hooks": ["node scripts/analyze-complexity.js"]
}
]
}
}
Ready-To-Use Hook Templates
Template 1: File Protection Hook
Purpose: Block writes to sensitive files (secrets, credentials, config)
Hook Type: PreToolUse
Matcher: "^(Write|Edit)$"
Configuration:
{
"hooks": {
"PreToolUse": [
{
"matcher": "^(Write|Edit)$",
"hooks": ["node scripts/protect-files.js"],
"continueOnError": false,
"timeout": 5000
}
]
}
}
Script: scripts/protect-files.js
#!/usr/bin/env node
const PROTECTED_PATTERNS = [
/\.env$/,
/\.env\./,
/credentials\.json$/,
/secrets\.yaml$/,
/id_rsa$/,
/\.pem$/,
/\.key$/
];
const args = process.argv.slice(2);
const filePath = args[0] || '';
const isProtected = PROTECTED_PATTERNS.
Установить hooks-system в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл hooks-system?
Comprehensive lifecycle hook patterns for Claude Code workflows. Use when configuring PreToolUse, PostToolUse, UserPromptSubmit, Stop, or SubagentStop hooks. Covers hook matchers, command hooks, prompt hooks, validation, metrics, auto-formatting, and security patterns. Trigger keywords - "hooks", "PreToolUse", "PostToolUse", "lifecycle", "tool matcher", "hook template", "auto-format", "security hook", "validation hook".
Как установить скилл hooks-system?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл hooks-system запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic