当前位置: 首页 > news >正文

Claude Code + Windows 桌面消息通知配置指南

Claude Code Windows 桌面通知配置指南

让 Claude Code 在完成任务后自动弹出 Windows 桌面通知,不用一直盯着屏幕等。

前置条件

  • Windows 10 或 Windows 11
  • Claude Code CLI 已安装并能正常使用

安装步骤

第一步:创建通知脚本

创建目录%USERPROFILE%\.claude\scripts\,然后在其中新建文件notify.ps1,内容如下:

param([string]$Title="Claude Code",[string]$Message="Task 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 duration="short"> <visual> <binding template="ToastGeneric"> <text>$escapedTitle</text> <text>$escapedMessage</text> </binding> </visual> <audio src="ms-winsoundevent:Notification.Default"/> </toast> "@$Xml=New-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$NotifyIcon=New-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 "<MESSAGE>"

If cygpath is not available, use the Windows path directly:

powershell.exe-NoProfile-ExecutionPolicyBypass-Command"&\"$env:USERPROFILE\\.claude\\scripts\\notify.ps1\"-Message '<MESSAGE>'"

After 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中已有其他配置(如envenabledPlugins等),只需把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参数默认值中,直接修改即可

实际效果演示:
在任务完成之后,自动弹窗通知,从此无需盯着命令行窗口,看任务有没有完成

http://www.zskr.cn/news/1323643.html

相关文章:

  • python使用笔记(linux环境)
  • 从芯片到系统:手把手拆解汽车MCU里的安全硬件(SHE/HSE)与独立HSM如何协作
  • 用Python和pywifi写个WiFi密码测试工具(附完整GUI源码)
  • Multi-Agent产品创新:从单一场景到跨域协同的演进
  • 从“马变斑马”到“卫星图转地图”:用CycleGAN/pix2pix玩转自定义数据集(附制作教程)
  • 性价比高生产的重庆轴类加工厂哪家推荐 - 品牌企业推荐师(官方)
  • 5分钟极速上手:BOTW-Save-Editor-GUI 塞尔达传说存档编辑器完整指南
  • 告别PacketSniffer!用CC2531和Ubiqua抓取并解密Zigbee加密数据(保姆级图文教程)
  • STM32G0实战:用CubeMX搞定CANFD和普通CAN双通道配置(附避坑点)
  • 别再到处找教程了!Chrome、Edge、Firefox三款浏览器一键开启Kiosk模式(附快捷方式创建步骤)
  • 告别资金黑洞!搭载AI风控天眼,千万级俱乐部接单平台与三角洲游戏电竞护航陪玩源码系统小程序重铸护航平台生态 - 壹软科技
  • UVM验证中add_typewide_sequence与add_sequence的区别与实战应用
  • 从链表到队列再到递归:三种C++解法搞定SWUST OJ#956约瑟夫问题(附完整代码)
  • RK3568开发板TB-96AI-3568CE深度评测:从核心接口到AI应用实战
  • 建立记忆(KV Cache)
  • Linux进程信息获取全攻略:从ps、top到/proc与psutil
  • 企业AI基建选型指南:托管/半托管/自建架构下的FinOps成本管控策略
  • 从FM收音机到5G基站:拆解DDS技术如何悄悄改变我们的通信设备
  • 创业团队如何利用Taotoken多模型聚合能力优化产品AIB功能
  • 【JavaSE全面教学】Java IO流与文件操作Day14(2026年)
  • 前端开发从入门到精通:Vue3+TypeScript实战教程
  • Perplexity实时新闻查询失效真相:Webhook劫持、缓存穿透与CDN时钟漂移三重陷阱
  • STD算法实战:用Python从零复现激光SLAM中的“稳定三角形”回环检测(附代码)
  • 从Silver Fox新变种看2026年网络钓鱼的攻防进化
  • 别再死记硬背了!用‘按权展开’法5分钟搞定二进制转十进制(C语言实战)
  • 【Perplexity编程搜索权威白皮书】:基于1786次真实编码场景测试,验证TOP3提示词组合准确率提升317%
  • 物理生物学研究报告【20260007】
  • 【无人机协同】联合优化无人机轨迹、发射功率与地面用户-MEC关联的多无人机多地面用户系统 附matlab代码✅
  • TI平台PMSM控制:带传感器与无传感器方案选型与实现详解
  • STM32单片机串口通信避坑指南:从CubeMX配置到中断回调函数编写