当 Claude 需要你输入时,发送系统通知提醒。即使你在其他应用中工作,也不会错过。
当 Claude 等待你的输入时:
- macOS: 系统通知 + Glass 提示音
- Linux: 桌面通知
- Windows: Toast 通知
将以下配置添加到你的 ~/.claude/settings.local.json:
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bash -c 'osascript -e \"display notification \\\"${TERMINAL_NAME:-$(basename $PWD)} needs your input\\\" with title \\\"Claude Code\\\" sound name \\\"Glass\\\"\"'"
}
]
}
]
}
}如果你的 settings.local.json 已有其他配置,只需将 hooks 部分合并进去。
确保安装了 notify-send(大多数发行版预装):
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "notify-send 'Claude Code' \"${TERMINAL_NAME:-$(basename $PWD)} needs your input\" --urgency=normal"
}
]
}
]
}
}使用 PowerShell toast 通知:
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "powershell -Command \"[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null; $xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02); $text = $xml.GetElementsByTagName('text'); $text[0].AppendChild($xml.CreateTextNode('Claude Code')) | Out-Null; $text[1].AppendChild($xml.CreateTextNode('Needs your input')) | Out-Null; [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Claude Code').Show([Windows.UI.Notifications.ToastNotification]::new($xml))\""
}
]
}
]
}
}Claude Code 提供 Notification hook 事件,当 Claude 需要用户输入时触发。
我们利用这个事件执行系统命令来显示通知:
- macOS:
osascript(AppleScript) - Linux:
notify-send - Windows: PowerShell toast
更改 sound name "Glass" 为其他系统音效:
Basso | Blow | Bottle | Frog | Funk | Glass | Hero | Morse | Ping | Pop | Purr | Sosumi | Submarine | Tink
替换 needs your input 为你喜欢的文案。
"matcher": "" 表示匹配所有通知。你可以设置特定条件来过滤。
Q: macOS 没有收到通知?
检查:系统设置 → 通知 → 允许 Terminal/iTerm/Warp 发送通知
Q: 如何测试?
运行 Claude Code,在 Claude 响应后等待它提问或需要确认时就会触发。
Q: 已有 settings.local.json 怎么办?
将 hooks 部分合并到现有配置中即可。
MIT