claudhopper

Hooks

Hooks are shell commands that Claude Code runs at fixed points: before a tool runs, after a file is edited, when it needs your attention. Claude does not get a vote. That is the point.

A hook does not ask Claude nicely. Neither does the heron.

Facts checkedNov 11at the source

Your first hook: get told when Claude is waiting

  1. Open ~/.claude/settings.json. Create it if it does not exist.
  2. Add a Notification hook. This one is for macOS. The docs have the Linux and Windows versions.
  3. Check it registered. Type /hooks in Claude Code and look under Notification.
~/.claude/settings.json
{
  "hooks": {
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          { "type": "command",
            "command": "osascript -e 'display notification \"Claude Code needs your attention\" with title \"Claude Code\"'" }
        ]
      }
    ]
  }
}

The one everybody wants: format after every edit

A PostToolUse hook with an Edit|Write matcher runs only after file-editing tools. This one hands the edited file to Prettier. Put it in .claude/settings.json in the project.

.claude/settings.json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "jq -r '.tool_input.file_path' | xargs npx prettier --write" }]
      }
    ]
  }
}

Events you will meet

  • PreToolUseBefore a tool call. The place to block things, such as edits to protected files.
  • PostToolUseAfter a tool call. Formatting, linting, logging.
  • NotificationWhen Claude is waiting for input or permission.
  • SessionStartWhen a session begins. Anything your command prints is added to Claude's context.

All events sit as keys inside one hooks object. Add a new event beside the existing ones; do not replace the object. The hooks reference has the full list and the JSON each one receives.

Clodhopper move: Pasting a hook from a stranger's gist. A hook is a shell command that runs on your machine without asking. Read it first. Out loud, if that helps.

Source: the Claude Code documentation at code.claude.com/docs, read on November 11, 2026.

Advertisement