Security Reminder Hook
This hook warns about potential security issues when editing files. Used in thesecurity-guidance plugin.
Configuration
hooks.json
Implementation
security_reminder_hook.py
Key Features
- Session-scoped warnings - Only shows each warning once per session
- Pattern matching - Checks both file paths and content
- Configurable - Can be disabled via
ENABLE_SECURITY_REMINDER=0 - Exit code 2 - Blocks execution but allows Claude to see the warning
Bash Command Validator
Validates bash commands and suggests better alternatives.Configuration
hooks.json
Implementation
bash_command_validator.py
Usage
When Claude tries to usegrep:
Ralph Wiggum Loop Hook
Implements continuous self-referential AI loops by blocking session exit.Configuration
hooks.json
Implementation (Simplified)
stop-hook.sh
How It Works
- State file -
.claude/ralph-loop.local.mdcontains iteration count and prompt - Stop interception - Hook runs when user tries to exit
- Loop control - Checks iteration limit and completion promise
- Prompt feedback - Feeds the same prompt back to continue loop
- Exit conditions - Max iterations or completion promise detected
Usage
HTTP Audit Hook
Posts tool usage to external audit system.Configuration
hooks.json
Request Body
Response
Session Setup Hook
Configures environment on session start.Configuration
hooks.json
Implementation
setup-session.sh
Worktree Setup Hook
Configures newly created git worktrees.Configuration
hooks.json
Implementation
setup-worktree.sh
Best Practices Demonstrated
Error handling
Error handling
All examples include:
set -euo pipefailin bash scripts- try/except blocks in Python
- Graceful fallbacks for missing data
- Clear error messages to stderr
State management
State management
- Session-scoped state files
- Cleanup of old state
- Atomic file operations
- Fallback to defaults when state missing
Performance
Performance
- Fast validation checks first
- Background processes for slow work
- Caching when appropriate
- Minimal I/O operations
User experience
User experience
- Clear, actionable error messages
- Emoji indicators for status
- Informative stderr output
- Appropriate exit codes
Next Steps
Configuration Files
Learn about settings.json and configuration
Plugin Development
Create plugins with custom hooks