Generate production-ready Claude Code hooks with interactive Q&A, automated installation, and enhanced validation. Supports 10 templates across 7 event types for comprehensive workflow automation.
✅ Tool detection (checks if required tools are installed)
✅ Silent failure mode (never interrupts your workflow)
✅ Appropriate timeout settings (5s-120s based on event type)
✅ No destructive operations
✅ Comprehensive validation before generation
✅ Clear documentation and troubleshooting guides
✅ Automatic backup during installation
How to Invoke
Natural Language Requests
Simply describe what you want the hook to do:
"I want to auto-format Python files after editing"
"Create a hook that runs tests when agents complete"
"Auto-add files to git after editing"
"Load my TODO.md at session start"
Explicit Template Selection
If you know which template you want:
"Generate a hook using the post_tool_use_format template for JavaScript"
"Create a test runner hook for Rust"
List Available Templates
"Show me all available hook templates"
"List hook templates"
Example Interactions
Example 1: Auto-Format Python
You: "I need a hook to auto-format my Python code after editing"
Hook Factory:
Detects template: post_tool_use_format
Detects language: Python
Generates hook with black formatter
Validates configuration
Saves to generated-hooks/auto-format-code-after-editing-python/
Creates hook.json and README.md
Example 2: Git Auto-Add
You: "Automatically stage files with git when I edit them"
Hook Factory:
Detects template: post_tool_use_git_add
Generates git auto-add hook
Validates git commands
Saves to generated-hooks/auto-add-files-to-git-after-editing/
Example 3: Test Runner
You: "Run my JavaScript tests after the agent finishes coding"
Hook Factory:
Detects template: subagent_stop_test_runner
Detects language: JavaScript
Configures jest/npm test
Saves to generated-hooks/run-tests-when-agent-completes-javascript/
cd generated-skills/hook-factory
# Install to user level (~/.claude/settings.json)
python3 installer.py install generated-hooks/[hook-name] user
# Install to project level (.claude/settings.json)
python3 installer.py install generated-hooks/[hook-name] project
# Uninstall
python3 installer.py uninstall [hook-name] user
# List installed hooks
python3 installer.py list user
Using Bash Script (macOS/Linux):
cd generated-skills/hook-factory
# Install
./install-hook.sh generated-hooks/[hook-name] user
# Features:
# - Automatic backup with timestamp
# - JSON validation before/after
# - Atomic write operations
# - Rollback on failure
# - Keeps last 5 backups
Auto-Install from Interactive Mode:
Answer 'y' to Q7 (Auto-Install)
Hook is automatically installed
No manual steps required
Manual Installation (Legacy)
Review Generated Files
cd generated-hooks/[hook-name]
cat README.md
cat hook.json
Manual Installation
Open .claude/settings.json (project) or ~/.claude/settings.json (user)
Copy the hook configuration from hook.json
Add to the appropriate event type array
Save and restart Claude Code
Verify
Check Claude Code logs: ~/.claude/logs/
Test the hook by performing the trigger action
Validation
Every hook is validated for:
JSON Syntax: Valid, parseable JSON
Structure: Required fields present and correct types
Safety: No destructive operations (rm -rf, etc.)
Tool Detection: External tools have detection checks
Silent Failure: Commands won't interrupt workflow
Timeouts: Appropriate for event type
Matchers: Valid glob patterns and tool names
Best Practices
Start Simple: Use natural language requests for common patterns
Review Before Installing: Always read the generated README.md
Test in Isolation: Try hooks in a test project first
Customize Gradually: Start with defaults, customize later
Monitor Logs: Check ~/.claude/logs/ if hooks aren't working
Limitations
Platform Support:
✅ macOS and Linux fully supported
❌ Windows not supported (Unix commands, bash-specific syntax)
Customization:
Interactive mode provides smart defaults but limited deep customization
Advanced users should use template mode + manual editing
No GUI - CLI only
Template System:
10 templates cover common patterns
Custom templates require manual addition to templates.json
No template composition yet (combining multiple patterns)
Technical Details
Files in This Skill
Core Files:
SKILL.md - This manifest file
hook_factory.py - Main orchestrator with CLI interface (687 lines)
generator.py - Template substitution and hook generation
Use more specific keywords (format, test, git add, load)
Or use explicit template selection
Or list templates to see what's available
Generated hook not working
Check Claude Code logs
Verify required tools are installed
Test command manually in terminal
Review README.md troubleshooting section
Validation errors
Review error messages and fix suggestions
Common issues: missing tool detection, destructive commands
Modify template if needed
Examples Directory
The examples/ directory contains reference implementations:
examples/
├── auto-format-python/ # PostToolUse format example
├── git-auto-add/ # PostToolUse git example
├── test-runner/ # SubagentStop test example
└── load-context/ # SessionStart context example
Each example includes working hook.json and README.md files you can copy directly.