この記事はClaude Codeと一緒に書いています。
やりたいこと
Claude Codeに作業を任せている間、画面の前で本を読んでいても気づけるようにしたかったので、処理完了や権限確認のタイミングでWindowsのデスクトップ通知を出したいと思いました。
すでにいろいろな情報があるのですが、一発でできなかったのでメモ代わりに残しておきます。
環境
- Windows 11 Professional 25H2
- WSL2 (Ubuntu 24.04 LTS)
- Claude Code 2.1.71
設定
~/.claude/settings.json に以下を追記します。プロジェクトごとの .claude/settings.json でも同様に設定できます。
{
"hooks": {
"Notification": [
{
"matcher": "permission_prompt",
"hooks": [
{
"type": "command",
"command": "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command 'Add-Type -AssemblyName System.Windows.Forms; $n = New-Object System.Windows.Forms.NotifyIcon; $n.Icon = [System.Drawing.SystemIcons]::Information; $n.Visible = $true; $n.ShowBalloonTip(5000, \"Claude Code\", \"確認が必要です\", \"Info\"); Start-Sleep -Seconds 3; $n.Dispose()'"
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command 'Add-Type -AssemblyName System.Windows.Forms; $n = New-Object System.Windows.Forms.NotifyIcon; $n.Icon = [System.Drawing.SystemIcons]::Information; $n.Visible = $true; $n.ShowBalloonTip(5000, \"Claude Code\", \"処理が完了しました\", \"Info\"); Start-Sleep -Seconds 3; $n.Dispose()'"
}
]
}
]
}
}
System.Windows.Forms.NotifyIcon でバルーン通知を出しています。BurntToastやgo-toastのインストールは不要です。
Stop は処理完了時、Notification の permission_prompt は権限確認が必要なときに発火します。
エスケープのポイント
PowerShellの -Command に渡す文字列全体をシングルクォートで囲むのがポイントです。内側のダブルクォートは \" でJSONエスケープします。
powershell.exe -Command '... \"Claude Code\" ...'
ダブルクォートで全体を囲むと、JSON側のエスケープと衝突して破綻します。