帮助开发者为 Claude Code 插件创建事件驱动 Hook,并校验工具调用与自动化流程。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "hook-development" 技能: 1. 下载 https://raw.githubusercontent.com/anthropics/claude-plugins-official/main/plugins/plugin-dev/skills/hook-development/SKILL.md 2. 保存为 ~/.claude/skills/hook-development/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为 Claude Code 插件创建一个 PreToolUse prompt hook,匹配 Write|Edit,在写文件前检查是否涉及系统路径、凭证泄露、路径穿越或敏感内容,并只返回 approve 或 deny。请给出适用于插件 hooks/hooks.json 的配置。
一段插件 hooks.json 配置,包含 PreToolUse、matcher 和 prompt 类型 hook。
请生成一个 command hook 示例,在 PreToolUse 时调用 bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh,并设置超时 60 秒。顺便说明这是插件 hooks.json 还是 .claude/settings.json 的格式。一个使用 ${CLAUDE_PLUGIN_ROOT} 的 command hook 配置示例,并指出对应的配置格式。
我想在 Claude Code 会话开始时自动加载项目上下文。请给出一个 SessionStart hook 的配置示例,并说明插件 hooks.json 的外层包装格式。
一个 SessionStart hook 示例,以及带有 description 和 hooks 外层字段的插件配置结构说明。
开发者在为 Claude Code 插件添加治理能力时,可用此技能设计 PreToolUse 或 Stop 等 Hook,对工具调用进行校验、拦截或补充规则。
当需要在 SessionStart、PostToolUse、SessionEnd 等事件触发自动动作时,此技能可帮助配置事件驱动 Hook,把校验、上下文加载和外部集成串起来。
如果团队希望用自然语言规则做上下文感知判断,而不是完全依赖 Bash 脚本,可使用此技能实现 prompt-based hooks。
文档介绍了 Claude Code 插件中 Hook 的开发方式,说明 Hook 是响应事件执行的自动化脚本,可用于校验工具调用、执行策略、加载上下文和集成外部工具。内容重点对比了 prompt-based hook 与 command hook 的适用场景,并解释插件 hooks/hooks.json 与 .claude/settings.json 两种配置格式,以及 PreToolUse、Stop、SessionStart 等事件的基本结构。
Hooks are event-driven automation scripts that execute in response to Claude Code events. Use hooks to validate operations, enforce policies, add context, and integrate external tools into workflows.
Key capabilities:
Use LLM-driven decision making for context-aware validation:
{
"type": "prompt",
"prompt": "Evaluate if this tool use is appropriate: $TOOL_INPUT",
"timeout": 30
}
Supported events: Stop, SubagentStop, UserPromptSubmit, PreToolUse
Benefits:
Execute bash commands for deterministic checks:
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/scripts/validate.sh",
"timeout": 60
}
Use for:
For plugin hooks in hooks/hooks.json, use wrapper format:
{
"description": "Brief explanation of hooks (optional)",
"hooks": {
"PreToolUse": [...],
"Stop": [...],
"SessionStart": [...]
}
}
Key points:
description field is optionalhooks field is required wrapper containing actual hook eventsExample:
{
"description": "Validation hooks for code quality",
"hooks": {
"PreToolUse": [
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/validate.sh"
}
]
}
]
}
}
For user settings in .claude/settings.json, use direct format:
{
"PreToolUse": [...],
"Stop": [...],
"SessionStart": [...]
}
Key points:
Important: The examples below show the hook event structure that goes inside either format. For plugin hooks.json, wrap these in {"hooks": {...}}.
Execute before any tool runs. Use to approve, deny, or modify tool calls.
Example (prompt-based):
{
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "prompt",
"prompt": "Validate file write safety. Check: system paths, credentials, path traversal, sensitive content. Return 'approve' or 'deny'."
}
]
}
]
}
Output for PreToolUse:
{
"hookSpecificOutput": {
"permissionDecision": "allow|deny|ask",
"updatedInput": {"field": "modified_value"}
},
"systemMessage": "Explanation for Claude"
}
Execute after tool completes. Use to react to results, provide feedback, or log.
Example:
{
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "prompt",
"prompt": "Analyze edit result for potential issues: syntax errors, security vulnerabilities, breaking changes. Provide feedback."
}
]
}
]
}
Output behavior:
Execute when main agent considers stopping. Use to validate completeness.
Example:
{
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "prompt",
…
它用于为 Claude Code 插件创建和实现 Hook,重点覆盖事件驱动自动化、工具调用校验,以及高级 prompt-based hooks API 的使用。
文档显示 prompt hook 适合用大模型做上下文感知判断,逻辑更灵活;command hook 通过 Bash 命令执行,更适合确定性检查、文件系统操作和外部工具集成。
不一样。插件的 hooks/hooks.json 需要使用包含 hooks 字段的包装格式,description 可选;.claude/settings.json 则是把各事件直接放在顶层,没有外层包装。
帮助开发者把本地 MCP 服务打包成自带运行时的 .mcpb 安装包。
浏览 Anthropic 官方精选的 Claude Code 插件目录并快速发现可用工具
帮助开发者梳理需求并规划合适的 MCP 服务器构建方案
生成可视化交互式单文件 HTML playground,便于探索配置并复制提示词
帮助开发者为 Claude Code 设计、编写和组织斜杠命令。
This skill should be used when the user asks about "plugin settings", "store plugin configuration", "user-configurable plugin", ".local.md files", "plugin state files", "read YAML frontmatter", "per-project plugin settings", or wants to make plugin behavior configurable. Documents the .claude/plugin-name.local.md pattern for storing plugin-specific configuration with YAML frontmatter and markdown content.
汇总 Claude Code 优质技能与插件资源,帮助开发者快速发现并扩展 AI 编码能力
帮助你高效创建、修改、测试与发布 Claude Code 插件的全流程技能
提供 Claude Code CLI、插件、MCP、配置与技能的官方使用指导
汇总 Claude Code 插件资源,帮助你快速扩展命令、代理、钩子与 MCP 能力
一键配置 Claude Code 的技能、钩子、代理与记忆系统,加速开发环境就绪。
帮助你编写 Hook 配置文件,以执行策略校验并自动化代理生命周期事件。