Hooks: Automating the Development Loop
Configure lifecycle hooks to auto-format, type-check, and enforce standards on every change.
What Are Hooks?
Hooks are automated scripts that run at specific points in the Claude Code lifecycle. They enforce quality standards without relying on remembering to run checks manually.
Hook Types
PreToolUse — runs before a tool executes. Use to validate, block dangerous operations, or modify parameters.
PostToolUse — runs after a tool executes. Use to format code, run type checks, or log changes.
Stop — runs when a session ends. Use for final audits: check for console.log statements, verify test coverage, save session state.
PreCompact — runs before context compaction. Use to save critical state.
Common Hook Configurations
Auto-format TypeScript on every edit:
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{"type": "command", "command": "prettier --write $TOOL_INPUT_FILE"}]
}]
}
}
Block force pushes:
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{"type": "command", "command": "echo $TOOL_INPUT_COMMAND | grep -q 'force' && exit 1 || exit 0"}]
}]
}
}
ECC Hooks
The ECC harness includes pre-configured hooks:
- Auto-format JS/TS files after edit
- TypeScript check after editing .ts/.tsx files
- console.log warning in edited files
- PR logging after git operations
- Cost tracking on session end
Hooks vs Manual Reminders
Hooks are reliable; reminders aren't. Any quality standard that matters should be a hook. Manual "remember to run X" instructions are forgotten under pressure. Encode the standard, don't rely on memory.
Configure hooks in ~/.claude/settings.json for global standards, or in .claude/settings.json for project-specific rules.