Claude Code 完成通知:提示弹窗与提示音
Claude 较长的一轮结束时弹出「Done in 2m 14s」提示并播放短促提示音,还可选发送桌面通知。
权限
- 执行命令可以在你的电脑上运行 shell 程序($.process.run / spawn)。具体运行哪些程序请查看源码。
- 修改界面在 Claude Code 界面中绘制内容:横条、面板、状态文字、弹出通知(ui.render / $.ui.*)。
- 播放声音可以播放音频或朗读文字($.audio.*)。
- 实测版本
- v2.1.291
- 最近实测
- 需要
- Claude Code ≥ 2.1.287
- 显示位置
- 弹出通知
这个插件能做什么?
完成提示(Done Toast)为你提供 Claude Code 完成通知:当一轮耗时较长的对话结束时,会弹出一条写着 Done in 2m 14s 的提示,同时播放一段简短的双音提示音。如果这一轮以错误结束,则会显示 Stopped on an error after 2m 14s。较短的轮次、被中断的轮次和子代理的轮次都保持静默,所以只要听到这个声音,就意味着“回来吧,你的回答已经好了”。
如果你在长任务进行期间会切到别的窗口工作,可以开启系统通知选项,同样的消息就会出现在 macOS 通知中心,或以 Linux notify-send 弹窗的形式显示。需要 Claude Code 2.1.287 或更高版本。
演示
录屏中,我们给 Claude 发送一个耗时超过阈值的任务。这一轮完成时,屏幕底部会出现一条显示本轮耗时的提示。
安装
从安装区块中选择一种方式即可。在 macOS 上声音开箱即用;系统通知需要手动开启。
$ install cm-done-toast
需要 Claude Code ≥ 2.1.287
1.在 Claude Code 中一行安装
/plugin install cm-done-toast --marketplace rotbit/claudemods-marketplace粘贴到正在运行的会话中(v2.1.275+)。Claude Code 会先询问是否添加该插件市场。
2.从终端安装
claude plugin marketplace add rotbit/claudemods-marketplace claude plugin install cm-done-toast@claudemods然后在所有已打开的会话中运行 /reload-plugins。
3.免安装试用
git clone https://github.com/rotbit/claudemods-marketplace claude --plugin-dir ./claudemods-marketplace/cm-done-toast仅在当前会话中加载该插件,不会写入你的设置。
工作原理
这个插件只有一个钩子。以下摘自 hooks/register.ts:
on('turn.complete', async ($, e, next) => {
const result = await next(e)
if (!shouldNotify(e, minSeconds)) return result
const text = toastText(e, includeAnswerPreview)
$.ui.toast(text)
if (sound) {
$.audio.play({ asset: 'sounds/done.wav' }).catch(() => undefined)
}
if (systemNotification) {
platform ??= $.process
.run(['uname', '-s'], { timeoutMs: 5000 })
.then(ran => (ran.exitCode === 0 ? parseUname(ran.stdout) : undefined))
.catch(() => undefined)
platform
.then(found =>
found === undefined ? undefined : $.process.run(notificationArgv(found, 'Claude Code', text), { timeoutMs: 10000 }),
)
.catch(() => undefined)
}
return result
})turn.complete 会在 Claude 完成一轮对话时触发。钩子会先等待 next(e),因此绝不会拖慢这一轮的结果。hooks/format.ts 中的 shouldNotify 对子代理轮次(带有 agentId 的轮次)、被中止的轮次以及短于 minSeconds 的轮次返回 false。toastText 会把耗时格式化为 45s、2m 14s 或 1h 3m。
提示音是随插件一起打包的 sounds/done.wav,通过 $.audio.play 播放。插件 API 没有平台字段,也没有发送通知的调用,所以在开启系统通知时,插件会执行一次 uname -s 并缓存结果。之后它会在 macOS 上运行 osascript -e 'display notification …',在 Linux 上运行 notify-send。参数以 argv 数组的形式传入,不经过 shell,因此 Claude 回答中的引号无法造成注入。声音和通知都是“发出即不管”的,出现的错误会被直接吞掉。
自定义
在 /config 中修改这些选项。想换成自己的声音,可以替换插件文件夹中的 sounds/done.wav,或修改钩子里的 asset 路径。提示文字来自 hooks/format.ts 中的 toastText,通知标题 'Claude Code' 则是 notificationArgv 的第二个参数。
| 设置项 | 类型 | 默认值 | 作用 |
|---|---|---|---|
| minSeconds | number | 30 | Minimum turn length (seconds). Only turns at least this long raise the toast, sound and notification. |
| sound | boolean | true | Play a sound. Play a short chime when the turn finishes (macOS only: Claude Code plays clips with afplay). |
| systemNotification | boolean | false | System notification. Also raise a desktop notification via osascript (macOS) or notify-send (Linux). |
| includeAnswerPreview | boolean | false | Include answer preview. Add the first 80 characters of Claude's answer to the toast and notification. |
在 Claude Code 中通过 /config 修改这些设置,插件会热重载。
权限与安全
修改界面对应提示通知,播放声音对应提示音。之所以会出现执行命令,是因为代码中用到了 $.process.run,但它只在你开启 systemNotification 后才会使用:届时它会运行一次 uname -s,然后以固定参数运行 osascript 或 notify-send。在默认设置下,不会启动任何进程。
该插件不会拦截工具调用、不读取你的提示词、不接触文件,也不使用网络。可以用 /plugin disable cm-done-toast 停用它,或者用 claude --safe-mode 启动一个关闭所有插件的会话。
- 执行命令
- 可以在你的电脑上运行 shell 程序($.process.run / spawn)。具体运行哪些程序请查看源码。
- 修改界面
- 在 Claude Code 界面中绘制内容:横条、面板、状态文字、弹出通知(ui.render / $.ui.*)。
- 播放声音
- 可以播放音频或朗读文字($.audio.*)。
兼容性与故障排除
已在 macOS 终端中使用 Claude Code 2.1.291 测试。如果一轮结束时什么都没有发生:
- 确认
claude --version为 2.1.287 或更高版本,并且该插件已在/plugin中启用。 - 通过 shell 安装后,运行
/reload-plugins。 - 这一轮可能短于
minSeconds。 - 在 macOS 以外的系统上没有声音,这是预期行为。
- 在 macOS 上,如果系统通知始终不出现,请在“系统设置”中允许你的终端应用发送通知。
- 在 Linux 上,需要安装 libnotify(
notify-send)才能使用系统通知。
常见问题
- 为什么一个简短的回答之后没有收到通知?
- 短于 minSeconds(默认 30 秒)的对话轮次不会提醒。把 minSeconds 设为 0,即可在每一轮结束时都收到通知。
- 为什么在 Linux 或 Windows 上没有声音?
- Claude Code 使用 afplay 播放音频片段,而 afplay 只存在于 macOS。提示通知在所有平台上都会照常显示。
- 怎样获得 macOS 通知中心的提醒?
- 在 /config 中开启 systemNotification。之后插件会在 macOS 上运行 osascript,在 Linux 上运行 notify-send。macOS 可能会询问一次是否允许你的终端发送通知。
- 子代理会触发它吗?
- 不会。带有 agentId 的轮次会被跳过,被中断的轮次也一样,所以每个回答只会收到一次通知。
- 通知里可以包含 Claude 的回答吗?
- 开启 includeAnswerPreview 即可附上回答的前 80 个字符。它默认关闭,因为开启后这段文字会出现在你的系统通知历史中。
# 相关插件


工具调用计数器
统计 Claude 每轮和每个会话的工具调用次数,在加载指示器旁显示计数,并新增 /tally 查看明细。
- 加载动画
- 对话记录
- 状态栏
- 拦截工具调用
- 修改界面
- 添加命令/工具
已在 v2.1.291 实测
