Skip to main content

claude code 增加提醒:

  1. claude code 增加提醒:https://linux.do/t/topic/1213841

    前置要求
    macOS 系统
    已安装 Claude 桌面应用 (Claude.app)
    terminal-notifier
    安装步骤
    1. 安装 terminal-notifier
    brew install terminal-notifier
    2. 添加通知脚本
    创建目录

    mkdir -p ~/.claude/hooks
    复制下面的notify.sh脚本到hooks目录下
    #!/bin/bash
    
    # Claude Code 用户操作通知脚本
    # 发送带自定义图标的 macOS 系统通知
    
    MESSAGE="${1:-Claude Code 需要您的操作}"
    
    # 使用自定义应用的 bundle ID 来发送通知
    # 这样左侧会显示 Claude.app 的图标
    terminal-notifier \
      -message "$MESSAGE" \
      -title "Claude Code" \
      -subtitle "请检查终端" \
      -sender "com.anthropic.claudefordesktop" \
      -sound default
    
    exit 0

    添加权限

    chmod +x ~/.claude/hooks/notify.sh

    3. 配置 Claude Code hooks
    将下的内容合并到 ~/.claude/settings.json 的 hooks 部分。

    或者手动编辑 ~/.claude/settings.json,添加:
    {
      "hooks": {
        "Notification": [
          {
            "hooks": [
              {
                "type": "command",
                "command": "bash ~/.claude/hooks/notify.sh '有待处理的操作'"
              }
            ]
          }
        ]
      }
    }

    4. 测试通知
    bash ~/.claude/hooks/notify.sh '测试通知'
    第一次会出现授权,点击允许即可。

    image02
    image02
    758×282 40 KB
    再次测试发送通知,应该看到带 Claude 橙色图标的通知!

    工作原理
    脚本通过 terminal-notifier 的 -sender 参数指定 com.anthropic.claudefordesktop bundle ID,macOS 会自动使用该应用的图标显示通知。

    卸载
    rm -f ~/.claude/hooks/notify.sh
    然后从 ~/.claude/settings.json 中删除 hooks 配置。