Token导航 LogoToken导航

Agent Skill · AI 工具

claude-hook-writer(Claude hook 写作)

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

claude-hook-writer 是AI 工具类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为执行命令;许可证为 MIT,第三方扫描已通过,按安装量在AI 工具类的 2,536 个 Skill 里排第 512。

总安装 3,888周安装 167GitHub Stars 126下载 1,363核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/secondsky/claude-skills --skill claude-hook-writer

这个 Skill 是做什么的

AI 工具类 Skill 用来扩展助手本身的能力,例如接模型、接检索、接外部服务。

提供专业钩子编写指导与安全最佳实践验证。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。适合防止钩子在无用户干预下执行危险操作。使用时需确保钩子不泄露凭证且超时设置合理。涉及发布时应封装为 PRPM 包并添加详细文档说明。

claude-hook-writer 属于AI 工具类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/claude-hook-writer

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/secondsky/claude-skills --skill claude-hook-wr…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

claude-hook-writer 怎么安装?

在终端执行 npx skills add https://github.com/secondsky/claude-skills --skill claude-hook-writer。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

claude-hook-writer 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

claude-hook-writer 需要什么权限?

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

claude-hook-writer 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

claude-hook-writer 用的人多吗?

公开数据是累计安装 3,888 次,近一周安装 167 次,下载 1,363 次,GitHub 126 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

claude-hook-writer 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理AI 工具类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要厂商级技术支持和 SLA 的生产系统。

AI 工具类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
executing-plans

执行计划 · Codex、Claude

1,515,336173,110只读MIT通过
verification-before-completion

完成前的验证 · Codex、Claude

1,319,472173,121权限未标注MIT通过
subagent-driven-development

子 Agent 驱动开发 · Codex、Claude

1,312,416173,138只读MIT通过
copy-editing

复制编辑 · Codex、Claude

1,209,57625,632只读MIT通过
paywall-upgrade-cro

付费专区升级 cro · Codex、Claude

1,030,17625,617只读MIT通过
claude-hook-writer

Claude hook 写作 · 本页

3,888126执行命令MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Claude Hook Writer

Status: Production Ready Version: 2.0.0 (Optimized with progressive disclosure) Last Updated: 2025-12-17


Overview

Expert guidance for writing secure, reliable, and performant Claude Code hooks. This skill validates design decisions, enforces best practices, and prevents common pitfalls.


When to Use This Skill

  • Designing a new Claude Code hook
  • Reviewing existing hook code
  • Debugging hook failures
  • Optimizing slow hooks
  • Securing hooks that handle sensitive data
  • Publishing hooks as PRPM packages

Core Principles

1. Security is Non-Negotiable

Hooks execute automatically with user permissions and can read, modify, or delete any file the user can access.

ALWAYS validate and sanitize all input. Hooks receive JSON via stdin—never trust it blindly.

For complete security patterns: Load references/security-requirements.md when implementing validation or securing hooks.

2. Reliability Over Features

A hook that works 99% of the time is a broken hook. Edge cases (Unicode filenames, spaces in paths, missing tools) will happen.

Test with edge cases before deploying.

For reliability patterns: Load references/reliability-performance.md when handling errors or edge cases.

3. Performance Matters

Hooks block operations. A 5-second hook means Claude waits 5 seconds before continuing.

Keep hooks fast. Run heavy operations in background.

For performance optimization: Load references/reliability-performance.md when optimizing hook speed.

4. Fail Gracefully

Missing dependencies, malformed input, and disk errors will occur.

Handle errors explicitly. Log failures. Return meaningful exit codes.


Hook Design Checklist

Before writing code, answer these questions:

What Event Does This Hook Target?

  • PreToolUse - Before tool execution (modify input, validate, block)
  • PostToolUse - After tool completes (format, log, cleanup)
  • UserPromptSubmit - Before user input processes (validate, enhance)
  • SessionStart - When Claude Code starts (setup, env check)
  • SessionEnd - When Claude Code exits (cleanup, persist state)
  • Notification - During alerts (desktop notifications, logging)
  • Stop / SubagentStop - When responses finish (cleanup, summary)
  • PreCompact - Before context compaction (save important context)

Common mistake: Using PostToolUse for validation (too late—tool already ran). Use PreToolUse to block operations.

Which Tools Should Trigger This Hook?

Be specific. matcher: "*" runs on every tool call.

Good matchers:

  • "Write" - Only file writes
  • "Edit|Write" - File modifications
  • "Bash" - Shell commands
  • "mcp__github__*" - All GitHub MCP tools

Bad matchers:

  • "*" - Everything (use only for logging/metrics)

What Input Does This Hook Need?

Different tools provide different input. Check what's available:

# PreToolUse / PostToolUse
{
  "input": {
    "file_path": "/path/to/file.ts",     // Read, Write, Edit
    "command": "npm test",                // Bash
    "old_string": "...",                  // Edit
    "new_string": "..."                   // Edit
  }
}

Validate fields exist before using them:

FILE=$(echo "$INPUT" | jq -r '.input.file_path // empty')
if [[ -z "$FILE" ]]; then
  echo "No file path provided" >&2
  exit 1
fi

Should This Be a Command Hook or Prompt Hook?

Command hooks (type: "command"):

  • Fast (milliseconds)
  • Deterministic
  • Good for: formatting, logging, file checks

Prompt hooks (type: "prompt"):

  • Slow (2-10 seconds)
  • Context-aware (uses LLM)
  • Good for: complex validation, security analysis, intent detection

Rule of thumb: Use command hooks unless you need LLM reasoning.

What Exit Code Communicates Success/Failure?

  • exit 0 - Success (continue operation)
  • exit 2 - Block operation (show error to Claude)
  • exit 1 or other - Non-blocking error (log but continue)

For PreToolUse hooks:

  • Exit 2 blocks the tool from running
  • Exit 0 allows it (optionally with modified input)

For PostToolUse hooks:

  • Exit codes don't block (tool already ran)
  • Use exit 0 for success, 1 for logging errors

Top 5 Pitfalls (Must Know)

Pitfall #1: Not Quoting Variables

Error: Hooks break on filenames with spaces or special characters

Why: Unquoted variables split on whitespace

Example:

# ❌ WRONG - breaks on "my file.txt"
cat $FILE
prettier --write $FILE
rm $FILE

# ✅ RIGHT - handles spaces and special chars
cat "$FILE"
prettier --write "$FILE"
rm "$FILE"

Why this matters: Files with spaces ("my file.txt"), Unicode ("文件.txt"), or special chars ("file (1).txt") are common.

For quoting best practices: Load references/security-requirements.md for comprehensive input handling patterns.


Pitfall #2: Trusting Input Without Validation

Error: Hook executes on malicious or malformed input

Why: Not validating JSON fields before using them

Example:

# ❌ DANGEROUS - no validation
FILE=$(jq -r '.input.file_path')
rm "$FILE"  # Could delete ../../../etc/passwd

# ✅ SAFE - validate first
FILE=$(jq -r '.input.file_path // empty')
[[ -n "$FILE" ]] || exit 1
[[ "$FILE" == "$CLAUDE_PROJECT_DIR"* ]] || exit 2
[[ "$FILE" != *".."* ]] || exit 2
rm "$FILE"

Why this matters: Prevents path traversal attacks, protects files outside project, prevents malformed input crashes.

For complete security patterns: Load references/security-requirements.md.


Pitfall #3: Blocking Operations Too Long

Error: Hook takes 30+ seconds, blocking Claude

Why: Running expensive operations (tests, builds) synchronously in hook

Example:

# ❌ BLOCKS Claude for 30 seconds
npm test
npm run build

# ✅ RUN IN BACKGROUND - returns immediately
(npm test > /tmp/test-results.log 2>&1 &)
(npm run build > /tmp/build.log 2>&1 &)
exit 0

Why this matters: Slow hooks create bad user experience. Target < 100ms for PreToolUse, < 500ms for PostToolUse.

For performance optimization: Load references/reliability-performance.md.


Pitfall #4: Wrong Exit Code for Blocking

Error: PreToolUse hook doesn't actually block the operation

Why: Using exit 1 instead of exit 2

Example:

# ❌ WRONG - logs error but doesn't block
if [[ $FILE == ".env" ]]; then
  echo "Don't edit .env" >&2
  exit 1  # Tool still runs!
fi

# ✅ RIGHT - actually blocks
if [[ $FILE == ".env" ]]; then
  echo "Blocked: .env is protected" >&2
  exit 2  # Tool is blocked
fi

Why this matters: Exit 1 only logs errors. Exit 2 is required to block in PreToolUse hooks.

For exit code patterns: Load references/hook-templates.md for complete hook response patterns.


Pitfall #5: Assuming Tools Exist

Error: Hook crashes when dependency is missing

Why: Not checking if tool is installed before using

Example:

# ❌ BREAKS if prettier not installed
prettier --write "$FILE"

# ✅ SAFE - check first
if command -v prettier &>/dev/null; then
  prettier --write "$FILE"
else
  echo "prettier not installed, skipping" >&2
  exit 0  # Success exit, just skip
fi

Why this matters: Users may not have all tools installed. Hooks should degrade gracefully.

For reliability patterns: Load references/reliability-performance.md.


Critical Rules

Always Do

✅ Validate all JSON input before using (jq -r '... // empty') ✅ Quote all variables containing paths or user input ✅ Use absolute paths for scripts (${CLAUDE_PLUGIN_ROOT}/...) ✅ Block sensitive files (.env, *.key, credentials) ✅ Check if required tools exist (command -v toolname) ✅ Set reasonable timeouts (< 5s for PreToolUse) ✅ Run heavy operations in background ✅ Test with edge cases (spaces, Unicode, special chars) ✅ Use exit 2 to block in PreToolUse hooks ✅ Log errors to stderr or file, not stdout

Never Do

❌ Trust JSON input without validation ❌ Use unquoted variables ($FILE instead of "$FILE") ❌ Use relative paths for scripts ❌ Skip path sanitization (check for .., validate in project) ❌ Assume tools are installed ❌ Block for > 1 second in PreToolUse hooks ❌ Use exit 1 when you mean to block (use exit 2) ❌ Log sensitive data to stdout or files ❌ Use matcher: "*" unless truly necessary


When to Load References

Load reference files when working on specific hook aspects:

Security Requirements (references/security-requirements.md)

Load when:

  • Implementing input validation and sanitization
  • Securing hooks that handle sensitive data
  • Blocking sensitive files (.env, keys, credentials)
  • Preventing path traversal attacks
  • Understanding security vulnerabilities and best practices
  • Testing security with malicious input

Reliability & Performance (references/reliability-performance.md)

Load when:

  • Handling missing dependencies or tools
  • Setting timeouts and handling slow operations
  • Optimizing hook performance (< 100ms target)
  • Running heavy operations in background
  • Caching expensive results
  • Testing with edge cases (Unicode, spaces, deep paths)
  • Deduplicating expensive operations

Code Templates (references/code-templates.md)

Load when:

  • Starting a new hook and need working examples
  • Implementing format-on-save functionality
  • Blocking sensitive files from modification
  • Logging commands or operations
  • Using prompt-based security analysis
  • Customizing templates for specific use cases

Testing & Debugging (references/testing-debugging.md)

Load when:

  • Writing test cases for hooks
  • Debugging hook failures or unexpected behavior
  • Testing with edge cases (malformed JSON, missing fields)
  • Checking hook execution in transcript (Ctrl-R)
  • Profiling hook performance
  • Creating automated test suites

Publishing Guide (references/publishing-guide.md)

Load when:

  • Publishing hooks to PRPM registry
  • Creating package manifest (prpm.json)
  • Configuring hook.json with advanced options
  • Using continue, stopReason, suppressOutput, systemMessage
  • Writing README.md for users
  • Understanding versioning and publishing commands

Quick Reference (references/quick-reference.md)

Load when:

  • Need quick syntax lookup (exit codes, jq patterns)
  • Looking up environment variables
  • Finding common bash patterns (file validation, background execution)
  • Checking hook events and matchers
  • Need performance tips summary
  • Looking up JSON input structure

Final Checklist

Before publishing a hook:

  • Validates all stdin input with jq
  • Quotes all variables
  • Uses absolute paths for scripts
  • Blocks sensitive files (.env, *.key, etc.)
  • Handles missing tools gracefully
  • Sets reasonable timeout (< 5s for PreToolUse)
  • Logs errors to stderr or file, not stdout
  • Tests with edge cases (spaces, Unicode, malformed JSON)
  • Tests in real Claude Code session
  • Documents dependencies in README
  • Uses semantic versioning
  • Clear description and tags

Using Bundled Resources

This skill includes 6 reference files for on-demand loading:

Security & Reliability (2 files):

  • security-requirements.md - Input validation, path sanitization, blocking sensitive files
  • reliability-performance.md - Error handling, timeouts, performance optimization

Implementation (2 files):

  • code-templates.md - Working hook examples (format-on-save, block-sensitive, logger, etc.)
  • quick-reference.md - Fast syntax lookup (exit codes, jq patterns, environment vars)

Testing & Publishing (2 files):

  • testing-debugging.md - Test patterns, edge cases, debugging techniques
  • publishing-guide.md - PRPM packaging, advanced configuration, README template

Load references on-demand when specific knowledge is needed. See "When to Load References" section for triggers.


Resources


Last verified: 2025-12-17 | Version: 2.0.0

平台分布

Cursor

41.2%
按下载量换算562

Codex

27.85%
按下载量换算380

windsurf

14.63%
按下载量换算199

Claude Code

7.25%
按下载量换算99

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

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

安装前确认

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

继续浏览同类 Skills