Back to list
DuncanJurman

hooks-reference

by DuncanJurman

Claude Code plugin marketplace

1🍴 0📅 Jan 23, 2026

SKILL.md


name: hooks-reference description: Claude Code hooks configuration reference. Use when creating hooks, understanding hook events (PreToolUse, PostToolUse, Stop, SessionStart, etc.), debugging hook behavior, or implementing automation.

Claude Code Hooks Reference

Hooks are user-defined shell commands that execute at various points in Claude Code's lifecycle, providing deterministic control over behavior.

Quick Reference: Hook Events

EventWhenInputCan Control
PreToolUseBefore tool runsTool name, inputsBlock/modify tool
PostToolUseAfter tool succeedsTool name, resultFeedback to Claude
PostToolUseFailureAfter tool failsTool name, errorError handling
PermissionRequestPermission dialog shownDetailsAllow/deny
UserPromptSubmitUser submits promptUser inputModify prompt
NotificationNotification sentMessageCustom notifications
StopClaude stopsReasonContinue/stop
SubagentStopSubagent completesResultSubagent behavior
PreCompactBefore compactionContextModify context
SessionStartSession beginsSession infoEnv setup
SessionEndSession endsStatsCleanup

Hook Configuration Location

~/.claude/settings.json          # User-level (all projects)
.claude/settings.json            # Project-level (team shared)
.claude/settings.local.json      # Project-local (gitignored)

Basic Hook Structure

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "your-script.sh"
          }
        ]
      }
    ]
  }
}

Matcher Patterns

PatternMatches
*All tools
BashBash tool only
Write|EditWrite or Edit tools
Read.*Read and any Read variants

Hook Types

Command Hook

{
  "type": "command",
  "command": "jq '.tool_input' >> /tmp/log.txt"
}

Prompt Hook

{
  "type": "prompt",
  "prompt": "Review the output: $ARGUMENTS"
}

Agent Hook

{
  "type": "agent",
  "prompt": "Verify the changes meet security requirements"
}

Control Flow via Exit Codes

Exit CodeEffect
0Success, continue
2Block (PreToolUse only)
Non-zeroError, continue with warning

Hook Output Format (stdout JSON)

{
  "continue": true,
  "decision": "approve",
  "reason": "Looks good",
  "suppressOutput": false
}

Common Patterns

Auto-format on file write

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

Block sensitive file edits

{
  "PreToolUse": [{
    "matcher": "Write|Edit",
    "hooks": [{
      "type": "command",
      "command": "jq -e '.tool_input.file_path | test(\"\\\\.env|\\\\.git\")' && exit 2 || exit 0"
    }]
  }]
}

Log all Bash commands

{
  "PreToolUse": [{
    "matcher": "Bash",
    "hooks": [{
      "type": "command",
      "command": "jq -r '.tool_input.command' >> ~/.claude/bash-log.txt"
    }]
  }]
}

Environment Variables in Hooks

VariableValue
CLAUDE_PROJECT_DIRProject root directory
CLAUDE_PLUGIN_ROOTPlugin installation path

Debugging Hooks

# View loaded hooks
/hooks

# Test hook manually with sample input
echo '{"tool_name":"Bash","tool_input":{"command":"ls"}}' | your-hook.sh

# Check exit code
echo $?

Security Considerations

  • Hooks run with your credentials
  • Validate all input before use
  • Don't log sensitive data
  • Use absolute paths for scripts
  • Test hooks in isolation first

For complete documentation including all event schemas, see:

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon