explaingit

disler/claude-code-hooks-mastery

Analysis updated 2026-07-03

3,664PythonAudience · developerComplexity · 3/5Setup · moderate

TLDR

A hands-on guide to all 13 Claude Code hook events, with Python scripts that add safety filters, session logging, audio alerts, and multi-agent coordination to an AI coding session.

Mindmap

mindmap
  root((repo))
    What it does
      Teaches 13 hook events
      Session observability
      AI safety controls
    Hook Types
      UserPromptSubmit
      PreToolUse
      Stop hook
    Use Cases
      Block dangerous commands
      Audio feedback
      Multi-agent workflows
    Tech Stack
      Python UV scripts
      Claude Code
      ElevenLabs TTS
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Block dangerous shell commands like rm -rf before Claude executes them using a PreToolUse hook.

USE CASE 2

Log every tool Claude uses during a session to a JSON file for auditing and replay.

USE CASE 3

Play an AI-generated audio summary through text-to-speech when Claude finishes a response using the Stop hook.

USE CASE 4

Set up a two-agent flow where one Claude instance builds code and a separate validator agent checks quality.

What is it built with?

PythonClaude CodeUVElevenLabsOpenAI

How does it compare?

disler/claude-code-hooks-masterytextualize/rich-cligalaxy-dawn/claude-scholar
Stars3,6643,6653,661
LanguagePythonPythonPython
Setup difficultymoderateeasymoderate
Complexity3/51/52/5
Audiencedeveloperdeveloperresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires Claude Code installed and the UV Python tool, audio summary features need an ElevenLabs or OpenAI API key.

In plain English

This repository teaches you how to use Claude Code hooks, which are custom scripts that run automatically at specific moments during a Claude Code AI coding session. Claude Code is Anthropic's command-line tool for AI-assisted development, and hooks let you attach your own behavior to events like when a session starts, when Claude is about to use a tool, when it finishes responding, or when something goes wrong. The project demonstrates all 13 hook events that Claude Code exposes. A few examples: the UserPromptSubmit hook fires as soon as you submit a message, before Claude even sees it, so you can use it for logging or security filtering. The PreToolUse hook fires before Claude runs any tool, and this repo uses it to block dangerous commands like rm -rf or access to sensitive files like .env. The Stop hook fires when Claude finishes a response, and the example here uses it to play an AI-generated audio summary through text-to-speech. Beyond the hooks themselves, the repository shows how to set up Claude Code sub-agents, which are separate Claude instances that the main Claude can spawn to work on tasks in parallel. There is also a team-based validation pattern where one agent builds code and a separate validator agent checks the quality, with hooks coordinating the flow between them. All the hooks are written as standalone Python scripts using the UV single-file script format, which means each hook can declare its own dependencies without interfering with the rest of the project. The hooks log every event to a JSON file in a logs directory, so you can inspect what Claude did during a session. Audio feedback through ElevenLabs, OpenAI, or a local text-to-speech library is optional. The prerequisites are Claude Code itself and the UV Python tool. The repository is aimed at developers who are already using Claude Code and want more control and observability over what it does. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Write a Claude Code PreToolUse hook in Python using UV single-file format that blocks any shell command containing 'rm -rf' or accessing '.env' files.
Prompt 2
I want a UserPromptSubmit hook that logs every user message and timestamp to a JSON file. Write the UV script.
Prompt 3
How do I configure a Stop hook in Claude Code that calls ElevenLabs to speak a one-sentence summary when Claude finishes a response?
Prompt 4
Show me how to spawn a Claude sub-agent from a main Claude Code session using hooks to validate code quality.
Prompt 5
Write a Claude Code hook that sends a desktop notification whenever Claude uses the Bash tool.

Frequently asked questions

What is claude-code-hooks-mastery?

A hands-on guide to all 13 Claude Code hook events, with Python scripts that add safety filters, session logging, audio alerts, and multi-agent coordination to an AI coding session.

What language is claude-code-hooks-mastery written in?

Mainly Python. The stack also includes Python, Claude Code, UV.

How hard is claude-code-hooks-mastery to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is claude-code-hooks-mastery for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub disler on gitmyhub

Verify against the repo before relying on details.