Command Palette

Search for a command to run...

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

create-hooks

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

Guide for creating Claude Code hooks with proper configuration, shell commands, event handling, and security practices. Use when the user wants to create…

ronnycodingот ronnycoding★ 20 звёзд на GitHub16 установок в других каталогах

Об этом скилле

Create Hooks Guide

This skill helps you create Claude Code hooks - user-defined shell commands that execute at specific points in Claude Code's lifecycle. Hooks provide deterministic control over behavior rather than relying on LLM decisions.

Quick Start

When creating a new hook, follow this workflow:

  1. Identify the event - Which lifecycle event should trigger the hook?
  2. Define the action - What shell command should execute?
  3. Configure matcher - Which tools should trigger (specific tool or * for all)?
  4. Test the command - Verify the shell command works independently
  5. Add to settings.json - Register the hook in ~/.claude/settings.json
  6. Test in Claude Code - Verify the hook executes and behaves correctly
  7. Review security - Ensure no credential leakage or malicious behavior

Hook Events

Claude Code supports nine hook events:

1. PreToolUse

When: Before tool calls execute Can block: Yes (exit code 2) Use for:

  • File protection (block writes to sensitive files)
  • Validation (check command safety before execution)
  • Logging (track what tools will execute)
  • Permission checks (verify user authorization)

2. PostToolUse

When: After tool calls complete Can block: No Use for:

  • Code formatting (prettier, gofmt, black after edits)
  • Linting (run linters after code changes)
  • Testing (run tests after modifications)
  • Notifications (alert on specific tool completions)
  • Cleanup (remove temporary files)

3. UserPromptSubmit

When: User submits prompts, before processing Can block: Yes Use for:

  • Input validation
  • Prompt logging
  • Custom preprocessing
  • Security checks

4. Notification

When: Claude Code sends notifications Can block: No Use for:

  • Custom notification systems (desktop, Slack, email)
  • Notification filtering
  • Alert aggregation
  • Status dashboards

5. Stop

When: Claude Code finishes responding Can block: No Use for:

  • Session logging
  • Metrics collection
  • Cleanup operations
  • Status updates

6. SubagentStop

When: Subagent tasks complete Can block: No Use for:

  • Subagent result logging
  • Multi-agent workflow tracking
  • Performance metrics
  • Orchestration coordination

7. PreCompact

When: Before compact operations Can block: Yes Use for:

  • Backup creation
  • Validation before context reduction
  • State preservation
  • History archival

8. SessionStart

When: Session initiation or resumption Can block: No Use for:

  • Environment setup
  • Project initialization
  • Logging session start
  • Resource allocation

9. SessionEnd

When: Session termination Can block: No Use for:

  • Cleanup operations
  • Session summary logging
  • Resource deallocation
  • Statistics reporting

Configuration Format

Hooks are configured in ~/.claude/settings.json:

{
  "hooks": {
    "EventName": [
      {
        "matcher": "ToolName or *",
        "hooks": [
          {
            "type": "command",
            "command": "shell_command_here"
          }
        ]
      }
    ]
  }
}

Structure Breakdown

EventName: One of the nine hook events (e.g., PreToolUse, PostToolUse)

matcher:

  • Specific tool name (e.g., "Edit", "Bash", "Write")
  • "*" for all tools
  • Case-sensitive, must match tool name exactly

type: Always "command" for shell hooks

command: Shell command to execute (bash on Unix, cmd on Windows)

Shell Command Structure

Commands receive JSON input via stdin containing event data:

Common Fields (all events)

{
  "description": "Human-readable description",
  "tool_name": "Name of tool being used",
  "tool_input": { /* Tool-specific parameters */ }
}

Tool-Specific Input Examples

Edit tool:

{
  "tool_name": "Edit",
  "description": "Update user authentication",
  "tool_input": {
    "file_path": "/path/to/file.js",
    "old_string": "...",
    "new_string": "..."
  }
}

Bash tool:

{
  "tool_name": "Bash",
  "description": "Run tests",
  "tool_input": {
    "command": "npm test"
  }
}

Write tool:

{
  "tool_name": "Write",
  "description": "Create new component",
  "tool_input": {
    "file_path": "/path/to/file.ts",
    "content": "..."
  }
}

Processing JSON Input

Use jq for parsing JSON in shell commands:

# Extract file path
jq -r '.tool_input.file_path'

# Extract command
jq -r '.tool_input.command'

# Extract description with fallback
jq -r '.description // "No description"'

# Conditional processing
jq -r 'if .tool_input.file_path then .tool_input.file_path else empty end'

Exit Codes & Blocking

Exit code 0: Success

  • PreToolUse: Allows tool execution to continue
  • Other events: Indicates successful hook execution

Exit code 2: Block execution (PreToolUse only)

  • Prevents the tool from executing
  • Sends feedback to Claude about the block
  • Use for file protection, validation failur
Полный SKILL.md на GitHub

Установить create-hooks в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл create-hooks?

Guide for creating Claude Code hooks with proper configuration, shell commands, event handling, and security practices. Use when the user wants to create hooks, automate workflows, add event handlers, format code automatically, protect files, log actions, or mentions creating/configuring/building hooks.

Как установить скилл create-hooks?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл create-hooks запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

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

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