New advertisers: 50% off your first month with code FIRSTMONTHSee slots
anthropics avatar

Hook Development

Guide for writing Claude Code plugin hooks, covering prompt-based and command hook types across lifecycle events.

skills.sh installs
7.8K
GitHub stars
47.9K
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers prompt-based and command hook types for PreToolUse, PostToolUse, Stop, SubagentStop, UserPromptSubmit, SessionStart, SessionEnd, PreCompact, and Notification events
  • Includes JSON configuration formats for both plugin hooks/hooks.json files and .claude/settings.json, plus input fields, output schemas, and exit codes
  • Recommends ${CLAUDE_PLUGIN_ROOT} for portable command paths and $CLAUDE_ENV_FILE for persisting environment variables at session start
  • Designed for plugin authors who need to validate tool calls, block dangerous commands, or enforce completion standards

Install

$ npx -y skills add anthropics/claude-plugins-official --skill hook-development -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Hook Development for Claude Code Plugins

Overview

Hooks are event-driven automation scripts that execute in response to Claude Code events. Use hooks to validate operations, enforce policies, add context, and integrate external tools into workflows.

Key capabilities:

  • Validate tool calls before execution (PreToolUse)
  • React to tool results (PostToolUse)
  • Enforce completion standards (Stop, SubagentStop)
  • Load project context (SessionStart)
  • Automate workflows across the development lifecycle

Hook Types

Prompt-Based Hooks (Recommended)

Use LLM-driven decision making for context-aware validation:

{
  "type": "prompt",
  "prompt": "Evaluate if this tool use is appropriate: $TOOL_INPUT",
  "timeout": 30
}

Supported events: Stop, SubagentStop, UserPromptSubmit, PreToolUse

Benefits:

  • Context-aware decisions based on natural language reasoning
  • Flexible evaluation logic without bash scripting
  • Better edge case handling
  • Easier to maintain and extend

Command Hooks

Execute bash commands for deterministic checks:

{
  "type": "command",
  "command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh",
  "timeout": 60
}

Details

Repository
github.com/anthropics/claude-plugins-official
Category
Skill & Plugin Building
First seen
May 16, 2026

More from anthropics/claude-plugins-official

All 23

Similar to Hook Development

More Skill & Plugin Building