Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
evanfang0054 avatar

Hook Creator

  • 2 installs
  • 1 repo stars
  • Updated July 28, 2026
  • evanfang0054/cc-system-creator-scripts

Creates and configures Claude Code hooks that run shell commands on lifecycle events like PreToolUse and PostToolUse for formatting, logging, or file protection.

About

Guides building Claude Code hooks by choosing an event, writing a stdin-JSON shell command, configuring matchers, and picking user or project settings scope. A developer uses it to add auto-formatting, logging, notifications, or file-protection hooks.

  • Covers PreToolUse/PostToolUse/Notification events and matchers
  • Writes hooks to user or project settings.json with test guidance

Hook Creator by the numbers

  • 2 all-time installs (skills.sh)
  • Ranked #1,839 of 2,715 Automation & Workflows skills by installs in the Skillselion catalog
  • Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/evanfang0054/cc-system-creator-scripts --skill hook-creator

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs2
repo stars1
Last updatedJuly 28, 2026
Repositoryevanfang0054/cc-system-creator-scripts

What it does

Creates and configures Claude Code hooks that run shell commands on lifecycle events like PreToolUse and PostToolUse for formatting, logging, or file protection.

Files

SKILL.mdMarkdownGitHub ↗

Hook 钩子创建器

创建在特定生命周期事件中执行 shell 命令的 Claude Code 钩子。

钩子创建工作流程

1. 确定使用场景 - 明确钩子需要完成的功能 2. 选择合适的事件 - 从可用的钩子事件中选择(参见 references/hook-events.md) 3. 设计钩子命令 - 编写从 stdin 处理 JSON 输入的 shell 命令 4. 配置匹配器 - 设置工具/事件过滤器(使用 * 匹配所有,或指定工具名称如 BashEdit|Write) 5. 选择存储位置 - 用户设置(~/.claude/settings.json)或项目(.claude/settings.json) 6. 测试钩子 - 使用简单测试用例验证行为

钩子配置结构

{
  "hooks": {
    "<事件名称>": [
      {
        "matcher": "<工具模式>",
        "hooks": [
          {
            "type": "command",
            "command": "<shell命令>"
          }
        ]
      }
    ]
  }
}

常用模式

读取输入数据

钩子通过 stdin 接收 JSON。使用 jq 提取字段:

# 提取工具输入字段
jq -r '.tool_input.file_path'

# 带默认值的提取
jq -r '.tool_input.description // "无描述"'

# 条件处理
jq -r 'if .tool_input.file_path then .tool_input.file_path else empty end'

PreToolUse 的退出代码

  • 0 - 允许工具继续执行
  • 2 - 阻止工具并向 Claude 提供反馈

匹配器模式

  • * - 匹配所有工具
  • Bash - 仅匹配 Bash 工具
  • Edit|Write - 匹配 Edit 或 Write 工具
  • Read - 匹配 Read 工具

快速示例

记录所有 bash 命令:

jq -r '"\(.tool_input.command)"' >> ~/.claude/bash-log.txt

编辑后自动格式化 TypeScript:

jq -r '.tool_input.file_path' | { read f; [[ "$f" == *.ts ]] && npx prettier --write "$f"; }

阻止编辑 .env 文件:

python3 -c "import json,sys; p=json.load(sys.stdin).get('tool_input',{}).get('file_path',''); sys.exit(2 if '.env' in p else 0)"

资源文档

  • 钩子事件参考:查看 references/hook-events.md 了解详细的事件文档,包含输入/输出架构
  • 示例配置:查看 references/examples.md 获取完整的、经过测试的钩子配置

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.