Claude Code + Windows 桌面消息通知配置指南
Claude Code Windows 桌面通知配置指南让 Claude Code 在完成任务后自动弹出 Windows 桌面通知不用一直盯着屏幕等。前置条件Windows 10 或 Windows 11Claude Code CLI 已安装并能正常使用安装步骤第一步创建通知脚本创建目录%USERPROFILE%\.claude\scripts\然后在其中新建文件notify.ps1内容如下param([string]$TitleClaude Code,[string]$MessageTask completed!)try{[void][Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType WindowsRuntime][void][Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom, ContentType WindowsRuntime]$AppId{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe$escapedTitle[System.Security.SecurityElement]::Escape($Title)$escapedMessage[System.Security.SecurityElement]::Escape($Message)$Template toast durationshort visual binding templateToastGeneric text$escapedTitle/text text$escapedMessage/text /binding /visual audio srcms-winsoundevent:Notification.Default/ /toast $XmlNew-ObjectWindows.Data.Xml.Dom.XmlDocument$Xml.LoadXml($Template)$Toast[Windows.UI.Notifications.ToastNotification]::new($Xml)[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($AppId).Show($Toast)}catch{Add-Type-AssemblyName System.Windows.Forms$NotifyIconNew-ObjectSystem.Windows.Forms.NotifyIcon$NotifyIcon.Icon [System.Drawing.SystemIcons]::Information$NotifyIcon.BalloonTipTitle $Title$NotifyIcon.BalloonTipText $Message$NotifyIcon.Visible $true$NotifyIcon.ShowBalloonTip(10000)Start-Sleep-Seconds 5$NotifyIcon.Dispose()}第二步创建自定义命令可选支持手动发通知创建目录%USERPROFILE%\.claude\commands\然后在其中新建文件notify.md内容如下Send a Windows desktop toast notification to inform the user. The user typed: $ARGUMENTS If $ARGUMENTS is empty, use the default message: Claude Code 任务完成 Run this bash command to send the notification (replace MESSAGE with the notification text): bash powershell.exe -NoProfile -ExecutionPolicy Bypass -File $(cygpath -w $HOME/.claude/scripts/notify.ps1) -Message MESSAGEIf cygpath is not available, use the Windows path directly:powershell.exe-NoProfile-ExecutionPolicyBypass-Command\$env:USERPROFILE\\.claude\\scripts\\notify.ps1\-Message MESSAGEAfter sending the notification, briefly tell the user “已发送桌面通知”.### 第三步配置 Stop Hook自动通知 打开 %USERPROFILE%\.claude\settings.json在 JSON 根对象中添加 hooks 字段。 **完整的 settings.json 示例** json { hooks: { Stop: [ { matcher: , hooks: [ { type: command, command: powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:/Users/你的用户名/.claude/scripts/notify.ps1, async: true } ] } ] } }注意把C:/Users/你的用户名/替换为同事的实际用户目录路径。可以用echo %USERPROFILE%在 cmd 中查看。如果settings.json中已有其他配置如env、enabledPlugins等只需把hooks字段追加进去即可不要覆盖原有内容。第四步验证在 Claude Code 中直接输入以下内容让 Claude 发一条测试通知请运行 powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:/Users/你的用户名/.claude/scripts/notify.ps1 -Title 测试 -Message 通知功能正常如果右下角弹出 Windows Toast 通知说明配置成功。文件结构总览%USERPROFILE%\.claude\ ├── scripts\ │ └── notify.ps1 ← 通知脚本必需 ├── commands\ │ └── notify.md ← 手动命令可选 └── settings.json ← Hook 配置必需使用方式方式说明自动通知每次 Claude 完成回复自动弹出通知手动通知在 Claude Code 中输入/notify 自定义消息常见问题Q: 没有弹出通知确认 Windows 通知设置中没有禁用 PowerShell 的通知权限设置 → 系统 → 通知确认文件路径正确没有中文或特殊字符Q: 每次回复都弹通知太频繁从settings.json中删除整个hooks字段即可关闭自动通知只保留/notify手动命令需要时再用Q: 通知内容能自定义吗可以。手动通知通过/notify 消息内容自定义自动通知的默认消息定义在notify.ps1的$Message参数默认值中直接修改即可实际效果演示在任务完成之后自动弹窗通知从此无需盯着命令行窗口看任务有没有完成