Claude Code hook

Claude Code Hooks Mastery

Reference project demonstrating every Claude Code hook event with working Python scripts for logging, blocking and TTS.

3,972 stars 640 forksHooks Source

Install

From source
git clone https://github.com/disler/claude-code-hooks-mastery.git

From the README

Claude Code Hooks Mastery

Claude Code Hooks - Quickly master how to use Claude Code hooks to add deterministic (or non-deterministic) control over Claude Code's behavior. Plus learn about Claude Code Sub-Agents, the powerful Meta-Agent, and Team-Based Validation with agent orchestration.

Table of Contents

- Prerequisites
- Hook Lifecycle & Payloads
- What This Shows
- UV Single-File Scripts Architecture
- Key Files
- Features Demonstrated
- Hook Error Codes & Flow Control
- UserPromptSubmit Hook Deep Dive
- Claude Code Sub-Agents
- Team-Based Validation System
- Output Styles Collection
- Custom Status Lines

Prerequisites

This requires:
- Astral UV - Fast Python package installer and resolver
- Claude Code - Anthropic's CLI for Claude AI

Optional Setup:

Optional:
- ElevenLabs - Text-to-speech provider (with MCP server integration)
- ElevenLabs MCP Server - MCP server for ElevenLabs
- Firecrawl MCP Server - Web scraping and crawling MCP server (my favorite scraper)
- OpenAI - Language model provider + Text-to-speech provider
- Anthropic - Language model provider
- Ollama - Local language model provider

Hook Lifecycle & Payloads

This demo captures all 13 Claude Code hook lifecycle events with their JSON payloads:

Hook Lifecycle Overview

1. UserPromptSubmit Hook
Fires: Immediately when user submits a prompt (before Claude processes it)
Payload: prompt text, session_id, timestamp
Enhanced: Prompt validation, logging, context injection, security filtering

2. PreToolUse Hook
Fires: Before any tool execution
Payload: tool_name, tool_input parameters
Enhanced: Blocks dangerous commands (rm -rf, .env access)

3. PostToolUse Hook
Fires: After successful tool completion
Payload: tool_name, tool_input, tool_response with results

4. Notification Hook
Fires: When Claude…
Read the full README on GitHub

How hooks work

  • Hooks are shell commands Claude Code runs at fixed points: before or after a tool call, when you submit a prompt, when Claude stops, on notifications and at session start.
  • They are set in the hooks section of ~/.claude/settings.json (or .claude/settings.json for a project), or come bundled in a plugin.
  • A hook can block a tool call, add context, or run a formatter or test. Read the scripts before you install them: they run on your machine with your permissions.
Claude Code docs

Details

Type
Hooks
Language
Python
Last updated
4 March 2026

FAQ

What is Claude Code Hooks Mastery?

Reference project demonstrating every Claude Code hook event with working Python scripts for logging, blocking and TTS. It is a hook for Claude Code, from disler/claude-code-hooks-mastery on GitHub.

How do I install Claude Code Hooks Mastery?

Clone disler/claude-code-hooks-mastery from GitHub and follow the setup steps in its README.

Is Claude Code Hooks Mastery popular?

disler/claude-code-hooks-mastery has 3,972 GitHub stars and 640 forks, and is included in 3 curated Claude Code lists. It was last updated on 4 March 2026.

More hooks

Browse the most popular Claude Code mods, all hooks, or the skills and MCP server directories.