惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
NISL@THU
NISL@THU
T
Tor Project blog
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
O
OpenAI News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
V2EX - 技术
V2EX - 技术
H
Help Net Security
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
Forbes - Security
Forbes - Security
人人都是产品经理
人人都是产品经理
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
I
InfoQ
Schneier on Security
Schneier on Security
K
Kaspersky official blog
罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Security Affairs
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
雷峰网
雷峰网
G
GRAHAM CLULEY
Cloudbric
Cloudbric
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
AI
AI
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
博客园_首页
T
Threat Research - Cisco Blogs
S
Secure Thoughts
有赞技术团队
有赞技术团队

博客园 - 陈大欠

andrej karpathy skills 从 Harness Engineering 到 superpowers 从 Harness Engineering 到 OpenSpec 从 Harness Engineering 到 Trellis Harness Engineering copilot-api:让 ClaudeCode 接入 Github Copilot Scoop Claude-LED MagicCenterHub Windows Terminal & PowerShell 玩转 Visual Studio 外部工具 WCF API 语义搜索工具 Step Builder:让对象构建有顺序、有边界、有校验 基于 Attribute 的 AOP 字段校验 浅析 .NET 响应式编程 IObservable与ReactiveX Cron表达式简明教程 正则表达式拾遗 快速批量升级 NugetPackage 版本 C# IEquatable和IEqualityComparer 最佳实践 使用XDT提高开发效率 如何保证XML正确性 分析 Dump 入门简明教程 Git commit emoji 对照表 ELK Stack 笔记 HTML5/CSS3(PrefixFree.js) 3D文字特效 Jquery实现图片上下一张 js css 构建滚动边框 使用jquery构建Metro style 返回顶部 使用js实现移动设备访问跳转到指定目录 从一幅图中了解开源世界 Jquery ajax 学习笔记 工欲善其事必先利其器系列之:在VS里面折叠js代码
Claude Code Hooks 配置说明
陈大欠 · 2026-07-18 · via 博客园 - 陈大欠

Claude Code Hooks 配置说明

概述

本配置使用 Windows Toast 通知系统,在 Claude Code 执行关键事件时发送桌面通知,让你无需盯着终端即可了解任务状态。

前置依赖

  • PowerShell 5+ (pwsh)
  • BurntToast 模块 - Windows 原生通知库

安装命令:

Install-Module -Name BurntToast -Force -Scope CurrentUser

完整配置示例

以下是 ~/.claude/settings.json 中的 hooks 配置:

{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "pwsh -ExecutionPolicy RemoteSigned -Command \"Import-Module BurntToast; New-BurntToastNotification -Text (Split-Path -Leaf (Get-Location)), '√ 任务已完成,请检查结果' -AppLogo D:\\OneDrive\\ApplicationData\\icon\\Claude.png -Sound Default\""
          }
        ]
      }
    ],
    "Notification": [
      {
        "matcher": "permission_prompt",
        "hooks": [
          {
            "type": "command",
            "command": "pwsh -ExecutionPolicy RemoteSigned -Command \"Import-Module BurntToast; New-BurntToastNotification -Text (Split-Path -Leaf (Get-Location)), '! 需要你审批权限' -Sound Default\""
          }
        ]
      },
      {
        "matcher": "idle_prompt",
        "hooks": [
          {
            "type": "command",
            "command": "pwsh -ExecutionPolicy RemoteSigned -Command \"Import-Module BurntToast; New-BurntToastNotification -Text (Split-Path -Leaf (Get-Location)), '+ 正在等待你的输入' -Sound Default\""
          }
        ]
      }
    ]
  }
}

Hooks 详解

1. Stop Hook - 任务完成通知

触发时机:Claude Code 完成任务并停止响应时

配置

{
  "Stop": [
    {
      "matcher": "",
      "hooks": [
        {
          "type": "command",
          "command": "pwsh -ExecutionPolicy RemoteSigned -Command \"Import-Module BurntToast; New-BurntToastNotification -Text (Split-Path -Leaf (Get-Location)), '√ 任务已完成,请检查结果' -AppLogo D:\\OneDrive\\ApplicationData\\icon\\Claude.png -Sound Default\""
        }
      ]
    }
  ]
}

通知效果

  • 标题:当前工作目录名称
  • 消息:√ 任务已完成,请检查结果
  • 声音:默认提示音
  • 图标:自定义 Claude 图标(D:\OneDrive\ApplicationData\icon\Claude.png)

2. Notification Hook - 权限审批通知

触发时机:Claude Code 需要执行权限时弹出审批提示

配置

{
  "Notification": [
    {
      "matcher": "permission_prompt",
      "hooks": [
        {
          "type": "command",
          "command": "pwsh -ExecutionPolicy RemoteSigned -Command \"Import-Module BurntToast; New-BurntToastNotification -Text (Split-Path -Leaf (Get-Location)), '! 需要你审批权限' -Sound Default\""
        }
      ]
    }
  ]
}

通知效果

  • 标题:当前工作目录名称
  • 消息:! 需要你审批权限
  • 声音:默认提示音

3. Notification Hook - 空闲输入通知

触发时机:Claude Code 等待用户输入时

配置

{
  "Notification": [
    {
      "matcher": "idle_prompt",
      "hooks": [
        {
          "type": "command",
          "command": "pwsh -ExecutionPolicy RemoteSigned -Command \"Import-Module BurntToast; New-BurntToastNotification -Text (Split-Path -Leaf (Get-Location)), '+ 正在等待你的输入' -Sound Default\""
        }
      ]
    }
  ]
}

通知效果

  • 标题:当前工作目录名称
  • 消息:+ 正在等待你的输入
  • 声音:默认提示音

工作流程

Claude Code 执行中
       ↓
  ┌────┴────┐
  ↓         ↓
需要权限   等待输入
  ↓         ↓
! 通知    + 通知
  ↓         ↓
用户审批   用户输入
  ↓         ↓
  └────┬────┘
       ↓
    任务完成
       ↓
    √ 通知

自定义修改指南

更换通知图标

修改 -AppLogo 参数路径:

-AppLogo "D:\你的图标路径.png"

关闭声音

移除 -Sound Default 参数或改为:

-Sound None

更换通知文本

直接修改单引号内的中文消息内容,例如:

'你的自定义消息'

修改通知标题

当前标题是动态获取的工作目录名:

(Split-Path -Leaf (Get-Location))

可改为固定标题:

'我的项目'

BurntToast 常用参数

参数 说明 示例
-Text 标题和消息 -Text '标题', '内容'
-AppLogo 图标路径 -AppLogo 'C:\icon.png'
-Sound 提示音 -Sound Default / -Sound None
-ExpirationTime 通知过期时间 -ExpirationTime (Get-Date).AddMinutes(5)

调试命令

测试 BurntToast 是否正常工作:

Import-Module BurntToast
New-BurntToastNotification -Text '测试', '通知正常工作' -Sound Default

参考链接