10
4

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 の通知設定 + 通知一括削除ショートカット(Mac)

10
Last updated at Posted at 2026-04-30

はじめに

Claude Code を使っていると、タスクを投げた後に別作業をしていて完了に気づかない問題があります。通知を有効にすれば気づけますが、今度は通知が溜まって邪魔になります(なりました)。

この記事では「気づける通知設定」と「溜まった通知をワンキーで消すショートカット」をセットで構築します。

ゴール

  • Claude Code がタスク完了 / ユーザー入力待ちになったら macOS 通知が出る
  • 溜まった通知はキー一発で全消去できる

ちなみに: Claude Code には公式のデスクトップ通知機能もあるらしく、Ghostty / Kitty / iTerm2 で使えるそうです(公式ドキュメント)。私は試していませんが、対応ターミナルを使っている方はそちらの方が簡単かもしれません。本記事は hooks で自作する方法を扱います。

1. Claude Code の通知設定(hooks + osascript)

こちらの Qiita 記事 の方法をベースに、terminal-notifier の代わりに macOS 標準の osascript を使う構成です。

環境によっては terminal-notifier が動かないことがあるので、依存を増やさず osascript で実装するのがおすすめです。

1-1. 通知スクリプトを作成

mkdir -p ~/.claude
cat > ~/.claude/notify.sh << 'EOF'
#!/bin/bash

# stdin から hook の JSON を受け取る
INPUT=$(cat)

# hook イベント名を取り出す
HOOK_EVENT=$(echo "$INPUT" | /usr/bin/python3 -c "import sys, json; print(json.load(sys.stdin).get('hook_event_name', ''))" 2>/dev/null)

case "$HOOK_EVENT" in
    "Notification")
        TITLE="Claude Code"
        MESSAGE="入力待ちです"
        ;;
    "Stop")
        TITLE="Claude Code"
        MESSAGE="タスク完了"
        ;;
    *)
        TITLE="Claude Code"
        MESSAGE="$HOOK_EVENT"
        ;;
esac

osascript -e "display notification \"$MESSAGE\" with title \"$TITLE\" sound name \"Glass\""
EOF

chmod +x ~/.claude/notify.sh

1-2. Claude Code の hooks に登録

Claude Code を起動して /hooks コマンドを実行し、以下の2つのイベントに ~/.claude/notify.sh を登録します。

  • Notification: ユーザー入力が必要になった時
  • Stop: タスクが完了した時

1-3. macOS 側の通知設定

ここがハマりポイント。osascript で出る通知は 「スクリプトエディタ」 という macOS 標準アプリが発行元になります。

システム設定 → 通知 → スクリプトエディタ を開き:

  • 通知を許可 をオン
  • 通知スタイル「持続的」 に変更(これが重要)

通知スタイルが「バナー」だと数秒で消えてしまうので、離席中に気づけません。「持続的」 にすると自分で消すまで画面に残ります。

これで Claude Code がタスク完了 / 入力待ちになると、画面右上に通知が出続けて気づけるようになります。

2. 溜まった通知をワンキーで消すショートカット

通知を「持続的」にすると今度は手動で消す手間が出てきます。が、macOS には残念ながら「全通知を消す」標準ショートカットがありません。

ネット記事でよく紹介される「システム設定 → キーボードショートカット → Appショートカット に すべての通知をクリア を追加する」という方法は実は動きません。Appショートカットはアプリのメニューバー項目に対するものなので、通知センターパネル内のボタンには効かないからです。

killall NotificationCenter も、macOS が通知を永続化しているため再起動後に復活します。

確実な解は AppleScript で UI 要素を直接叩く 方法です。

2-1. スクリプトを保存

mkdir -p ~/scripts
cat > ~/scripts/dismiss-notifications.sh << 'SCRIPT_EOF'
#!/bin/bash

osascript <<'EOF'
tell application "System Events"
    tell process "NotificationCenter"
        try
            -- パターン1: 複数通知の「すべて消去」を試す
            try
                set topGroup to UI element 1 of UI element 1 of UI element 1 of UI element 1 of UI element 1 of window 1
                perform (first action of topGroup whose description is "すべて消去")
                return
            end try
            
            -- パターン2: ScrollArea 直下の各グループで「閉じる」を叩く
            set sa to UI element 1 of UI element 1 of UI element 1 of window 1
            repeat with g in (UI elements of sa)
                try
                    perform (first action of g whose description is "閉じる")
                end try
            end repeat
        end try
    end tell
end tell
EOF
SCRIPT_EOF

chmod +x ~/scripts/dismiss-notifications.sh

スクリプトが2パターン試すのは、通知の状態によって UI 階層が変わるためです。

  • 複数通知が溜まっている状態: グループ化されて「すべて消去」アクションが出る
  • 単独通知: 「閉じる」アクションを個別に叩く必要がある

両方を順に試すことでどの状態でも機能します。

2-2. アクセシビリティ権限を付与

通知センターの UI を操作するため、システム設定 → プライバシーとセキュリティ → アクセシビリティ で実行元アプリ(ターミナル、ショートカット.app)を許可します。

2-3. 動作確認

通知を溜めた状態で:

~/scripts/dismiss-notifications.sh

通知が一括で消えれば成功です。

2-4. ショートカットキーを割り当て

Mac 標準の ショートカット.app で割り当てます。

  1. ショートカット.app を起動
  2. 左上の「+」で新規ショートカット作成
  3. 右側の検索欄で 「シェルスクリプトを実行」 を検索し、中央にドラッグ
  4. スクリプト欄に ~/scripts/dismiss-notifications.sh を入力
  5. 上部のショートカット名を 「通知をクリア」 に変更
  6. 右上の ⓘ アイコン「キーボードショートカットを使用」 に好きなキーを登録(私はCtrl+Wに設定しています)

これで任意のキーで通知を一掃できます。

トラブルシューティング: 通知が削除されない場合

macOS のバージョンや通知の種類で UI 階層が違うと、上記スクリプトが効かないことがあります。AIとやりとりをして、以下のようなコマンドを作成することで、現在の通知センターの構造をダンプできます。

osascript > /tmp/nc-dump.txt 2>&1 <<'APPLESCRIPT'
tell application "System Events"
    tell process "NotificationCenter"
        set output to ""
        try
            set L1 to UI elements of window 1
            repeat with i from 1 to count of L1
                set e1 to item i of L1
                set output to output & "[" & i & "] " & (role of e1) & linefeed
                try
                    set L2 to UI elements of e1
                    repeat with j from 1 to count of L2
                        set e2 to item j of L2
                        set output to output & "  [" & i & "." & j & "] " & (role of e2) & linefeed
                        try
                            repeat with a in (actions of e2)
                                set output to output & "    action: " & (description of a) & linefeed
                            end repeat
                        end try
                        try
                            set L3 to UI elements of e2
                            repeat with k from 1 to count of L3
                                set e3 to item k of L3
                                set output to output & "    [" & i & "." & j & "." & k & "] " & (role of e3) & linefeed
                                try
                                    repeat with a in (actions of e3)
                                        set output to output & "      action: " & (description of a) & linefeed
                                    end repeat
                                end try
                            end repeat
                        end try
                    end repeat
                end try
            end repeat
        end try
        return output
    end tell
end tell
APPLESCRIPT

cat /tmp/nc-dump.txt

通知が画面に出ている状態で実行し、action: すべて消去action: 閉じる がどの階層にあるかを確認して、スクリプトの UI element N of ... のネスト数を調整してください。

また、英語環境の場合は "すべて消去""Clear All""閉じる""Close" に書き換えが必要です。

まとめ

  • Claude Code の hooks に osascript で通知を出すスクリプトを登録
  • macOS 側で「スクリプトエディタ」の通知スタイルを 持続的 に設定
  • 溜まった通知は AppleScript で UI 要素を叩いて一括削除
  • ショートカット.app で好きなキーに割り当て

通知が自動で来て、ショートカットで通知を削除できるようになると、Claude Code を日常的に使う身としてはかなり快適になったのでおすすめです!


株式会社シンシア

株式会社シンシアでは、実務未経験のエンジニアの方や学生エンジニアインターンを採用し一緒に働いています。
※ シンシアにおける働き方の様子はこちら

弊社には年間100人程度の実務未経験の方に応募いただき、技術面接を実施しております。
この記事が少しでも学びになったという方は、ぜひ wantedly のストーリーもご覧いただけるととても嬉しいです!

10
4
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
10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?