Documentation Index Fetch the complete documentation index at: https://docs.aitmpl.com/llms.txt
Use this file to discover all available pages before exploring further.
Hook Components
Hooks are automation triggers that execute before or after specific events. They enable automated workflows, validation, and enforcement of best practices.
Browse All Hooks Explore 45+ hooks at aitmpl.com
Installation
# Install a single hook
npx claude-code-templates@latest --hook git/conventional-commits
# Install multiple hooks
npx claude-code-templates@latest --hook git/conventional-commits --hook security/secret-scanner
# Install from specific category
npx claude-code-templates@latest --hook security/dangerous-command-blocker
Hook Categories
Git
Security
Testing
Git Workflow
Automation
Pre/Post Tool
Performance
Monitoring
Git Hooks Automate git workflows and enforce commit standards:
Conventional Commits Enforce conventional commit message format npx claude-code-templates@latest --hook git/conventional-commits
Validates:
Commit message format (feat:, fix:, docs:, etc.)
Scope and description
Breaking change notation
Prevent Direct Push Block direct pushes to protected branches npx claude-code-templates@latest --hook git/prevent-direct-push
Protects:
main/master branches
production branches
Enforces PR workflow
Validate Branch Name Enforce branch naming conventions npx claude-code-templates@latest --hook git/validate-branch-name
Enforces:
feature/, bugfix/, hotfix/ prefixes
Lowercase with hyphens
Ticket/issue references
Security Hooks Prevent security vulnerabilities and secrets leakage:
Secret Scanner Scan commits for hardcoded secrets and API keys npx claude-code-templates@latest --hook security/secret-scanner
Detects:
API keys and tokens
Private keys and certificates
Database credentials
OAuth secrets
Dangerous Command Blocker Block dangerous commands and operations npx claude-code-templates@latest --hook security/dangerous-command-blocker
Blocks:
Force pushes to main
Destructive operations
Unsafe shell commands
Security Scanner Run security scans before commits npx claude-code-templates@latest --hook security/security-scanner
File Protection Protect sensitive files from being committed npx claude-code-templates@latest --hook security/file-protection
Testing Hooks Automate test execution and validation:
Test Runner Run tests automatically before commits npx claude-code-templates@latest --hook testing/test-runner
Features:
Pre-commit test execution
Changed file detection
Test coverage validation
Git Workflow Hooks Advanced git flow automation:
Branch Protection Protect important branches from accidental changes npx claude-code-templates@latest --hook git-workflow/branch-protection
Commit Linting Lint commit messages for quality npx claude-code-templates@latest --hook git-workflow/commit-linting
Automation Hooks General automation and notifications:
Simple Notifications Send notifications on key events npx claude-code-templates@latest --hook automation/simple-notifications
Changelog Generator Auto-generate changelog entries npx claude-code-templates@latest --hook automation/changelog-generator
Execute before or after Claude Code tools:
Pre-Tool Validation Validate context before tool execution npx claude-code-templates@latest --hook pre-tool/validation
Post-Tool Cleanup Clean up after tool execution npx claude-code-templates@latest --hook post-tool/cleanup
Monitor and optimize performance:
Bundle Size Check Warn on bundle size increases npx claude-code-templates@latest --hook performance/bundle-size-check
Performance Monitor Track operation performance npx claude-code-templates@latest --hook performance/monitor
Monitoring Hooks Track events and metrics:
Error Tracking Track and report errors npx claude-code-templates@latest --hook monitoring/error-tracking
Usage Analytics Collect usage analytics npx claude-code-templates@latest --hook monitoring/usage-analytics
Hook Types
Pre-Commit Hooks
Run before a commit is created:
Validate commit messages
Run linters and formatters
Check for secrets
Run tests
Pre-Push Hooks
Run before pushing to remote:
Run full test suite
Check branch protection
Validate no uncommitted changes
Run before Claude Code tool execution:
Validate environment
Check permissions
Load context
Post-Tool Hooks
Run after Claude Code tool execution:
Clean up temporary files
Update metrics
Send notifications
Hook Configuration
Hooks are stored in .claude/hooks/:
{
"name" : "conventional-commits" ,
"description" : "Enforce conventional commit messages" ,
"trigger" : "pre-commit" ,
"command" : "python" ,
"args" : [ ".claude/scripts/conventional-commits.py" ]
}
Python Script Hooks
Many hooks use Python scripts for complex logic:
# .claude/scripts/secret-scanner.py
import re
import sys
patterns = [
r ' (?i) ( api [ _- ] ? key | apikey ) \s * = \s * [ " \' ][ ^ " \' ] ' ,
r ' (?i) ( password | passwd ) \s * = \s * [ " \' ][ ^ " \' ] ' ,
# ... more patterns
]
def scan_file ( filepath ):
with open (filepath) as f:
content = f.read()
for pattern in patterns:
if re.search(pattern, content):
return True
return False
Example Usage
# Install conventional commits hook
npx claude-code-templates@latest --hook git/conventional-commits
# Now all commits must follow conventional format
git commit -m "feat: add user authentication"
# ✓ Valid
git commit -m "Added authentication"
# ✗ Rejected - must use conventional format
Disabling Hooks
Temporarily bypass hooks when needed:
# Skip git hooks
git commit --no-verify -m "emergency fix"
# Disable specific hook
chmod -x .claude/hooks/conventional-commits.json
Creating Custom Hooks
Create your own hooks:
Create JSON config in .claude/hooks/
Create Python script in .claude/scripts/ (if needed)
Test the hook
Share with your team
Next Steps