Token导航 LogoToken导航TokenDH.com
AI 工具执行命令github未标认证来源可访问clear审计通过

create-hooks创建钩子

Agent Skill

create-hooks 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

233

周安装

10

GitHub Stars

16

下载量

82
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:create-hooks(创建钩子)
来源仓库:https://github.com/cfircoo/claude-code-toolkit
仓库路径:skills/create-hooks
安装命令:
npx skills add https://github.com/cfircoo/claude-code-toolkit --skill create-hooks
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/cfircoo/claude-code-toolkit --skill create-hooks

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在需要整理仓库状态或协作事项时使用。

  • 适用于 Codex、Claude、Cursor、Gemini CLI 等宿主环境,支持项目级自动化与安全检查。
  • 通过命令行安装,需确认 hooks.json 配置路径与事件匹配规则,避免误触发。
  • 涉及命令执行时,应验证用户权限与环境变量,防止敏感操作泄露。
  • create-hooks 属于AI 工具类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Hooks provide programmatic control over Claude's behavior without modifying core code, enabling project-specific automation, safety checks, and workflow customization.

<quick_start>

  1. Create hooks config file:

- Project: .claude/hooks.json - User: ~/.claude/hooks.json

  1. Choose hook event (when it fires)
  2. Choose hook type (command or prompt)
  3. Configure matcher (which tools trigger it)
  4. Test with claude --debug

.claude/hooks.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '\"\\(.tool_input.command) - \\(.tool_input.description // \\\"No description\\\")\"' >> ~/.claude/bash-log.txt"
          }
        ]
      }
    ]
  }
}

This hook:

  • Fires before (PreToolUse) every Bash tool use
  • Executes a command (not an LLM prompt)
  • Logs command + description to a file

</quick_start>

<hook_types>

EventWhen it firesCan block?
PreToolUseBefore tool executionYes
PostToolUseAfter tool executionNo
UserPromptSubmitUser submits a promptYes
StopClaude attempts to stopYes
SubagentStopSubagent attempts to stopYes
SessionStartSession beginsNo
SessionEndSession endsNo
PreCompactBefore context compactionYes
NotificationClaude needs inputNo

Blocking hooks can return "decision": "block" to prevent the action. See references/hook-types.md for detailed use cases. </hook_types>

<hook_anatomy> <hook_type name="command"> Type: Executes a shell command

Use when:

  • Simple validation (check file exists)
  • Logging (append to file)
  • External tools (formatters, linters)
  • Desktop notifications

Input: JSON via stdin Output: JSON via stdout (optional)

{
  "type": "command",
  "command": "/path/to/script.sh",
  "timeout": 30000
}

</hook_type>

<hook_type name="prompt"> Type: LLM evaluates a prompt

Use when:

  • Complex decision logic
  • Natural language validation
  • Context-aware checks
  • Reasoning required

Input: Prompt with $ARGUMENTS placeholder Output: JSON with decision and reason

{
  "type": "prompt",
  "prompt": "Evaluate if this command is safe: $ARGUMENTS\n\nReturn JSON: {\"decision\": \"approve\" or \"block\", \"reason\": \"explanation\"}"
}

</hook_type> </hook_anatomy>

{
  "matcher": "Bash",           // Exact match
  "matcher": "Write|Edit",     // Multiple tools (regex OR)
  "matcher": "mcp__.*",        // All MCP tools
  "matcher": "mcp__memory__.*" // Specific MCP server
}

No matcher: Hook fires for all tools

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [...]  // No matcher - fires on every user prompt
      }
    ]
  }
}

<input_output> Hooks receive JSON via stdin with session info, current directory, and event-specific data. Blocking hooks can return JSON to approve/block actions or modify inputs.

Example output (blocking hooks):

{
  "decision": "approve" | "block",
  "reason": "Why this decision was made"
}

See references/input-output-schemas.md for complete schemas for each hook type. </input_output>

<environment_variables> Available in hook commands:

VariableValue
$CLAUDE_PROJECT_DIRProject root directory
${CLAUDE_PLUGIN_ROOT}Plugin directory (plugin hooks only)
$ARGUMENTSHook input JSON (prompt hooks only)

Example:

{
  "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/validate.sh"
}

</environment_variables>

<common_patterns> Desktop notification when input needed:

{
  "hooks": {
    "Notification": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "osascript -e 'display notification \"Claude needs input\" with title \"Claude Code\"'"
          }
        ]
      }
    ]
  }
}

Block destructive git commands:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "prompt",
            "prompt": "Check if this command is destructive: $ARGUMENTS\n\nBlock if it contains: 'git push --force', 'rm -rf', 'git reset --hard'\n\nReturn: {\"decision\": \"approve\" or \"block\", \"reason\": \"explanation\"}"
          }
        ]
      }
    ]
  }
}

Auto-format code after edits:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": "prettier --write $CLAUDE_PROJECT_DIR",
            "timeout": 10000
          }
        ]
      }
    ]
  }
}

Add context at session start:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo '{\"hookSpecificOutput\": {\"hookEventName\": \"SessionStart\", \"additionalContext\": \"Current sprint: Sprint 23. Focus: User authentication\"}}'"
          }
        ]
      }
    ]
  }
}

</common_patterns>

This shows which hooks matched, command execution, and output. See references/troubleshooting.md for common issues and solutions.

<reference_guides> Hook types and events: references/hook-types.md

  • Complete list of hook events
  • When each event fires
  • Input/output schemas for each
  • Blocking vs non-blocking hooks

Command vs Prompt hooks: references/command-vs-prompt.md

  • Decision tree: which type to use
  • Command hook patterns and examples
  • Prompt hook patterns and examples
  • Performance considerations

Matchers and patterns: references/matchers.md

  • Regex patterns for tool matching
  • MCP tool matching patterns
  • Multiple tool matching
  • Debugging matcher issues

Input/Output schemas: references/input-output-schemas.md

  • Complete schema for each hook type
  • Field descriptions and types
  • Hook-specific output fields
  • Example JSON for each event

Working examples: references/examples.md

  • Desktop notifications
  • Command validation
  • Auto-formatting workflows
  • Logging and audit trails
  • Stop logic patterns
  • Session context injection

Troubleshooting: references/troubleshooting.md

  • Hooks not triggering
  • Command execution failures
  • Prompt hook issues
  • Permission problems
  • Timeout handling
  • Debug workflow </reference_guides>

<toolkit_hook_structure> Creating Installable Hooks for claude-code-toolkit

When creating hooks for distribution via the toolkit, use this structure:

hooks/
└── my-hook/
    ├── README.md                # Documentation
    ├── install.sh               # Standalone installer
    ├── settings-template.json   # Hook configuration to merge
    └── toggle.sh                # Optional: on/off toggle script

settings-template.json (hook configuration):

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "your-hook-command-here"
          }
        ]
      }
    ]
  }
}

install.sh (standalone installer):

#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLAUDE_DIR="$HOME/.claude"
TEMPLATE_FILE="$SCRIPT_DIR/settings-template.json"

# Check dependencies
command -v jq &>/dev/null || { echo "jq required"; exit 1; }

# Create settings if missing
mkdir -p "$CLAUDE_DIR"
[ -f "$CLAUDE_DIR/settings.json" ] || echo '{}' > "$CLAUDE_DIR/settings.json"

# Backup and merge
cp "$CLAUDE_DIR/settings.json" "$CLAUDE_DIR/settings.json.bak"
jq -s '.[0] * .[1]' "$CLAUDE_DIR/settings.json" "$TEMPLATE_FILE" > /tmp/merged.json
mv /tmp/merged.json "$CLAUDE_DIR/settings.json"

echo "Hook installed"

REQUIRED: Update root installers:

After creating a new hook, you MUST update both install-linux.sh and install-mac.sh:

  1. Add install function:
install_my_hook() {
    local INSTALL_SCRIPT="$SCRIPT_DIR/hooks/my-hook/install.sh"
    [ -f "$INSTALL_SCRIPT" ] || { echo "Hook not found"; return; }
    bash "$INSTALL_SCRIPT"
}
  1. Add to "install all" section:
echo -e "${BLUE}My Hook (description):${NC}"
install_my_hook
  1. Add to "select by folder" section:
echo
echo -e "${BLUE}━━━ My Hook ━━━${NC}"
echo -e "${DIM}Brief description of what the hook does${NC}"
echo -n "Install my-hook? (y/n): "
read -r choice
[[ "$choice" =~ ^[Yy]$ ]] && install_my_hook

Examples in toolkit:

  • hooks/concise-mode/ - UserPromptSubmit hook with toggle
  • hooks/damage-control/ - PreToolUse hooks with Python scripts </toolkit_hook_structure>

<security_checklist> Critical safety requirements:

  • Infinite loop prevention: Check stop_hook_active flag in Stop hooks to prevent recursive triggering
  • Timeout configuration: Set reasonable timeouts (default: 60s) to prevent hanging
  • Permission validation: Ensure hook scripts have executable permissions (chmod +x)
  • Path safety: Use absolute paths with $CLAUDE_PROJECT_DIR to avoid path injection
  • JSON validation: Validate hook config with jq before use to catch syntax errors
  • Selective blocking: Be conservative with blocking hooks to avoid workflow disruption

Testing protocol:

# Always test with debug flag first
claude --debug

# Validate JSON config
jq . .claude/hooks.json

</security_checklist>

<success_criteria> A working hook configuration has:

  • Valid JSON in .claude/hooks.json (validated with jq)
  • Appropriate hook event selected for the use case
  • Correct matcher pattern that matches target tools
  • Command or prompt that executes without errors
  • Proper output schema (decision/reason for blocking hooks)
  • Tested with --debug flag showing expected behavior
  • No infinite loops in Stop hooks (checks stop_hook_active flag)
  • Reasonable timeout set (especially for external commands)
  • Executable permissions on script files if using file paths </success_criteria>

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

30.26%
按下载量换算25

windsurf

21.84%
按下载量换算18

OpenCode

16.54%
按下载量换算14

Codex

11.58%
按下载量换算9

Antigravity

7.59%
按下载量换算6

Gemini CLI

3.59%
按下载量换算3

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/cfircoo/claude-code-toolkit --skill create-hooks;npx skills add cfircoo/claude-code-toolkit --skill "create-hooks" 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills