Lifecycle automations that trigger on events

Hooks

5 hooks that automate repetitive actions across the development lifecycle. They fire on specific events — before a tool runs, after a file changes, when a session ends.

Active Hooks

HookEventAction
Port GuardBefore pnpm devKill anything on port 3000
Browser OpenAfter pnpm devOpen Chrome to localhost:3000
Auto-FormatAfter Write/EditRun Prettier on changed files
Session LogAgent finishesLog timestamp to session log
NotificationAgent needs attentionmacOS notification via osascript

How Hooks Work

Hooks are shell commands configured in ~/.claude/settings.json under the hooks key:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash(pnpm dev)",
        "hooks": [
          {
            "type": "command",
            "command": "lsof -ti:3000 | xargs kill -9 2>/dev/null; exit 0"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "npx prettier --write \"$FILE_PATH\" 2>/dev/null; exit 0"
          }
        ]
      }
    ]
  }
}

Hook Events

EventWhen It FiresCommon Use
PreToolUseBefore a tool executesPort cleanup, validation
PostToolUseAfter a tool completesFormatting, browser open
StopWhen agent finishesLogging, cleanup
NotificationAgent pauses for inputDesktop alerts

Matcher Patterns

  • Bash(pnpm dev) — matches specific bash commands
  • Write|Edit — matches multiple tools with pipe
  • * — matches everything

Role Availability

RoleHooks
engineerAll 5
businessPrettier only
contentPrettier only
opsAll 5

Adding Custom Hooks

Edit ~/.claude/settings.json to add new hooks. Each hook needs:

  1. Event — when to fire (PreToolUse, PostToolUse, Stop, Notification)
  2. Matcher — which tool/command to match
  3. Command — shell command to execute