From claude-plugins-validation
Add a new hook entry to hooks/hooks.json in an existing plugin (idempotent — skips duplicate entries; cross-platform-aware). Use when adding a new event-handler that must run identically on Linux/macOS/Windows. Used dynamically via the-skills-menu (TRDD-478d9687).
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-plugins-validation:add-hookWhen to use
When the cpv-main-menu user picks Create → Add hook to existing plugin, or any flow needs to append a new event-handler entry to hooks/hooks.json with cross-platform-safe command
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Adds a new hook entry to a plugin's `hooks/hooks.json`. The scaffold is idempotent — re-running with the same event+command is a no-op. The new hook command MUST be cross-platform: prefer Python or Node.js delegation. Bash-only constructs (`set -euo pipefail`, `[[ ]]`, `$(<file)`, process substitution, brace expansion) will trigger `validate_hook` MAJOR findings. Loaded by `cpv-main-menu-agent`...
Adds a new hook entry to a plugin's hooks/hooks.json. The scaffold is idempotent — re-running with the same event+command is a no-op. The new hook command MUST be cross-platform: prefer Python or Node.js delegation. Bash-only constructs (set -euo pipefail, [[ ]], $(<file), process substitution, brace expansion) will trigger validate_hook MAJOR findings. Loaded by cpv-main-menu-agent via the Create → Add hook menu branch.
uv on PATH.claude-plugin/plugin.jsonadd_component.py writes the command verbatim — it does NOT inspect or reject bash-only constructs at write time — so a bash-only command lands in hooks/hooks.json and is caught only later by validate_hook/validate_plugin --strict (step 5) as a MAJOR. Use Python/Node delegation up front to pass that re-validation.add_component.py --type hook invocation.hooks/hooks.json if missing or merges into the existing file.plugin-validation-skill to confirm cross-platform compliance.${CLAUDE_PLUGIN_ROOT} (lost on every plugin update). Use ${CLAUDE_PLUGIN_DATA} instead.Copy this checklist and track your progress:
add_component.py --type hook executedhooks/hooks.json updated or createdvalidate_plugin --strict re-runhooks/hooks.json keyed by event name.| Error | Resolution |
|---|---|
| MAJOR: bash-only constructs | Convert command to Python/Node delegation |
| MINOR: POSIX-only tool (jq, sed, awk) | Replace with Python equivalent (json, re.sub, list comprehension) |
| Hook never fires | Check event name spelling; restart Claude Code (plugin hooks pick up on plugin reload) |
| State lost between sessions | Move runtime state writes from ${CLAUDE_PLUGIN_ROOT} to ${CLAUDE_PLUGIN_DATA} |
# Cross-platform Python delegation (recommended)
uv run "${CLAUDE_PLUGIN_ROOT}/scripts/add_component.py" /path/to/my-plugin \
--type hook --event PostToolUse \
--command 'python3 "${CLAUDE_PLUGIN_ROOT}/scripts/post_tool.py"'
# Cross-platform Node delegation
uv run "${CLAUDE_PLUGIN_ROOT}/scripts/add_component.py" /path/to/my-plugin \
--type hook --event SessionStart \
--command 'node "${CLAUDE_PLUGIN_ROOT}/scripts/init.js"'
PreToolUse, PostToolUse, PostToolUseFailure, PostToolBatch, PermissionRequest, PermissionDenied, UserPromptSubmit, UserPromptExpansion, Notification, Stop, StopFailure, SubagentStop, SubagentStart, SessionStart, SessionEnd, PreCompact, PostCompact, TeammateIdle, TaskCompleted, TaskCreated, ConfigChange, WorktreeCreate, WorktreeRemove, InstructionsLoaded, Elicitation, ElicitationResult, CwdChanged, FileChanged.
${CLAUDE_PLUGIN_DATA}/log.jsonl).add-component-to-plugin skill — multi-purpose scaffold wrapperplugin-validation-skill — validate hooks.json cross-platform compliancecanonical-pipeline skill — pipeline rules around hook designfix-validation skill — fix-up recipes for hook errorsnpx claudepluginhub emasoft/emasoft-plugins --plugin claude-plugins-validationBlocks Edit/Write/Bash actions until Claude investigates importers, data schemas, and user instructions. Improves output quality by forcing concrete facts before edits.