こんにちは。KDDIアジャイル開発センターのハットリです。皆さん、Claude Codeを使用していますでしょうか?Claude Codeを使用していると、裏のターミナルで通知が権限設定で止まっていたり、何か許可を求めていて止まっていたり、何なら処理が終わったことに気づかなかったりといった経験はないでしょうか?それらを通知フックを設定することで解決できます。
前提
- macOS
-
jqインストール済み -
terminal-notifierインストール済み(brew install terminal-notifier) - システム設定 → 通知 → terminal-notifier をオンにしておく
設定
1. 通知スクリプトを作成
~/.claude/scripts/hooks/notification.sh を作成:
#!/bin/bash
input=$(cat)
notification_type=$(echo "$input" | jq -r '.notification_type')
message=$(echo "$input" | jq -r '.message')
title=$(echo "$input" | jq -r '.title // "Claude Code"')
case "$notification_type" in
permission_prompt)
sound="Ping"
display_title="⚠️ 権限が必要です"
;;
idle_prompt)
sound="Pop"
display_title="⏸️ 入力待ち中"
;;
auth_success)
sound="Glass"
display_title="✓ 認証成功"
;;
elicitation_dialog)
sound="Submarine"
display_title="💬 入力が必要です"
;;
*)
sound="Glass"
display_title="$title"
;;
esac
/opt/homebrew/bin/terminal-notifier \
-title "$display_title" \
-message "$message" \
-sound "$sound" \
2>/dev/null
chmod +x ~/.claude/scripts/hooks/notification.sh
2. ~/.claude/settings.json にフックを登録
{
"hooks": {
"Notification": [
{
"hooks": [
{
"type": "command",
"command": "~/.claude/scripts/hooks/notification.sh"
}
]
}
]
}
}
通知タイプ一覧
| notification_type | タイミング |
|---|---|
permission_prompt |
ツール実行の権限確認 |
idle_prompt |
入力待ち状態 |
auth_success |
認証成功 |
elicitation_dialog |
追加入力が必要な時 |
参考
- Claude Code Hooks リファレンス — Notification フックのイベントスキーマ・設定方法の公式ドキュメント