Skip to content

mrlong0129/claude-code-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Notifier

当 Claude 需要你输入时,发送系统通知提醒。即使你在其他应用中工作,也不会错过。

English

效果

当 Claude 等待你的输入时:

  • macOS: 系统通知 + Glass 提示音
  • Linux: 桌面通知
  • Windows: Toast 通知

安装

macOS

将以下配置添加到你的 ~/.claude/settings.local.json

{
  "hooks": {
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "bash -c 'osascript -e \"display notification \\\"${TERMINAL_NAME:-$(basename $PWD)} needs your input\\\" with title \\\"Claude Code\\\" sound name \\\"Glass\\\"\"'"
          }
        ]
      }
    ]
  }
}

如果你的 settings.local.json 已有其他配置,只需将 hooks 部分合并进去。

Linux

确保安装了 notify-send(大多数发行版预装):

{
  "hooks": {
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "notify-send 'Claude Code' \"${TERMINAL_NAME:-$(basename $PWD)} needs your input\" --urgency=normal"
          }
        ]
      }
    ]
  }
}

Windows

使用 PowerShell toast 通知:

{
  "hooks": {
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "powershell -Command \"[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null; $xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02); $text = $xml.GetElementsByTagName('text'); $text[0].AppendChild($xml.CreateTextNode('Claude Code')) | Out-Null; $text[1].AppendChild($xml.CreateTextNode('Needs your input')) | Out-Null; [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Claude Code').Show([Windows.UI.Notifications.ToastNotification]::new($xml))\""
          }
        ]
      }
    ]
  }
}

工作原理

Claude Code 提供 Notification hook 事件,当 Claude 需要用户输入时触发。

我们利用这个事件执行系统命令来显示通知:

  • macOS: osascript (AppleScript)
  • Linux: notify-send
  • Windows: PowerShell toast

自定义

修改提示音(macOS)

更改 sound name "Glass" 为其他系统音效:

Basso | Blow | Bottle | Frog | Funk | Glass | Hero | Morse | Ping | Pop | Purr | Sosumi | Submarine | Tink

修改通知文案

替换 needs your input 为你喜欢的文案。

添加匹配条件

"matcher": "" 表示匹配所有通知。你可以设置特定条件来过滤。

常见问题

Q: macOS 没有收到通知?

检查:系统设置 → 通知 → 允许 Terminal/iTerm/Warp 发送通知

Q: 如何测试?

运行 Claude Code,在 Claude 响应后等待它提问或需要确认时就会触发。

Q: 已有 settings.local.json 怎么办?

hooks 部分合并到现有配置中即可。

License

MIT

About

Get system notifications when Claude Code needs your input

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors