This directory contains security and workflow hooks for Claude Code that provide enterprise-grade governance and automation.
Purpose: Simple demonstration of hook functionality without security implications.
Features:
- ✅ Logs file operations (Edit, Write, MultiEdit tools)
- ✅ Shows file information (size, lines, type)
- ✅ Non-blocking - always allows operations to proceed
- ✅ Perfect for learning how hooks work
Configuration:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "./hooks/file-logger.sh",
"blocking": false,
"timeout": 5000
}
]
}
]
}
}Log Location: ~/.claude/logs/file-logger.log
Purpose: Prevents accidental credential exposure in AI-generated or AI-modified code.
Features:
- ✅ Detects 15+ credential patterns (API keys, tokens, passwords, private keys)
- ✅ Blocks dangerous operations with detailed warnings
- ✅ Comprehensive logging and audit trails
- ✅ Security team notifications via webhooks
- ✅ Emergency override capability for authorized users
- ✅ Environment variable and URL credential detection
Configuration:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "./hooks/prevent-credential-exposure.sh",
"blocking": true,
"timeout": 10000
}
]
}
]
}
}Environment Variables:
SECURITY_WEBHOOK_URL: Optional Slack/Teams webhook for security alertsCLAUDE_SECURITY_OVERRIDE: Emergency override (use with extreme caution)
# Copy to Claude Code hooks directory
cp hooks/file-logger.sh ~/.claude/hooks/
# Make executable
chmod +x ~/.claude/hooks/file-logger.sh
# Configure in ~/.claude/settings.json# Use relative path in project settings
# Add to .claude/settings.json in your project{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/file-logger.sh",
"blocking": false
}
]
}
]
}
}# Set webhook for security alerts
export SECURITY_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"
# Add to your shell profile for persistence
echo 'export SECURITY_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"' >> ~/.zshrc# Create a test file with a fake API key
echo 'API_KEY="sk-ant-1234567890abcdef"' > test-credentials.txt
# Try to edit with Claude Code - should be blocked
claude edit test-credentials.txt# Create a test file with environment exposure
echo 'const apiKey = process.env.SECRET_API_KEY;' > test-env.js
# Try to edit with Claude Code - should be blocked
claude edit test-env.js# Enable override (use sparingly!)
export CLAUDE_SECURITY_OVERRIDE=true
# Now the operation will proceed with warnings
claude edit test-credentials.txt
# Disable override immediately after
unset CLAUDE_SECURITY_OVERRIDEThe hook detects these credential patterns:
- Anthropic API Keys:
sk-ant-... - OpenAI API Keys:
sk-... - GitHub Tokens:
ghp_...,gho_... - AWS Access Keys:
AKIA... - Database URLs:
postgres://user:pass@host - JWT Tokens:
eyJ... - Private Keys:
-----BEGIN PRIVATE KEY----- - Generic API Keys: Pattern-based detection
- Environment Variable Exposure:
process.env.SECRET_*
- General Hook Logs:
~/.claude/logs/security-hooks.log - Security Violations:
~/.claude/logs/credential-violations.log
# View recent security events
tail -f ~/.claude/logs/security-hooks.log
# Check for violations
cat ~/.claude/logs/credential-violations.log
# Count violations by type
grep "VIOLATION:" ~/.claude/logs/credential-violations.log | cut -d: -f3 | sort | uniq -c- Always Review: Examine the detected pattern before overriding
- Use Environment Variables: Store credentials in environment variables
- Secrets Management: Use proper secrets management systems (1Password, HashiCorp Vault, etc.)
- Emergency Override: Only use
CLAUDE_SECURITY_OVERRIDEin genuine emergencies - Regular Audits: Review violation logs regularly for patterns
- Team Training: Educate team on secure coding practices
- Verify executable permissions:
ls -la ~/.claude/hooks/ - Check Claude Code settings:
cat ~/.claude/settings.json - Review hook logs:
tail ~/.claude/logs/security-hooks.log
- Review the detected pattern in logs
- Consider if the pattern is actually a security risk
- Use environment variables instead of hardcoded values
- Add file to
.gitignoreif it's test data
- The hook runs quickly but can be optimized for large files
- Consider adding file size limits if needed
- Use async execution for non-blocking notifications
To add new credential patterns or improve detection:
- Add new patterns to the
CREDENTIAL_PATTERNSarray - Test with realistic examples
- Update documentation
- Submit changes for review
This hook is designed to prevent accidental credential exposure. It should be part of a comprehensive security strategy that includes:
- Proper secrets management
- Regular security training
- Code review processes
- Automated security scanning in CI/CD
- Incident response procedures