Windows Toast Notify
功能概述
Windows Toast Notify 是一个系统通知技能,让 Claude Code 在关键时刻主动通知用户,类似 Mac Dock 小红点的效果。通过配置 hooks,可以在任务完成、需要确认、等待输入等场景自动触发 Windows 系统通知。
通知类型
| 类型 | 标题 | 触发场景 | 用途 |
|---|---|---|---|
complete | ✅ 任务完成 | Stop hook | 代码完成、bug修复、功能实现 |
confirm | ⏳ 需要确认 | PermissionRequest、EnterPlanMode | 需要用户审批或确认 |
wait | 🔔 等待响应 | AskUserQuestion | Claude提问、请求信息 |
milestone | 🎯 关键节点 | 自定义使用 | 重要进度、阶段切换 |
error | ❌ 执行失败 | 自定义使用 | 错误、异常情况 |
工作原理
- Hook 触发: Claude Code 在特定事件时执行配置的 hooks
- PowerShell 脚本: 调用
notify.ps1发送 Windows Toast 通知 - 系统通知中心: 通知显示在 Windows 通知中心,支持声音提示
权限预允许机制
Claude Code 的权限系统有两层配置:
- 全局配置:
~/.claude/settings.json中的permissions.allow - 本地配置: 工作目录
.claude/settings.local.json中的permissions.allow
当用户首次允许某个操作后,权限被记录到本地配置,下次执行相同操作时:
- 首次请求:
PermissionRequesthook 触发 → 发送通知 - 已预允许: 静默执行,不触发任何 hook,无通知
配置指南
1. 文件结构
~/.claude/skills/windows-toast-notify/ ├── SKILL.md # 技能说明文档 ├── scripts/ │ ├── notify.ps1 # 主通知脚本 │ └── teammate-idle-notify.ps1 # 团队成员空闲通知 └── assets/ └── icon.png # 通知图标(可选)2. 基础配置
在~/.claude/settings.json中配置 hooks:
{"hooks":{"PermissionRequest":[{"matcher":"","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File ~/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type confirm -Message 'Claude需要你的确认' -Sound"}]}],"PostToolUse":[{"matcher":"EnterPlanMode","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File ~/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type confirm -Message '请审批计划' -Sound"}]},{"matcher":"AskUserQuestion","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File ~/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type confirm -Message 'Claude需要你的输入' -Sound"}]}],"Stop":[{"matcher":"","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File ~/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type complete -Message '任务已完成' -Sound"}]}]}}3. 脚本参数
notify.ps1支持以下参数:
powershell-ExecutionPolicy Bypass-File notify.ps1 `-Type<类型> `-Message <消息内容> `[-Sound]`[-Duration <显示秒数>]| 参数 | 必需 | 说明 | 示例 |
|---|---|---|---|
-Type | 是 | 通知类型 | complete,confirm,wait,milestone,error |
-Message | 是 | 通知内容 | '任务已完成' |
-Sound | 否 | 播放提示音 | 添加此参数启用 |
-Duration | 否 | 显示时长(秒) | 5(默认值) |
4. 使用 /update-config 配置
推荐使用/update-config技能配置,避免手动编辑出错:
/update-config 添加通知hooks: - PermissionRequest时发送confirm通知并播放声音 - EnterPlanMode时发送confirm通知并播放声音 - AskUserQuestion时发送confirm通知并播放声音 - Stop时发送complete通知并播放声音5. 验证配置
测试通知是否正常工作:
powershell-ExecutionPolicyBypass-File~/.claude/skills/windows-toast-notify/scripts/notify.ps1-Typecomplete-Message"测试通知"-Sound安全考虑
1. 脚本执行权限
风险: PowerShell 脚本可能执行恶意代码
安全措施:
- 使用
-ExecutionPolicy Bypass仅用于信任的脚本 - 脚本位于用户目录
~/.claude/skills/,需用户明确创建 - 脚本内容仅调用 Windows Toast API,不执行系统修改
建议:
# 定期审查脚本内容Get-Content~/.claude/skills/windows-toast-notify/scripts/notify.ps12. Hook 配置安全
风险: 恶意 hook 可执行任意命令
安全措施:
settings.json由用户手动编辑或通过/update-config配置- Claude Code 在执行 hook 前不请求额外权限(hooks 在 harness 层执行)
- 命令仅限 PowerShell 调用通知脚本
建议:
- 不要在 hook 命令中包含敏感信息
- 定期检查
settings.json中的 hooks 配置
3. 通知内容安全
风险: 通知内容可能暴露敏感信息(如文件路径、命令)
安全措施:
- 通知消息应使用通用描述,避免包含敏感路径或命令
- 通知显示在系统通知中心,其他应用可能读取
建议消息格式:
// 安全 ✓ - 通用描述"Message":"任务已完成""Message":"Claude需要你的确认"// 不安全 ✗ - 包含敏感信息"Message":"密码文件 /etc/shadow 已修改""Message":"执行命令: rm -rf /home/user"4. Windows 通知权限
系统级配置:
- 打开 Windows 设置 → 系统 → 通知
- 确保 “获取来自应用和其他发送者的通知” 已开启
- 可单独配置 PowerShell 或 Claude Code 的通知权限
隐私考虑:
- 通知内容会出现在通知中心历史记录
- 锁屏时通知可能可见
- 可在 Windows 设置中关闭锁屏通知
5. 网络安全
无网络请求:notify.ps1脚本完全本地执行,不发送任何网络请求
数据存储: 所有配置保存在本地settings.json,不上传云端
常见问题
通知没有出现?
检查 Windows 通知设置
- 设置 → 系统 → 通知 → 开启通知
- 确保 “允许应用发送通知” 已启用
验证脚本路径
Test-Path ~/.claude/skills/windows-toast-notify/scripts/notify.ps1手动测试
powershell-ExecutionPolicyBypass-File~/.claude/skills/windows-toast-notify/scripts/notify.ps1-Typecomplete-Message"测试"检查 BurntToast 模块(可选)
Get-Module-ListAvailable-Name BurntToast
想要自定义图标?
- 准备 PNG 图标文件
- 放置到
~/.claude/skills/windows-toast-notify/assets/icon.png - 修改
notify.ps1中的-AppLogo参数
想要不同的声音?
修改notify.ps1中的声音配置:
# Windows 系统声音选项$buttonParams= @{Sound ='Notification.Default'}# 默认$buttonParams= @{Sound ='Notification.Looping.Alarm'}# 闹钟$buttonParams= @{Sound ='Notification.Looping.Call'}# 呼叫附录:完整配置示例
{"hooks":{"PermissionRequest":[{"matcher":"","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File C:/Users/admin/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type confirm -Message 'Claude需要你的确认' -Sound"}]}],"PostToolUse":[{"matcher":"EnterPlanMode","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File C:/Users/admin/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type confirm -Message '请审批Claude的计划' -Sound"}]},{"matcher":"ExitPlanMode","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File C:/Users/admin/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type milestone -Message '计划已批准,开始执行'"}]},{"matcher":"AskUserQuestion","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File C:/Users/admin/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type confirm -Message 'Claude需要你的输入' -Sound"}]}],"TeammateIdle":[{"matcher":"","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File C:/Users/admin/.claude/skills/windows-toast-notify/scripts/teammate-idle-notify.ps1"}]}],"Stop":[{"matcher":"","hooks":[{"type":"command","command":"powershell -ExecutionPolicy Bypass -File C:/Users/admin/.claude/skills/windows-toast-notify/scripts/notify.ps1 -Type complete -Message '任务已完成' -Sound"}]}]}}版本信息
- 版本: 1.0.0
- 适用平台: Windows 10/11
- 依赖: PowerShell 5.1+ 或 PowerShell 7+
- 可选依赖: BurntToast PowerShell 模块(增强通知体验)