Claude FastClaude Fast
Hooks

Claude Code Hooks: 5 Automations That Eliminate Developer Friction

Stop clicking approve buttons and losing flow state. These 5 production-ready hooks transform Claude Code from assistant to autonomous teammate.

Problem: You're deep in flow state, building a feature. Claude needs to write a file. Click approve. Run a command. Click approve. Format code. Click approve. Twenty interruptions later, you've forgotten what you were building.

Quick Win: Add this to .claude/settings.json and never approve a Prettier format again:

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Write|Edit",
      "hooks": [{
        "type": "command",
        "command": "npx prettier --write \"$CLAUDE_TOOL_INPUT_FILE_PATH\""
      }]
    }]
  }
}

Every file Claude writes now auto-formats. Zero clicks. Zero context switches.

The 8 Hook Types (Quick Reference)

Hooks intercept Claude Code events and execute shell commands. Here's what triggers each:

HookWhen It FiresBest Use
PreToolUseBefore any tool runsBlock dangerous operations
PostToolUseAfter tool completesAuto-format, lint, log
PermissionRequestBefore permission dialogAuto-approve safe commands
SessionStartSession beginsInject context (git status, TODOs)
StopClaude finishes respondingRun tests, validate output
PreCompactBefore context compactionBackup transcripts
SubagentStopSubagent completesValidate agent output
UserPromptSubmitYou hit enterInject instructions, validate input

Hook 1: Auto-Format on Save

The formatter hook above runs Prettier after every Write or Edit. Extend it for your stack:

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Write|Edit",
      "hooks": [
        {"type": "command", "command": "npx prettier --write \"$CLAUDE_TOOL_INPUT_FILE_PATH\""},
        {"type": "command", "command": "npx eslint --fix \"$CLAUDE_TOOL_INPUT_FILE_PATH\""}
      ]
    }]
  }
}

Multiple hooks run in parallel. Your code is formatted AND linted before Claude's response appears.

Hook 2: Session Context Injection

Start every session with project awareness:

{
  "hooks": {
    "SessionStart": [{
      "hooks": [{
        "type": "command",
        "command": "echo '## Current State' && git status --short && echo '## Active TODOs' && grep -r 'TODO:' src/ --include='*.ts' | head -5"
      }]
    }]
  }
}

Claude now sees uncommitted changes and pending TODOs before you say anything.

Hook 3: Auto-Approve Safe Commands

Tired of approving npm test every time? Use PermissionRequest:

{
  "hooks": {
    "PermissionRequest": [{
      "matcher": "Bash(npm test*)",
      "hooks": [{
        "type": "command",
        "command": "echo '{\"decision\": \"approve\"}'"
      }]
    }]
  }
}

The hook returns JSON with decision: approve. Test commands run without prompts.

Hook 4: Test After Implementation

Catch bugs immediately with a Stop hook:

{
  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "npm test --passWithNoTests 2>&1 | tail -20"
      }]
    }]
  }
}

Every time Claude finishes responding, tests run. Failures appear in context.

Hook 5: Skill Activation (ClaudeFast)

The Skill Activation Hook appends skill recommendations to your prompts:

{
  "hooks": {
    "UserPromptSubmit": [{
      "hooks": [{
        "type": "command",
        "command": "node .claude/hooks/SkillActivationHook/skill-activation-prompt.mjs"
      }]
    }]
  }
}

Type "implement a feature" and Claude sees which skills to load. No memory required.

Configuration Locations

Three places to configure hooks:

LocationScopeUse Case
.claude/settings.jsonProject (shared)Team standards
.claude/settings.local.jsonProject (personal)Your preferences
~/.claude/settings.jsonAll projectsGlobal defaults

Project settings override user settings.

When Things Go Wrong

Hook not triggering Check matcher syntax. Write|Edit works. Write | Edit (spaces) fails.

Command failing silently Add logging: your-command 2>&1 | tee ~/.claude/hook-debug.log

Too slow Hooks have 60-second timeout. For slow operations, run in background.

Start With One Hook

Pick your biggest friction point:

  • Constant formatting? Add PostToolUse formatter
  • Approving safe commands? Add PermissionRequest auto-approve
  • Missing context? Add SessionStart injection

One hook. One friction point eliminated. Then iterate.

Next Steps

Last updated on

On this page

Claude Code ready in seconds.