Auto-formatting Python Code

toml

[[hooks]] event = "PostToolUse" [hooks.matcher] tool_name = "edit_file" file_paths = ["*.py"] command = "black $CLAUDE_FILE_PATHS && ruff check --fix $CLAUDE_FILE_PATHS"

Why useful: Ensures consistent code formatting without manual intervention

Automatic Testing

toml

[[hooks]] event = "PostToolUse" run_in_background = true [hooks.matcher] tool_name = "edit_file" file_paths = ["src/**/*.py", "tests/**/*.py"] command = "pytest"

Why useful: Runs tests immediately after code changes, catches regressions early

Security Validation

toml

[[hooks]] event = "PreToolUse" [hooks.matcher] tool_name = "Edit|MultiEdit|Write" command = "python3 -c \\"import json, sys; data=json.load(sys.stdin); path=data.get('tool_input',{}).get('file_path',''); sys.exit(2 if any(p in path for p in ['.env', 'package-lock.json', '.git/']) else 0)\\""

Why useful: Prevents accidental modification of sensitive files

Git Commit Automation

toml

[[hooks]] event = "Stop" command = "git add -A && git commit -m 'Auto-commit: $(date)' || true"

Why useful: Automatic commit creation after task completion for backup

Notification with TTS

toml

[[hooks]] event = "Notification" command = "say 'Claude needs your input' && notify-send 'Claude Code' 'Awaiting input'"

Why useful: Audio and visual alerts when Claude needs attention