Hooks: Build Your Custom Workflow
Insert custom logic at every stage of Claude Code's tool calls — auto-format, test, review, and secure — all automated
What are Claude Code Hooks?
Hooks are Claude Code's event system that lets you run custom shell scripts before and after tool calls. Automatically run linters after file saves, execute tests before commits, or trigger alerts on sensitive file access — all without manual intervention.
seo_hooks.what_is_desc2
Hook Types Explained
Claude Code provides four Hook types covering the complete tool call lifecycle
seo_hooks.type1_title
Triggers before tool execution — validate params, check permissions, auto-approve or reject
seo_hooks.type2_title
Triggers after tool execution — auto-format, run tests, send notifications
seo_hooks.type3_title
Triggers on Claude Code notifications — integrate with Slack, email, or other channels
seo_hooks.type4_title
Triggers when Claude Code finishes responding — log results or run cleanup
seo_hooks.usecases_title
seo_hooks.usecases_desc
seo_hooks.usecase1_title
seo_hooks.usecase1_desc
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"command": "if echo \"$TOOL_INPUT\" | grep -q 'git commit'; then npm run format; fi"
}]
}
}
seo_hooks.usecase2_title
seo_hooks.usecase2_desc
{
"hooks": {
"PostToolUse": [{
"matcher": "Bash",
"command": "if echo \"$TOOL_INPUT\" | grep -q 'pytest\\|npm test'; then notify-send 'Tests completed'; fi"
}]
}
}
seo_hooks.usecase3_title
seo_hooks.usecase3_desc
{
"hooks": {
"PreToolUse": [{
"matcher": "Edit|Write",
"command": "if echo \"$TOOL_INPUT\" | grep -qE '\\.env|credentials|secrets'; then exit 2; fi"
}]
}
}
Headless Mode & CI/CD
Run Claude Code in CI/CD pipelines with the -p flag for unattended automation tasks
seo_hooks.headless_flag_title
seo_hooks.headless_flag_desc
seo_hooks.headless_pipeline_title
seo_hooks.headless_pipeline_desc
seo_hooks.headless_json_title
seo_hooks.headless_json_desc
# seo_hooks.headless_code_comment
claude -p "Review this PR and suggest improvements" \
--output-format json \
--max-turns 5
settings.json Configuration
Define your Hooks in .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"command": "~/scripts/pre-bash-hook.sh"
},
{
"matcher": "Edit|Write",
"command": "~/scripts/protect-sensitive-files.sh"
}
],
"PostToolUse": [
{
"matcher": "Bash",
"command": "~/scripts/post-bash-hook.sh"
}
],
"Notification": [
{
"command": "~/scripts/send-notification.sh"
}
],
"Stop": [
{
"command": "~/scripts/on-stop.sh"
}
]
}
}
seo_hooks.best_practices_title
seo_hooks.best_practices_desc
seo_hooks.bp1_title
seo_hooks.bp1_desc
seo_hooks.bp2_title
seo_hooks.bp2_desc
seo_hooks.bp3_title
seo_hooks.bp3_desc
seo_hooks.bp4_title
seo_hooks.bp4_desc
seo_hooks.faq_title
seo_hooks.faq1_q
seo_hooks.faq1_a
seo_hooks.faq2_q
seo_hooks.faq2_a
seo_hooks.faq3_q
seo_hooks.faq3_a
seo_hooks.faq4_q
seo_hooks.faq4_a
Enterprise Automation with QCode.cc
Combine QCode.cc API relay with Hooks for enterprise-grade AI coding pipelines
seo_hooks.qcode_advantage1_title
seo_hooks.qcode_advantage1_desc
seo_hooks.qcode_advantage2_title
seo_hooks.qcode_advantage2_desc
seo_hooks.qcode_advantage3_title
seo_hooks.qcode_advantage3_desc
Automate Your Claude Code Workflow
Unlock AI coding's full potential with Hooks + QCode.cc