Agent skill

hook-creator

This skill should be used when the user asks to "create a hook", "write hook config", "add hooks.json", "configure event hooks", "create PreToolUse hook", "add SessionStart hook", "implement hook validation", "set up event-driven automation", needs guidance on hooks.json structure, hook events (PreToolUse, PostToolUse, Stop, SessionStart, SessionEnd, UserPromptSubmit), or wants to automate workflows and implement event-driven behavior in Claude Code plugins.

Stars 4
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/basher83/agent-auditor/tree/main/skills/hook-creator

SKILL.md

Hook Creator

Overview

Creates hook configurations that respond to Claude Code events automatically. Hooks enable automation like formatting on save, running tests after edits, or custom session initialization.

When to use: User wants to automate workflows, needs event-driven behavior, or requests hooks for their plugin.

References: Consult plugins/meta/claude-docs/skills/claude-docs/reference/plugins-reference.md for hook specifications and available events.

Hook Structure Requirements

Hooks are defined in hooks/hooks.json with:

  1. Event type (SessionStart, PostToolUse, etc.)
  2. Matcher (optional, for filtering which tool uses trigger hook)
  3. Hook actions (command, validation, notification)
  4. Proper use of ${CLAUDE_PLUGIN_ROOT} for plugin-relative paths

Available Events

From official documentation:

  • PreToolUse - Before Claude uses any tool
  • PostToolUse - After Claude uses any tool
  • UserPromptSubmit - When user submits a prompt
  • Notification - When Claude Code sends notifications
  • Stop - When Claude attempts to stop
  • SubagentStop - When subagent attempts to stop
  • SessionStart - At session beginning
  • SessionEnd - At session end
  • PreCompact - Before conversation history compaction

Creation Process

Step 1: Identify Event and Purpose

Ask the user:

  • What should happen automatically?
  • When should it happen (which event)?
  • What tool uses should trigger it (if PostToolUse)?

Step 2: Choose Hook Type

Three hook types:

  • command: Execute shell commands/scripts
  • validation: Validate file contents or project state
  • notification: Send alerts or status updates

Step 3: Write Hook Configuration

Structure for hooks/hooks.json:

json
{
  "hooks": {
    "EventName": [
      {
        "matcher": "ToolName1|ToolName2",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PLUGIN_ROOT}/scripts/script.sh"
          }
        ]
      }
    ]
  }
}

Step 4: Create Associated Scripts

If using command hooks:

  1. Create script in plugin's scripts/ directory
  2. Make executable: chmod +x scripts/script.sh
  3. Use ${CLAUDE_PLUGIN_ROOT} for paths

Step 5: Verify Against Official Docs

Check plugins/meta/claude-docs/skills/claude-docs/reference/plugins-reference.md for:

  • Current event names
  • Hook configuration schema
  • Environment variable usage

Key Principles

  • Event Selection: Choose most specific event for the need
  • Matcher Precision: Use matchers to avoid unnecessary executions
  • Script Paths: Always use ${CLAUDE_PLUGIN_ROOT} for portability
  • Error Handling: Scripts should handle errors gracefully

Examples

Example 1: Code Formatting Hook

User: "Auto-format code after I edit files"

Hook configuration:

json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PLUGIN_ROOT}/scripts/format-code.sh"
          }
        ]
      }
    ]
  }
}

Creates scripts/format-code.sh that runs formatter on modified files.

Example 2: Session Welcome Message

User: "Show a message when Claude starts"

Hook configuration:

json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo 'Welcome! Plugin loaded successfully.'"
          }
        ]
      }
    ]
  }
}

Simple command hook, no external script needed.

Example 3: Test Runner Hook

User: "Run tests after I modify test files"

Hook configuration:

json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PLUGIN_ROOT}/scripts/run-tests.sh"
          }
        ]
      }
    ]
  }
}

Creates scripts/run-tests.sh that detects test file changes and runs relevant tests.

Expand your agent's capabilities with these related and highly-rated skills.

basher83/agent-auditor

doc-generator

Generate markdown documentation from Python codebases by analyzing source files, extracting docstrings, type hints, and code structure. Use when the user asks to document Python code, create API docs, or generate README files from source code.

4 0
Explore
basher83/agent-auditor

crawl4ai

This skill should be used when users need to scrape websites, extract structured data, handle JavaScript-heavy pages, crawl multiple URLs, or build automated web data pipelines. Includes optimized extraction patterns with schema generation for efficient, LLM-free extraction.

4 0
Explore
basher83/agent-auditor

multi-agent-composition

This skill should be used when the user asks to "choose between skill and agent", "compose multi-agent system", "orchestrate agents", "manage agent context", "design component architecture", "should I use a skill or agent", "when to use hooks vs MCP", "build orchestrator workflow", needs decision frameworks for Claude Code components (skills, sub-agents, hooks, MCP servers, slash commands), context management patterns, or wants to build effective multi-component agentic systems with proper orchestration and anti-patterns guidance.

4 0
Explore
basher83/agent-auditor

command-creator

This skill should be used when the user asks to "create a slash command", "write a command file", "add command to plugin", "create /command", "write command frontmatter", "add command arguments", "configure command tools", needs guidance on command structure, YAML frontmatter fields (description, argument-hint, allowed-tools), markdown command body, or wants to add custom slash commands to Claude Code plugins with proper argument handling and tool restrictions.

4 0
Explore
basher83/agent-auditor

test-blocked-fixture

This is a test fixture with intentional violations for regression testing. It contains <angle brackets> which trigger B5, and has an unexpected frontmatter property which triggers W2.

4 0
Explore
basher83/agent-auditor

skill-factory

Research-backed skill creation workflow with automated firecrawl research gathering, multi-tier validation, and comprehensive auditing. Use when "create skills with research automation", "build research-backed skills", "validate skills end-to-end", "automate skill research and creation", needs 8-phase workflow from research through final audit, wants firecrawl-powered research combined with validation, or requires quality-assured skill creation following Anthropic specifications for Claude Code.

4 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results