coding

Claude Code Has Hidden Hook System for Auto-Linting

Claude Code includes a hidden hook system that automatically runs linting tools on code changes, helping developers maintain code quality and catch errors

Someone found that Claude Code has a hook system that runs scripts automatically before or after tool calls - super useful for auto-linting or security checks.

Drop a .claude/settings.json in your project:

{
 "hooks": {
 "PostToolUse": [{
 "matcher": "Edit|Write",
 "hooks": [{ "type": "command", "command": "./scripts/lint.sh" }]
 }],
 "PreToolUse": [{
 "matcher": "Bash",
 "hooks": [{ "type": "command", "command": "./scripts/security-check.sh" }]
 }]
 }
}

The hooks receive JSON on stdin with the full tool input. If your script exits with code 2, it blocks the action entirely.

Pretty handy for building guardrails - like preventing Claude from running sketchy bash commands or automatically checking code style after every file edit. No more manually reviewing every single change.