Skip to content

Hooks & Automation

Hooks let you run shell commands automatically in response to Claude Code events. They’re the bridge between Claude’s actions and your custom tooling.

Hooks are shell commands that execute when specific events occur in Claude Code. Think of them like git hooks, but for AI actions.

Hooks are defined in your settings files:

  • ~/.claude/settings.json — global hooks
  • .claude/settings.json — project-specific hooks
{
"hooks": {
"tool_call": [
{
"tool": "Write",
"command": "echo 'File written: $FILE_PATH' >> /tmp/claude-log.txt"
}
],
"prompt_submit": [
{
"command": "echo 'Prompt submitted at $(date)' >> /tmp/claude-log.txt"
}
]
}
}
EventWhen It Fires
tool_callBefore a tool is executed
prompt_submitWhen you submit a message
session_startWhen a Claude session begins

Run Prettier whenever Claude writes a file:

{
"hooks": {
"tool_call": [
{
"tool": "Write",
"command": "npx prettier --write $FILE_PATH"
}
]
}
}

Run ESLint after Claude edits a JavaScript/TypeScript file:

{
"hooks": {
"tool_call": [
{
"tool": "Edit",
"pattern": "*.{js,ts,jsx,tsx}",
"command": "npx eslint --fix $FILE_PATH"
}
]
}
}

Log all Claude actions for review:

{
"hooks": {
"tool_call": [
{
"command": "echo \"$(date): $TOOL_NAME on $FILE_PATH\" >> .claude/audit.log"
}
]
}
}
HooksSkills
TriggerAutomatic (event-driven)Manual (you invoke them)
PurposeSide effects and guardrailsComplete workflows
ExamplesAuto-format, lint, logDeploy, review, commit
ScopeIndividual tool callsMulti-step processes
  • Code quality enforcement — auto-lint and format
  • Security guardrails — block writes to sensitive directories
  • Logging and auditing — track what Claude does
  • Integration triggers — notify Slack, update tickets
  • Build validation — run type checks after edits
  1. Add a simple logging hook to your project’s .claude/settings.json
  2. Run a Claude session and make some changes
  3. Check the log to see what was captured
  4. Add a formatting hook for your preferred language