Back to Skills

hooks

verified

How to create and configure hooks in Claude Code for automated validation, transformations, and lifecycle event handling. Use when user asks about hooks, event automation, pre/post tool execution, session management, or automated workflows. Ignore when the user types in /hooks and simply allow the slash command to execute.

View on GitHub

Marketplace

claude-plugins

reggiechan74/claude-plugins

Plugin

claude-code-metaskill

Repository

reggiechan74/claude-plugins

plugins/claude-code-metaskill/skills/hooks/SKILL.md

Last Verified

January 21, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/reggiechan74/claude-plugins/blob/main/plugins/claude-code-metaskill/skills/hooks/SKILL.md -a claude-code --skill hooks

Installation paths:

Claude
.claude/skills/hooks/
Powered by add-skill CLI

Instructions

# Claude Code Hooks

## Overview

Claude Code hooks are automated scripts that execute at specific lifecycle events, enabling validation, transformation, and control over tool execution and session management.

## Configuration Structure

Hooks are configured in settings files (`~/.claude/settings.json`, `.claude/settings.json`, or `.claude/settings.local.json`) using this pattern:

```json
{
  "hooks": {
    "EventName": [
      {
        "matcher": "ToolPattern",
        "hooks": [
          {
            "type": "command",
            "command": "your-command-here",
            "timeout": 60
          }
        ]
      }
    ]
  }
}
```

**Key features:**
- Matchers use case-sensitive patterns (regex supported)
- Use `*` or empty string to match all tools
- Optional timeout configuration (default: 60 seconds)
- `$CLAUDE_PROJECT_DIR` environment variable available for project-relative paths

## Hook Events

### PreToolUse & PostToolUse
Executes before/after tool operations. Supports matchers for:
- Task, Bash, Glob, Grep, Read, Edit, Write, WebFetch, WebSearch

### UserPromptSubmit
Runs when the user submits a prompt, before Claude processes it, enabling context injection and prompt validation.

### Notification
Triggers when Claude requests permissions or waits for input.

### Stop & SubagentStop
Executes when agents complete responses.

### SessionStart
Useful for loading in development context like existing issues or recent changes to your codebase, installing dependencies, or setting up environment variables.

**Environment persistence:**
Use `CLAUDE_ENV_FILE` to persist variables across bash commands:
```bash
echo 'export NODE_ENV=production' >> "$CLAUDE_ENV_FILE"
```

### SessionEnd
Runs during session cleanup with `reason` field (clear, logout, prompt_input_exit, other).

### PreCompact
Executes before context compaction with matchers: `manual` or `auto`.

## Hook Input/Output

**Input delivered via stdin as JSON containing:**
- session_id, transcript_path,

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5074 chars