This directory contains hooks that execute automatically in response to Claude Code events. These hooks provide extensible automation, logging, and workflow enhancements throughout the development process.
Claude Code hooks are Python scripts that execute at specific points in the interaction lifecycle. They receive structured JSON input via stdin and can optionally provide output to modify behavior or add context. All hooks fail gracefully to ensure Claude Code remains functional even if individual hooks encounter errors.
session_start.py - Session Initialization
- Triggered by: New session startup, session resume, or session clear
- Purpose: Initialize development context, load project information, and optionally announce session start
- Command line options:
--load-context: Load development context from project files (CONTEXT.md, TODO.md, GitHub issues)--announce: Use TTS to announce session start
- Features:
- Git status integration (current branch, uncommitted changes)
- Context file loading (.claude/CONTEXT.md, TODO.md)
- GitHub issues integration via
ghCLI - Session state management
user_prompt_submit.py - Prompt Processing
- Triggered by: User submitting a prompt to Claude
- Purpose: Log prompts, validate input, manage session data, and optionally generate agent names
- Command line options:
--validate: Enable prompt validation for security patterns--log-only: Log prompts without validation--store-last-prompt: Store prompt for status display--name-agent: Generate agent name for the session using LLM
- Features:
- Session data management in JSON format
- Prompt validation and blocking capabilities
- Agent name generation via Anthropic or Ollama
pre_tool_use.py - Tool Execution Safety
- Triggered by: Before each tool execution
- Purpose: Log tool usage and provide safety validation
- Security features (currently commented out for flexibility):
- Dangerous
rm -rfcommand detection .envfile access protection- Comprehensive pattern matching for unsafe operations
- Dangerous
- Logging: Records all tool calls with session context
post_tool_use.py - Tool Execution Tracking
- Triggered by: After each tool execution completes
- Purpose: Log tool results and track execution patterns
- Data captured: Tool responses, execution timing, and session context
pre_compact.py - Conversation Management
- Triggered by: Before conversation history compaction (manual or automatic)
- Purpose: Backup transcripts and log compaction events
- Command line options:
--backup: Create timestamped backup of transcript before compaction--verbose: Display detailed compaction information
- Features:
- Automatic transcript backups to
logs/transcript_backups/ - Compaction trigger tracking (manual vs automatic)
- Custom instruction preservation
- Automatic transcript backups to
stop.py - Main Session Completion
- Triggered by: End of main Claude session
- Purpose: Announce completion, archive transcripts, and generate completion messages
- Command line options:
--chat: Convert transcript to chat.json format--notify: Enable TTS completion announcement
- Features:
- Intelligent TTS service selection (ElevenLabs > OpenAI > pyttsx3)
- LLM-generated completion messages with personalization
- Transcript archival to
logs/chat.json
subagent_stop.py - Subagent Completion
- Triggered by: End of subagent execution
- Purpose: Track subagent completion and provide audio feedback
- Command line options:
--chat: Archive subagent transcript--notify: Announce subagent completion
- Features: Specialized handling for orchestrated subagent workflows
notification.py - User Input Alerts
- Triggered by: When Claude needs user input
- Purpose: Provide audio notifications when user attention is required
- Command line options:
--notify: Enable TTS notifications
- Features:
- Engineer name personalization (30% chance to include name)
- Intelligent TTS service selection
- Contextual notification filtering
Priority-based TTS selection:
- ElevenLabs (
elevenlabs_tts.py) - Highest quality, requires API key - OpenAI (
openai_tts.py) - High quality, requires API key - pyttsx3 (
pyttsx3_tts.py) - Local fallback, no API key required
All TTS scripts accept text as command-line arguments and use UV for dependency management.
anth.py - Anthropic Integration
- Fast Claude 3.5 Haiku model for completion messages and agent names
- Generates personalized completion messages
- Creates unique agent names for sessions
- Command line interface:
--completion,--agent-name
oai.py - OpenAI Integration
- GPT-based completion message generation
- Secondary option for LLM-powered features
ollama.py - Local LLM Integration
- Local model support for offline development
- Preferred for agent name generation (faster, no API costs)
# TTS Services (optional)
ELEVENLABS_API_KEY=your_elevenlabs_key
OPENAI_API_KEY=your_openai_key
# LLM Services (optional)
ANTHROPIC_API_KEY=your_anthropic_key
# Personalization (optional)
ENGINEER_NAME=your_nameHooks are automatically executed by Claude Code based on events. Command-line options control specific behaviors:
# Example hook configurations in Claude Code settings
session_start.py --load-context --announce
user_prompt_submit.py --name-agent --store-last-prompt
pre_compact.py --backup --verbose
stop.py --chat --notifylogs/
├── session_start.json # Session initialization events
├── user_prompt_submit.json # User prompts and validation
├── pre_tool_use.json # Tool execution requests
├── post_tool_use.json # Tool execution results
├── pre_compact.json # Compaction events
├── stop.json # Session completions
├── subagent_stop.json # Subagent completions
├── notification.json # User notification events
├── chat.json # Archived conversation transcripts
└── transcript_backups/ # Pre-compaction transcript backups
.claude/data/sessions/
└── {session_id}.json # Session-specific data with prompts and agent names
- Session Start: Load project context, announce readiness via TTS
- Prompt Processing: Generate agent name, validate input, log interaction
- Tool Safety: Monitor dangerous operations, log all tool usage
- Compaction Safety: Backup transcripts before context compression
- Completion: Generate personalized completion message, archive session
- Subagent completion tracking for multi-agent workflows
- Session data management for agent identity persistence
- Comprehensive logging for debugging complex orchestrations
- Dangerous command detection (configurable)
- Environment file protection
- Comprehensive audit logging
- Graceful error handling to prevent workflow interruption
- Create Python script with UV shebang and dependencies
- Accept JSON input via stdin
- Use command-line arguments for configuration
- Log events to
logs/{hook_name}.json - Fail gracefully with appropriate exit codes
- Follow existing naming and structure conventions
- Add new service script to appropriate
utils/subdirectory - Follow priority-based selection pattern
- Include fallback mechanisms
- Support command-line testing interface
Hooks support project-specific customization through:
- Environment variable configuration
- Command-line argument variations
- Context file integration
- External tool integration (git, gh, etc.)
This hooks system provides a comprehensive foundation for automating and enhancing Claude Code workflows while maintaining flexibility and reliability.