Claude Code macOS 等待确认与任务完成通知

背景

在使用 Claude Code 进行开发时,Claude 有时会在执行关键操作前等待用户确认,或者在任务完成后进入空闲状态。如果你不盯着终端,就会错过这些时机,导致任务卡在那里迟迟不推进。

本文介绍如何通过 Claude Code 的 Hooks 机制 + terminal-notifier,在以下场景自动推送 macOS 系统通知:

  • ✅ Claude 需要用户确认或输入时发送通知
  • ✅ Claude 完成任务时发送通知

前置准备

安装 terminal-notifier:

1
brew install terminal-notifier

验证安装(第一次使用 terminal-notifier 可能会弹出系统通知授权,允许通知即可):

1
terminal-notifier -title 'Test' -message 'Hello from terminal-notifier'

核心配置

将以下配置合并到 Claude Code 的 settings.json(路径:~/.claude/settings.json)顶层对象中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"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 触发时机

Hook 类型 触发场景 通知声音
Notification Claude 需要用户确认或输入时 Glass
Stop Claude 完成任务时 Glass

terminal-notifier 参数说明

  • -title:通知标题
  • -message:通知内容
  • -sound:通知声音(macOS 系统内置音效,可选:Funk、Ping、Glass、Hero、Basso 等)
  • -activate:点击通知后激活的应用(com.apple.Terminal 即终端)

效果演示

配置完成后:

  1. Claude 需要确认或输入时 → 收到「Claude Code 需要您的确认或输入」通知(Glass 音效)
  2. Claude 完成任务时 → 收到「Claude Code 已完成任务」通知(Glass 音效)
  3. 点击通知 → 自动跳转回 Terminal,继续操作

再也不用一直盯着终端了 🎉

参考