macOS 系统通知脚本,当 Claude Code 需要你关注时发送桌面通知。
- 桌面通知提醒(标题显示
Claude:<项目名>) - 点击通知跳转到对应应用(IDE 或 Terminal.app)
- 可自定义通知声音
- 热更新:修改脚本后立即生效,无需重启 Claude Code
brew install terminal-notifier jq- 复制
notify.sh到任意位置 - 确保脚本有执行权限:
chmod +x notify.sh - 在
~/.claude/settings.json中添加 hook 配置:
{
"hooks": {
"Notification": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "/path/to/notify.sh",
"timeout": 5
}
]
}
]
}
}编辑 notify.sh 顶部的用户配置区域:
IDE_APP="terminal" # terminal / vscode / cursor / zed 等
SOUND="Tink" # 通知声音| 应用 | 配置值 | 说明 |
|---|---|---|
| Terminal.app | terminal |
跳转到发出通知的终端窗口/标签页 |
| VS Code | vscode |
URL Scheme 跳转 |
| Cursor | cursor |
URL Scheme 跳转 |
| Windsurf | windsurf |
URL Scheme 跳转 |
| Zed | zed |
URL Scheme 跳转 |
| Sublime Text | sublime |
URL Scheme 跳转 |
| IntelliJ IDEA | idea |
URL Scheme 跳转 |
| WebStorm | webstorm |
URL Scheme 跳转 |
| PyCharm | pycharm |
URL Scheme 跳转 |
Terminal.app 模式通过 TTY 识别窗口,使用 AppleScript 激活对应标签页。 设置
IDE_APP=""可禁用点击跳转功能。
Basso, Blow, Bottle, Frog, Funk, Glass, Hero, Morse,
Ping, Pop, Purr, Sosumi, Submarine, Tink
脚本支持热更新,修改 notify.sh 后立即生效,无需重启 Claude Code 会话。
调试技巧:在脚本中添加一行保存输入数据,方便查看 Claude Code 传递的完整 JSON:
echo "$INPUT" > /tmp/notification-debug.json然后触发一次通知,查看数据:
cat /tmp/notification-debug.json | jq .你也可以手动测试通知效果:
echo '{"message": "测试消息", "cwd": "/your/project/path"}' | ./notify.shClaude Code 发送的 JSON 包含以下字段:
{
"session_id": "会话 ID",
"transcript_path": "会话记录路径",
"cwd": "当前工作目录",
"hook_event_name": "Notification",
"message": "通知消息",
"notification_type": "通知类型 (permission_prompt 等)"
}MIT