Master Claude Code hooks for deterministic AI control
New!
Top 51.3% on sourcepulse
This repository demonstrates how to leverage Claude Code hooks for deterministic control over AI agent behavior, targeting developers and power users of Anthropic's Claude Code CLI. It provides a comprehensive framework for intercepting and modifying agent interactions, enhancing security, and enabling custom workflows through a structured hook system.
How It Works
The project utilizes Claude Code's hook lifecycle, which allows custom Python scripts to intercept 8 distinct events: UserPromptSubmit
, PreToolUse
, PostToolUse
, Notification
, Stop
, SubagentStop
, PreCompact
, and SessionStart
. Each hook can log events, validate inputs/outputs, inject context, or block execution using specific exit codes and JSON payloads. The architecture relies on UV single-file scripts for isolated, portable hook logic with self-declared dependencies, simplifying environment management and execution.
Quick Start & Requirements
pip install astral-uv
.Highlighted Details
UserPromptSubmit
hook allows prompt validation, security filtering, and context injection.PreToolUse
hook enables blocking of dangerous commands like rm -rf
.Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
The chat.json
file only contains the most recent conversation transcript and is overwritten with each new session, unlike other logs which are appended. Some hooks, like PostToolUse
and Notification
, cannot block execution.
5 days ago
Inactive