1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Code Hooks ログ記録用設定メモ

Posted at

はじめに

Claude Codeのhooks機能を使っていると「このイベントでどんなデータが渡されるんだろう?」と思うことがよくあります。なんのイベントでどんなデータを受け取っているか知っておくと、かゆいところに手が届くスクリプトがかけて、はかどると思うので、メモしておきます。

ログ記録用設定ファイル

~/.claude/settings-logging.jsonに以下の内容を保存します:

~/.claude/settings-logging.json
{
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "SubagentStop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "Notification": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "PreCompact": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ],
    "SessionStart": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "jq . >> /tmp/claude-hooks.log",
            "timeout": 30
          }
        ]
      }
    ]
  }
}

使い方

1. ログ記録モードで起動

# 設定ファイルを指定して起動
claude --settings ~/.claude/settings-logging.json

2. ログの確認

セッション中、全てのフックイベントが/tmp/claude-hooks.logに記録されます:

# ログをリアルタイムで監視
tail -f /tmp/claude-hooks.log
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?