Claude Code Reference

v2.1.178 · 87 auto-discovered · Commands, shortcuts, hooks, Python/AWS tips.

Hooks System

Hooks run shell commands in response to Claude events. Configure in settings.json. Exit 0 = allow, Exit 2 = block action.

-iAUTO
boolean
SessionStart
Session begins. Cannot block.
UserPromptSubmit
You submit a prompt. Cannot block.
PreToolUse
Before tool executes. CAN block (exit 2).Use matcher: "Bash" to intercept shell commands
PostToolUse
After tool succeeds. Cannot block.Great for auto-formatting after Edit/Write
PostToolUseFailure
After tool fails. Cannot block.
Stop
Claude finishes responding. Cannot block.
Notification
Claude needs your attention. Cannot block.
SubagentStart
Subagent lifecycle start.
SubagentStop
Subagent lifecycle end.
FileChanged
Watched files change.

Example: Auto-format Python on every edit

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "ruff format $(jq -r '.tool_input.file_path') 2>/dev/null; ruff check --fix $(jq -r '.tool_input.file_path') 2>/dev/null; true"
          }
        ]
      }
    ],
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "notify-send 'Claude Code' 'Needs your attention'"
          }
        ]
      }
    ]
  }
}