claude-hooks

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Claude Hooks Skill

Claude Hooks Skill

Creates and configures hooks for Claude Code to automate workflows and extend functionality.
为Claude Code创建并配置钩子,以实现工作流自动化并扩展功能。

What This Skill Does

本技能功能

  • Creates PreToolUse validation hooks
  • Sets up PostToolUse logging/cleanup
  • Configures notification hooks
  • Implements custom automation
  • Documents hook patterns
  • 创建PreToolUse验证钩子
  • 配置PostToolUse日志记录/清理
  • 设置通知钩子
  • 实现自定义自动化
  • 记录钩子模式

When to Use

使用场景

  • Tool execution validation
  • Audit logging
  • Custom notifications
  • Workflow automation
  • Security controls
  • 工具执行验证
  • 审计日志
  • 自定义通知
  • 工作流自动化
  • 安全控制

Reference Files

参考文件

  • references/CLAUDE_HOOK.template.md
    - Hook configuration examples and patterns
  • references/CLAUDE_HOOK.template.md
    - 钩子配置示例与模式

Hook Events

钩子事件

EventTriggerUse Case
PreToolUseBefore tool executesValidation, blocking
PostToolUseAfter tool completesLogging, cleanup
NotificationClaude sends notificationAlerts
StopClaude stopsFinal reports
事件触发条件使用场景
PreToolUse工具执行前验证、拦截
PostToolUse工具完成后日志记录、清理
NotificationClaude发送通知时告警
StopClaude停止时最终报告

Configuration Location

配置位置

Hooks are configured in
~/.claude/settings.json
under the
hooks
key.
钩子配置在
~/.claude/settings.json
hooks
键下。

Best Practices

最佳实践

  • Keep hooks fast (< 1 second)
  • Handle errors gracefully
  • Use specific matchers
  • Test hooks independently
  • Avoid verbose output
  • 保持钩子执行快速(< 1秒)
  • 优雅处理错误
  • 使用特定匹配器
  • 独立测试钩子
  • 避免冗余输出