Development Workflow Hooks

Automatic Code Formatting (Multi-language)

toml

`[[hooks]] event = "PostToolUse" run_in_background = true

[hooks.matcher] tool_name = "edit_file"

[hooks.conditional] if_file_matches = "*.py" command = "black $CLAUDE_FILE_PATHS && isort $CLAUDE_FILE_PATHS && flake8 $CLAUDE_FILE_PATHS"

[hooks.conditional] if_file_matches = "*.{js,ts,jsx,tsx}" command = "npx prettier --write $CLAUDE_FILE_PATHS && npx eslint --fix $CLAUDE_FILE_PATHS"

[hooks.conditional] if_file_matches = "*.go" command = "gofmt -w $CLAUDE_FILE_PATHS && golint $CLAUDE_FILE_PATHS"`

Smart Testing with Coverage

toml

`[[hooks]] event = "PostToolUse" run_in_background = true timeout = 300

[hooks.matcher] tool_name = "edit_file" file_paths = ["src//*", "lib//*"]

[hooks.conditional] if_file_matches = "*.py" command = """ pytest --cov=. --cov-report=term-missing --cov-fail-under=80 || echo "⚠️ Coverage below 80% - consider adding tests" """

[hooks.conditional] if_file_matches = "*.{js,ts}" command = """ npm test -- --coverage --watchAll=false || echo "⚠️ Tests failed - check console output" """`

Git Integration with Smart Commits

toml

`[[hooks]] event = "Stop" timeout = 30

[hooks.matcher] # Only run if files were actually modified command = """ if [ -n "$(git status --porcelain)" ]; then git add -A CHANGED_FILES=$(git diff --cached --name-only | head -5 | tr '\n' ' ') git commit -m "Auto-commit: Modified $CHANGED_FILES - $(date '+%H:%M')" || true echo "✅ Auto-committed changes" else echo "ℹ️ No changes to commit" fi """`

Security Validation with Detailed Feedback

toml

`[[hooks]] event = "PreToolUse" timeout = 10

[hooks.matcher] tool_name = "edit_file|create_file|write_file"

command = """ python3 -c " import json, sys, os data = json.loads(sys.stdin.read()) file_path = data.get('tool_input', {}).get('file_path', '')

# Security checks dangerous_patterns = ['.env', '.secret', 'id_rsa', 'package-lock.json', '.git/'] sensitive_dirs = ['node_modules/', '.next/', 'dist/', 'build/']

if any(pattern in file_path.lower() for pattern in dangerous_patterns): print(f'🚫 Blocked: {file_path} matches sensitive file pattern') sys.exit(2)

if any(dir in file_path for dir in sensitive_dirs): print(f'🚫 Blocked: {file_path} in protected directory') sys.exit(2)

print(f'✅ Security check passed for {file_path}') "`

Notification and Integration Hooks

Multi-Platform Notifications

toml

`[[hooks]] event = "Notification" timeout = 5

command = """

macOS

if command -v osascript >/dev/null; then osascript -e 'display notification "Claude needs input" with title "Claude Code"' say "Claude needs your input" & fi

Linux

if command -v notify-send >/dev/null; then notify-send "Claude Code" "Awaiting your input" fi

Windows (WSL)

if command -v powershell.exe >/dev/null; then powershell.exe -Command " Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.MessageBox]::Show('Claude needs input', 'Claude Code') " fi """`

Slack Integration for Team Updates

toml

`[[hooks]] event = "PostToolUse" run_in_background = true

[hooks.matcher] tool_name = "edit_file" file_paths = ["src/**/*"]

[hooks.conditional] if_env_var = "SLACK_WEBHOOK_URL" command = """ curl -X POST "$SLACK_WEBHOOK_URL" \ -H 'Content-type: application/json' \ --data "{ \"text\": \"🔧 Code updated by Claude in $(basename $PWD)\", \"attachments\": [{ \"color\": \"good\", \"fields\": [{ \"title\": \"Files Modified\", \"value\": \"$(echo $CLAUDE_FILE_PATHS | tr ' ' '\n' | head -3 | paste -sd, -)\" }] }] }" || echo "Failed to send Slack notification" """`