Command Palette

Search for a command to run...

Назад к скиллам
скилл № 21829

creating-claude-hooks

Use when creating or publishing Claude Code hooks - covers executable format, event types, JSON I/O, exit codes, security requirements, and PRPM package…

БесплатноБез исполняемых скриптов
pr-pmот pr-pm★ 125 звёзд на GitHub18 установок в других каталогах

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

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

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

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

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

Creating Claude Code Hooks

Use this skill when creating, improving, or publishing Claude Code hooks. Provides essential guidance on hook format, event handling, I/O conventions, and package structure.

When to Use This Skill

Activate this skill when:

  • User asks to create a new Claude Code hook
  • User wants to publish a hook as a PRPM package
  • User needs to understand hook format or events
  • User is troubleshooting hook execution
  • User asks about hook vs skill vs command differences

Quick Reference

Two Hook Configuration Methods

Method 1: JSON Configuration (Recommended)

  • Configure in .claude/settings.json, ~/.claude/settings.json, or plugin's hooks.json
  • Supports both command hooks and prompt hooks
  • More flexible, supports matchers and timeouts

Method 2: Executable Files (Legacy)

  • Place executables in .claude/hooks/<event-name>
  • Simpler but less configurable

Hook Types

Type Description Speed Use Case
Command Runs external script Fast (ms) Formatting, logging, file checks
Prompt Uses LLM reasoning Slow (2-10s) Complex validation, security analysis

Available Events

Event When It Fires Can Block? Common Use Cases
PreToolUse Before tool execution Yes (exit 2) Validation, permission checks, input modification
PostToolUse After tool completes No Formatting, logging, cleanup
UserPromptSubmit Before user input processes Yes Prompt validation, enhancement
SessionStart New session begins No Environment setup, context loading
Stop When assistant finishes No Cleanup, summary, verification
SubagentStop When subagent finishes No Subagent result processing
PreCompact Before context compaction No Save important context
Notification During alerts No Desktop notifications, logging
PermissionRequest When permission needed Yes Custom permission handling

Exit Codes

Code Meaning Behavior
0 Success Continue normally
2 Block Stop operation (PreToolUse only)
1 or other Error Log error, continue

JSON Hook Configuration

Settings-Based Hooks

Configure hooks in .claude/settings.json (project) or ~/.claude/settings.json (global):

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Write|Edit",
      "hooks": [{
        "type": "command",
        "command": "/path/to/validate-write.sh",
        "timeout": 5000
      }]
    }],
    "PostToolUse": [{
      "matcher": "Write|Edit",
      "hooks": [{
        "type": "command",
        "command": "/path/to/format-file.sh"
      }]
    }],
    "Stop": [{
      "matcher": "*",
      "hooks": [{
        "type": "prompt",
        "prompt": "Verify all requested changes were completed."
      }]
    }]
  }
}

Plugin hooks.json

For PRPM packages, use hook.json:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Write",
      "hooks": [{
        "type": "command",
        "command": "${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh",
        "timeout": 5000
      }]
    }]
  }
}

Matcher Patterns

Pattern Matches
"Write" Only Write tool
"Write|Edit" Write OR Edit tools
"Bash" Only Bash tool
"mcp__github__*" All GitHub MCP tools
"*" All tools (use sparingly)

Hook Options

{
  "type": "command",
  "command": "./my-hook.sh",
  "timeout": 5000,
  "once": true,
  "continue": true,
  "stopReason": "Message when blocked",
  "suppressOutput": false,
  "systemMessage": "Warning to show user"
}
Option Type Default Description
timeout number 60000 Max execution time in ms
once boolean false Run only once per session
continue boolean true Continue after hook completes
stopReason string - Message when continue=false
suppressOutput boolean false Hide stdout from transcript
systemMessage string - Warning message to user

Command Hooks

Command hooks run external scripts. They're fast and deterministic.

Shell Script Hook

#!/bin/bash
set -euo pipefail

# Read JSON input
INPUT=$(cat)
FILE=$(echo "$INPUT" | jq -r '.input.file_path // empty')

# Validate
-n &quot;$FILE&quot; || exit 0
-f &quot;$FILE&quot; || exit 0

# Block sensitive files
case "$FILE" in
  *.env|*.pem|*.key)
    echo "Blocked: $FILE is sensitive" >&2
    exit 2
    ;;
esac

exit 0

TypeScript Hook

#!/usr/bin/env node
import { readFileSync } from 'fs';

const input = JSON.parse(readFileSync(0, 'utf-8'));
const filePath = input.input?.file_path;

if (!filePath) process.exit(0);

// Block .env files
if (filePath.endsWith('.env')) {
  console.error('Blocked: Cannot modify .env files');
  proc
Полный SKILL.md на GitHub

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

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

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

FAQ

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

Use when creating or publishing Claude Code hooks - covers executable format, event types, JSON I/O, exit codes, security requirements, and PRPM package structure

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

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

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

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

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

Сравнить creating-claude-hooks с