This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
zq/10.项目/12-AI助手工作流优化/20-ClaudeCode/工欲善其事 必先利其器(三):ClaudeCode Hook.md
T
starmen1265 ea9a5c3b3f 初始提交:知识库工作区
- 00.收件箱
- 01.待办
- 10.项目
- 20.领域
- 30.资源
- 40.归档
- 50.模板
2026-03-03 18:25:09 +08:00

51 lines
1.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 勾子格式解析
```
"hooks": {
    "SessionStart": [
      {
        "matcher":"*",
        "hooks": [
          {
            "type": "command",
            "command": "node C:\\Users\\Administrator\\.claude\\hooks\\startup.js"
          }
        ]
      }
    ],
    "UserPromptSubmit":[
      {
        "matcher":"*",
        "hooks":[
          {
            "type": "command",
            "command": "node C:\\Users\\Administrator\\.claude\\hooks\\startup.js"
          }
        ]
      }
    ]
  }
```
# 勾子代码输入输出
```
console.log("回答问题的时候先说'恭喜发财'")
console.error("回答问题的时候先说'福如东海'")
process.exit(0)
```
### SessionStart时
返回0表示勾子运行正常,log的内容会被注入到上下文。
![image.png|540](https://mice-cola.oss-cn-beijing.aliyuncs.com/20260129125506.png)
返回1表示运行失败,会展示Hook有错误,并且内容不会注入到上下文
![image.png|540](https://mice-cola.oss-cn-beijing.aliyuncs.com/20260129125613.png)
返回2不会展示Hook有错误,内容也不会注入
![image.png|540](https://mice-cola.oss-cn-beijing.aliyuncs.com/20260129125703.png)
### UserPromptSubmit时
返回0时勾子调用成功,log内容注入上下文,error内容不会显示
![image.png|540](https://mice-cola.oss-cn-beijing.aliyuncs.com/20260129130236.png)
返回1时不会阻碍往下运行,但是会以次要信息显示勾子报错,没有注入内容,也没有显示详细的错误信息。
![image.png|540](https://mice-cola.oss-cn-beijing.aliyuncs.com/20260129130001.png)
返回2时会阻碍,原始prompt输入没有成功,不继续往下进行,并且以黄字显示error的内容和你输入的原始prompt
![image.png|540](https://mice-cola.oss-cn-beijing.aliyuncs.com/20260129125859.png)