技能 claude-hooks
�
Claude Code 钩子可在 AI 工具执行期间启用自动驗證、記錄和通知功能。此技能提供配置 PreToolUse、PostToolUse、Notification 和 Stop 钩子的模板和最佳实践。
支援: Claude Code(CC)
1
下載技能 ZIP
2
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
3
開啟並開始使用
測試它
正在使用「claude-hooks」。 How do I create a hook that logs every file that Claude writes?
預期結果:
- Add this to your ~/.claude/settings.json under the 'hooks' key:
- • Use PostToolUse event to capture writes after they complete
- • Matcher pattern 'Write' targets only file write operations
- • Command uses $CLAUDE_FILE_PATH environment variable
- • Appends each file path to ~/.claude/file_log.txt
安全審計
安全v3 • 1/10/2026
This skill contains only markdown documentation files with hook configuration templates. No executable code, scripts, network calls, or file system access. Pure reference content for Claude Code hook configuration.
2
已掃描檔案
146
分析行數
0
發現項
3
審計總數
未發現安全問題
審計者: claude 查看審計歷史 →
品質評分
41
架構
100
可維護性
81
內容
31
社群
100
安全
87
規範符合性
你能建構什麼
审核工具执行
記錄所有 Claude Code 工具调用以进行合规审核和安全审查
强制执行编码标准
在执行前驗證代码更改以强制执行团队约定
自定义通知
当特定工具完成或失败时向外部系统发送警报
試試這些提示
创建驗證钩子
Show me how to create a PreToolUse hook that validates Bash commands before they run
设置日志记录
Create a PostToolUse hook that logs all file write operations to a file
通知集成
Configure a Notification hook that sends alerts to Slack when Claude completes tasks
匹配器模式
Explain the different matcher patterns I can use to target specific tools like Bash(git:*) or MCP tools
最佳實務
- 保持钩子快速(1 秒内)以避免阻塞 Claude Code 执行
- 使用特定的匹配器模式而非通配符来仅定位需要的工具
- 使用适当的 shell 错误处理优雅地处理错误以防止级联故障
避免
- 在钩子中使用冗长日志记录而向对话上下文添加过多输出
- 创建没有超时处理而无限期阻塞的钩子
- 为所有工具 (*) 配置钩子而仅需要特定工具自动化
常見問題
哪些 Claude 版本支持钩子?
Hooks require Claude Code version 0.9.0 or later. Check your installation with 'claude --version'.
钩子的最大执行时间是多久?
Hooks should complete in under 1 second. Long-running hooks will block Claude Code tool execution.
钩子如何与 MCP 工具集成?
Use matcher pattern 'mcp__*' to target all MCP tools, or specific MCP tool names for individual tools.
钩子是否安全?
Hooks run as your user with your permissions. Only install hooks from trusted sources and review commands before use.
为什么我的钩子没有触发?
Check that your settings.json has correct JSON syntax, the event name matches (PreToolUse, PostToolUse), and matcher patterns are valid.
钩子与自定义指令有何不同?
Hooks execute shell commands automatically on events, while custom instructions affect Claude's behavior through prompt context.
開發者詳情
授權
UNLICENSED
引用
main
檔案結構