Claude Notify
Claude Code 通知配置 Skill。用于配置 Claude Code Hooks,让 Claude Code 在等待确认或长任务完成时通知用户。
Core Model
claude-notify Skill
-> ~/.claude/settings.json hooks
-> ~/.claude/hooks/notify-router.sh (thin wrapper)
-> ~/.claude/hooks/notify-router.js (Node.js entry)
-> ~/.claude/hooks/src/channels/ (macos / dingtalk / feishu / wecom)
Supported Events
Notification: Claude Code 需要用户注意时通知,标题 "Claude Code — 等待确认",播放 Ping 音效。PreToolUse: 记录本轮工具任务开始时间,用于长任务判断。Stop: Claude Code 停止生成时判断是否需要通知。Stop 与 Notification 互斥去重(5s 窗口)。
Notification Strategy
Notification→ 立即通知所有已启用通道(标题含 hook 来源)Stop→ 检查 Notification 是否在 5s 内刚发过(互斥去重),再检查一次性标记,再检查工具运行时长 >= 100sPreToolUse→ 静默记录 started_at / tool_count,不通知
Supported Channels
| Channel | Method | Features |
|---|---|---|
| macOS | terminal-notifier (+ osascript fallback) | 桌面横幅 + 点击跳转终端 + afplay 音效 |
| 钉钉 | Webhook | Markdown 消息 |
| 飞书 | Webhook | 卡片消息 + 可选 HMAC-SHA256 签名 |
| 企微 | Webhook | Markdown 消息 |
Runtime Files
~/.claude/skills/claude-notify
~/.claude/hooks/notify-router.sh (bash thin wrapper)
~/.claude/hooks/notify-router.js (Node.js main entry)
~/.claude/hooks/lib/config.js
~/.claude/hooks/lib/state.js
~/.claude/hooks/lib/i18n.js
~/.claude/hooks/channels/macos.js
~/.claude/hooks/channels/dingtalk.js
~/.claude/hooks/channels/feishu.js
~/.claude/hooks/channels/wecom.js
~/.claude/notify/config.json
~/.claude/notify/state.json
~/.claude/notify/notify-on-stop
~/.claude/notify/notify.log
Configuration
~/.claude/notify/config.json:
{
"channels": {
"macos": true,
"dingtalk": false,
"feishu": false,
"wecom": false
},
"dingtalk": { "webhook_url": "" },
"feishu": { "webhook_url": "", "secret": "" },
"wecom": { "webhook_url": "" },
"macos": { "sound": "Glass" },
"audio": { "enabled": true },
"long_task": {
"auto_detect": true,
"duration_seconds": 100,
"manual_once": true
}
}
Webhook token 只保存在用户本机,不应提交到仓库。
Install
bash claude-notify/setup.sh
脚本会:检查 Node.js 18+、检测已有安装(升级模式)、备份旧配置、交互式配置各通道、写入 config.json、合并 settings.json hooks、发送测试通知。
升级模式保留旧的 webhook URL,新增字段写入默认值。
Commands
| 命令 | 说明 |
|---|---|
notify-router.sh Status |
查看所有通道状态、阈值、配置文件位置 |
notify-router.sh Doctor |
自检:Skill/Hooks/Config/Node/macOS/terminal-notifier/Webhook |
notify-router.sh TestMacOS |
测试 macOS 桌面通知 |
notify-router.sh TestDingTalk |
测试钉钉通知 |
notify-router.sh TestFeishu |
测试飞书通知 |
notify-router.sh TestWeCom |
测试企微通知 |
notify-router.sh EnableOnce |
开启一次性长任务完成通知 |
notify-router.sh Disable |
软关闭所有通知通道 |
notify-router.sh SetThreshold 600 |
调整长任务阈值(>=60s) |
notify-router.sh UninstallHooks |
从 settings.json 移除 hooks |
bash claude-notify/scripts/test-install.sh |
回归测试 |
Safety Rules
- 修改
~/.claude/settings.json前必须备份。 - 合并 hooks 时不得覆盖已有配置。
- 通知脚本失败不得阻塞 Claude Code(
exit 0)。 - Webhook token 只能保存在用户本机
~/.claude/notify/config.json。 - 非 macOS 环境自动跳过桌面通知和音频,仅使用 Webhook 通道。
Stop防刷屏:Notification 5s 内已发则跳过;无 once 标记且未达 100s 工具时长时不通知。
Requirements
- Node.js 18+
- macOS 通知需
terminal-notifier(可选,未安装时降级为 osascript;brew install terminal-notifier)