Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

hooks-system

БесплатноБез исполняемых скриптовНе проверен

Comprehensive lifecycle hook patterns for Claude Code workflows. Use when configuring PreToolUse, PostToolUse, UserPromptSubmit, Stop, or SubagentStop hooks…

MadAppGangот 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 fails
  • false: Stop workflow on hook failure
  • Use false for 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.
Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить hooks-system с