炸弹投石机
83.01M · 2026-03-26
背景
前置准备
核心配置
配置说明
Hook 触发时机
terminal-notifier 参数说明
效果演示
参考
在使用 Claude Code 进行开发时,Claude 有时会在执行关键操作前等待用户确认,或者在任务完成后进入空闲状态。如果你不盯着终端,就会错过这些时机,导致任务卡在那里迟迟不推进。
本文介绍如何通过 Claude Code 的 Hooks 机制 + terminal-notifier,在以下场景自动推送 macOS 系统通知:
安装 terminal-notifier:
brew install terminal-notifier
验证安装(第一次使用 terminal-notifier 可能会弹出系统通知授权,允许通知即可):
terminal-notifier -title 'Test' -message 'Hello from terminal-notifier'
将以下配置添加到 Claude Code 的 settings.json(路径:~/.claude/settings.json)中的 hooks 字段:
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "terminal-notifier -title 'Claude Code' -message 'Claude Code 需要您的确认或输入' -sound Glass -activate com.apple.Terminal"
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "terminal-notifier -title 'Claude Code' -message 'Claude Code 已完成任务' -sound Glass -activate com.apple.Terminal"
}
]
}
]
}
| Hook 类型 | 触发场景 | 通知声音 |
|---|---|---|
| Notification | Claude 需要用户确认或输入时 | Glass |
| Stop | Claude 完成任务时 | Glass |
-title:通知标题-message:通知内容-sound:通知声音(macOS 系统内置音效,可选:Funk、Ping、Glass、Hero、Basso 等)-activate:点击通知后激活的应用(com.apple.Terminal 即终端)配置完成后:
再也不用一直盯着终端了