●FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtask●LIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its own●MCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MS●PLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callback●SONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15●IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October●FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtask●LIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its own●MCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MS●PLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callback●SONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15●IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Claude Code Hooks— Practical Techniques to Automate Your Dev Workflow
Learn how to automate your development workflow with Claude Code Hooks. From PreToolUse and PostToolUse configuration to automated code review, security checks, and deployment pipeline integration.
What Are Claude Code Hooks — The Automation Layer That Transforms Your Workflow
Claude Code Hooks let you automatically run custom scripts before and after Claude executes tools. This means you can fully automate code reviews, test runs, security checks, and more — tasks that used to require manual intervention.
In 2026, collaborating with AI assistants is the norm in software development. But shipping AI-generated code straight to production without guardrails is risky. Hooks give you a way to apply consistent quality controls to Claude's output automatically, balancing safety with efficiency.
Hook Structure and Configuration
Claude Code Hooks are defined in .claude/settings.json. There are four hook types available:
Fires before Claude edits files or runs commands. Returning exit code 2 blocks the tool execution entirely, making it ideal for preventing dangerous operations.
PostToolUse — Quality Checks After Execution
Fires immediately after a file edit or command completes. Perfect for automated linting, type checking, and test execution.
Notification — Automated Alert Forwarding
Fires when Claude issues a notification. Useful for Slack alerts, email notifications, or logging.
Stop — Session Cleanup
Fires just before Claude finishes a task and returns its response. Great for logging, cleanup, and summary generation.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦CI/CD pipeline full automation techniques combining Git hooks with Claude Code
✦Automated pre-commit fixes, formatting, security scanning implementation and optimization
✦Automated review process and production deployment validation methodology
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
This hook automatically finds and runs tests related to edited files:
#!/bin/bash# .claude/hooks/auto-test.sh# PostToolUse hook — automatically run related testsFILEPATH="$1"DIR=$(dirname "$FILEPATH")BASENAME=$(basename "$FILEPATH" | sed 's/\.[^.]*$//')# Look for test file candidatesTEST_FILES=()for pattern in \ "${DIR}/${BASENAME}.test.ts" \ "${DIR}/${BASENAME}.test.tsx" \ "${DIR}/${BASENAME}.spec.ts" \ "${DIR}/__tests__/${BASENAME}.test.ts" \ "tests/${BASENAME}.test.ts"; do if [ -f "$pattern" ]; then TEST_FILES+=("$pattern") fidoneif [ ${#TEST_FILES[@]} -eq 0 ]; then echo "📝 No related test files found" exit 0fiecho "🧪 Running related tests..."for test_file in "${TEST_FILES[@]}"; do echo " → $test_file" npx vitest run "$test_file" --reporter=verbose 2>&1done# Don't block on test failures — let Claude see the feedbackexit 0
Technique 4: Git Safety Guard
A hook that warns when Claude tries to execute dangerous Git commands:
#!/bin/bash# .claude/hooks/git-safety.sh# PreToolUse hook — block dangerous Git operationsCOMMAND="$1"# Dangerous Git command patternsDANGEROUS_PATTERNS=( "git push.*--force" "git push.*-f " "git reset --hard" "git checkout \." "git clean -fd" "git branch -D" "git rebase.*main")for pattern in "${DANGEROUS_PATTERNS[@]}"; do if echo "$COMMAND" | grep -qE "$pattern"; then echo "🚫 Dangerous Git operation detected: $COMMAND" echo "This operation risks data loss." echo "Run it manually or use a safer alternative." exit 2 fidoneexit 0
Technique 5: Slack Notification Integration
A hook that sends Slack notifications when Claude finishes a task — invaluable for team workflows:
#!/bin/bash# .claude/hooks/notify-slack.sh# Notification hook — send alerts via Slack WebhookMESSAGE="$1"SLACK_WEBHOOK_URL="${SLACK_WEBHOOK_URL:-}"if [ -z "$SLACK_WEBHOOK_URL" ]; then exit 0 # Skip if webhook not configuredfi# Format and send to SlackPAYLOAD=$(cat <<EOF{ "text": "🤖 Claude Code Notification", "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "*Notification from Claude Code:*\n${MESSAGE}" } }, { "type": "context", "elements": [ { "type": "mrkdwn", "text": "📁 Project: $(basename $(pwd)) | ⏰ $(date '+%Y-%m-%d %H:%M')" } ] } ]}EOF)curl -s -X POST "$SLACK_WEBHOOK_URL" \ -H 'Content-type: application/json' \ -d "$PAYLOAD" > /dev/null 2>&1exit 0
Combining Hooks — A Complete Automation Pipeline
Let's bring all the individual hooks together into a comprehensive automation pipeline:
Here are key considerations for running hooks in production.
Timeout Configuration
Hooks have a default 60-second timeout. For heavy processing, consider async or background execution:
#!/bin/bash# Run heavy tasks in the backgroundnohup bash -c "npm run test:coverage" > /tmp/test-results.log 2>&1 &echo "🧪 Tests running in background (results: /tmp/test-results.log)"exit 0
Debug Logging
Add logging to track hook behavior during development:
Control hook behavior with environment variables to easily switch between development and production:
#!/bin/bash# Adjust hook strictness based on environmentHOOK_MODE="${CLAUDE_HOOK_MODE:-strict}"if [ "$HOOK_MODE" = "permissive" ]; then echo "📝 Permissive mode: Skipping checks" exit 0fi# Strict mode processing...
A Note from an Indie Developer
Wrapping Up — Building Defensive Automation with Hooks
Claude Code Hooks provide a powerful mechanism for maintaining safe, consistent quality control when collaborating with AI assistants. By combining security guards, auto-linting, test runners, Git safety checks, and notification integrations, you can minimize human intervention while upholding high quality standards.
Start with a security guard hook, then gradually layer on auto-linting and test execution. Begin small and evolve your hook setup alongside your team's development workflow.
Share
Thank You for Reading
Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.