jpskill.com
🛠️ 開発・MCP コミュニティ

claude-code-hooks

Claudeのツール実行前後にカスタム処理を自動で組み込み、検証やログ記録も行うSkill。

📜 元の英語説明(参考)

Claude Code hook system for pre/post tool execution. Triggers on: hooks, PreToolUse, PostToolUse, hook script, tool validation, audit logging.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Claudeのツール実行前後にカスタム処理を自動で組み込み、検証やログ記録も行うSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
1
📖 Claude が読む原文 SKILL.md(中身を展開)

この本文は AI(Claude)が読むための原文(英語または中国語)です。日本語訳は順次追加中。

Claude Code Hooks

Execute custom scripts before/after Claude Code tool invocations.

Quick Reference

Event When Has Matcher
PreToolUse Before tool execution Yes
PostToolUse After tool completes Yes
PermissionRequest Permission dialog shown Yes
Notification Notifications sent Yes
UserPromptSubmit User submits prompt No
Stop Agent finishes No
SubagentStop Subagent finishes No
PreCompact Before context compaction No
SessionStart Session begins/resumes No
SessionEnd Session ends No

Basic Configuration

Add to ~/.claude/settings.json or .claude/settings.local.json:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": "$CLAUDE_PROJECT_DIR/hooks/validate.sh",
        "timeout": 5000
      }]
    }]
  }
}

Matcher Patterns

Pattern Matches
"Write" Only Write tool
"*" or "" All tools
"mcp__*" All MCP tools
"Bash" Bash commands

Hook Script Requirements

#!/bin/bash
# Receives JSON via stdin: { "tool_name": "...", "tool_input": {...} }
INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name')

# Exit codes:
# 0 = Success (continue)
# 2 = Block with error (stderr shown to Claude)
# Other = Non-blocking error

Common Use Cases

Use Case Event Example
Validate inputs PreToolUse Block dangerous commands
Audit logging PostToolUse Log all tool usage
Custom approval PermissionRequest Slack notification
Session init SessionStart Load project context

Security Checklist

  • [ ] Quote all variables: "$VAR" not $VAR
  • [ ] Validate paths (no .. traversal)
  • [ ] Use $CLAUDE_PROJECT_DIR for paths
  • [ ] Set reasonable timeouts
  • [ ] Handle jq parsing errors

Troubleshooting

# Debug hook loading
claude --debug

# List registered hooks
/hooks

# Test script manually
echo '{"tool_name":"Bash"}' | ./hooks/validate.sh

Official Documentation

Additional Resources

  • ./references/hook-events.md - All events with input/output schemas
  • ./references/configuration.md - Advanced config patterns
  • ./references/security-patterns.md - Production security

See Also: claude-code-debug for troubleshooting, claude-code-headless for CLI automation