Automate Repetitive Tasks with Hooks
Hooks are shell commands that execute automatically in response to Claude Code events. Configure them in your settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "vendor/bin/pint --dirty"
}
]
}
]
}
}
This example automatically runs Pint after every file edit — so your code is always formatted without you having to remember.
Available hook events:
- PreToolUse — runs before a tool executes
- PostToolUse — runs after a tool completes
- Stop — runs when Claude finishes its turn and returns control to you
The matcher field is a regex matched against the tool name (Write, Edit, Bash, etc.). Use ".*" to match all tools, or pipe-separate specific ones.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "vendor/bin/pint --dirty"
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "echo 'Running a shell command...'"
}
]
}
]
}
}
Hooks run synchronously — a PostToolUse hook fires before Claude moves to the next step, making it perfect for linting, formatting, or running a quick type-check after every change.
Use /update-config to set these up interactively, or just ask Claude to write the hook configuration for your specific needs.
Hooks turn repetitive quality steps into automatic ones — set them once and forget them.
Log in to leave a comment.
When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.
Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.
Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.