CC-101 · Module 4

Hooks & Automation

3 min read

Hooks are pre/post execution interceptors — similar to git hooks. They run before, after, or on failure of Claude actions.

Like GitHub's pre-commit hooks but for Claude Code actions. You can run validation before execution, cleanup after execution, or error handling on failure. Don't create these manually — ask Claude to set them up.

Use PostToolUse hooks to automatically run linting and formatting after Claude edits files.

Set up a post-tool-use hook that runs your formatter (Prettier, Black, SwiftFormat, etc.) after every file edit. This keeps code clean without Claude needing to know your formatting rules.

Use hooks to prevent destructive operations like database deletion, rm -rf, or other irreversible commands.

Safety guardrails for production environments. Set up pre-execution hooks that block or require confirmation for dangerous operations. Essential for real work environments, even if you skip it for side projects.