kanevry/session-orchestrator/hook-development
Claude Code and agent skill by kanevry/session-orchestrator
- community
Checking that the SKILL.md file is still in the repository.
Use when creating, modifying, or debugging Claude Code hooks — PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification. Covers the plugin `hooks/hooks.json` wrapper format vs. the user `settings.json` direct format, matchers, security patterns, `$CLAUDE_PLUGIN_ROOT` portability, lifecycle limitations, and debugging. Trigger on "add a hook", "validate tool use", "block dangerous commands", "enforce completion", "hook-based automation".
Install
npx vskill@latest install kanevry/session-orchestrator/hook-developmentSKILL.md
The same SKILL.md was published earlier as kanevry/session-orchestrator/hook-development.
Hook Development for Claude Code Plugins
Use the official Claude Code hooks reference as the source of truth for current events and schemas. This skill keeps only the conventions needed to author this plugin's hooks.
Hook types used in this plugin
Claude Code also documents http, mcp_tool, and experimental agent handlers. Use those only after checking their current fields and event support in the official reference.
Prompt-based (LLM-driven, for complex reasoning)
Prompt hooks are supported only on events documented for that handler type. $ARGUMENTS contains the hook input JSON.
Use for: context-aware decisions, flexible evaluation, natural-language reasoning.
Command (deterministic, for fast checks)
Use for: fast deterministic validations, file-system ops, external tools, performance-critical paths.
Our convention: hook logic lives in .mjs files — see hooks/pre-bash-destructive-guard.mjs and hooks/enforce-scope.mjs. The manifest invokes them through the repository's runtime wrapper.
Configuration formats
Keep the file location and its outer document shape explicit when copying an example.
Plugin hooks/hooks.json — wrapper format
hookswrapper is requireddescriptionis optional
User or project .claude/settings.json — settings format
- The top-level
hookskey is required in settings. - Plugin
hooks/hooks.jsonmay additionally carry a top-leveldescription.
The distinction is registration and scope: settings hooks belong to a user, project, or managed policy; plugin hooks run while the plugin is enabled. The nested event → matcher group → handler shape is the same.
Hook events
| Event | When | Use for | |
|---|---|---|---|
PreToolUse | Before tool runs | Validate, modify, block | |
PostToolUse | After tool completes | React to result, log | |
UserPromptSubmit | User submits prompt | Add context, validate | |
Stop | Main agent stopping | Completeness check | |
SubagentStop | Subagent stopping | Task validation | |
SessionStart | Session begins or resumes | Context load | |
SessionEnd | Session ends | Cleanup, logging | |
PreCompact | Before compaction | Preserve critical state | |
Notification | User notified | Logging, reactions |
PreToolUse output schema
Stop / SubagentStop output
Omit decision to allow stopping. approve is not a valid Stop decision. For non-error feedback that keeps the conversation running, use hookSpecificOutput.additionalContext with hookEventName set to Stop or SubagentStop.
SessionStart: persist env vars
$CLAUDE_ENV_FILE is unique to SessionStart hooks.
Input schema
All hooks receive JSON on stdin:
Event-specific extras:
PreToolUse:tool_name,tool_input,tool_use_idPostToolUse:tool_name,tool_input,tool_response,tool_use_idUserPromptSubmit:promptStop:stop_hook_active,last_assistant_message;SubagentStopalso carries agent identity and transcript fields
Event fields vary and evolve. Parse only fields needed by the hook and consult the official event section before depending on one. The UserPromptSubmit field name above was last checked against the official reference on 2026-09-15 (branch codex/ecc-systematic-review); this plugin registers no UserPromptSubmit handler, so no code here exercises either spelling — verify before depending on it. Prompt and agent hooks receive the complete input through $ARGUMENTS.
Environment variables
| Var | Scope | Purpose | |
|---|---|---|---|
$CLAUDE_PROJECT_DIR | All | Project root | |
$CLAUDE_PLUGIN_ROOT | Plugin hooks | Plugin directory — use this, never hardcode paths | |
$CLAUDE_ENV_FILE | SessionStart only | Persist env vars | |
$CLAUDE_CODE_REMOTE | All (conditional) | Set if running remote |
Portability rule
Matchers
Matchers are case-sensitive.
Security best practices
Validate inputs (command hooks)
In Node/.mjs hooks (our convention), same principle — parse stdin JSON, validate structure before trusting.
Path safety
Our enforce-scope.mjs implements this for wave-scope boundaries.
Quote variables
Timeouts
Current defaults are 600 seconds for command/HTTP/MCP-tool hooks, 30 seconds for prompt hooks, and 60 seconds for agent hooks, with shorter defaults for some events. SessionEnd also has a shared time budget. Set a short explicit timeout appropriate to the hook; a timed-out PreToolUse command hook does not block the tool call.
Parallel execution
All matching hooks run in parallel — they don't see each other's output, ordering is non-deterministic. Design for independence.
Registration and reload behavior
Installed capability and active registration are different. A plugin can ship hook files without those hooks running when the plugin is disabled. Settings hooks merge with plugin and managed hooks; /hooks shows the active sources.
Direct edits to hooks in settings files are normally picked up by Claude Code's file watcher. Plugin registration changes may require disabling/re-enabling the plugin or starting a fresh session. A command hook's script is launched when the event fires, so editing the script itself can affect the next invocation without re-registering the manifest.
To test a registration change, inspect /hooks, trigger the matching event, and use claude --debug when the source, matcher, output, or timeout remains unclear.
Debugging
Debug mode
Surfaces hook registration, execution logs, stdin/stdout JSON, timing.
Test a command hook directly
Validate JSON output
Invalid structured output is normally reported as a non-blocking hook error and the action proceeds, so always verify the output and the resulting decision.
Conditional activation
Pattern: check for a flag file or config before running:
Or config-based (matches our Session-Config pattern):
Our in-house examples (read these, not the upstream examples/)
hooks/pre-bash-destructive-guard.mjs— policy-driven command blocker backed by.orchestrator/policy/blocked-commands.jsonhooks/enforce-scope.mjs— scope enforcement usingwave-scope.jsonin the platform's state directoryhooks/on-session-start.mjs— banner + session inithooks/post-edit-validate.mjs— validates edits after the facthooks/on-stop.mjs— session-event capture + metrics
Do / Don't
Do:
- Prompt-based hooks for complex logic, command hooks for fast deterministic checks
- Always
${CLAUDE_PLUGIN_ROOT}for paths - Validate every input field before trusting it
- Quote all shell variables
- Set explicit timeouts for known-slow work
- Return only schema-valid structured JSON when the event needs a decision or context; emit nothing on a silent allow
Don't:
- Hardcoded paths
- Trust
tool_inputwithout validation - Long-running hooks (blocks the tool call)
- Rely on execution order (hooks run in parallel)
- Mutate global state
- Log sensitive data to stdout/stderr
Runtime Profile Control (#211)
All hook handlers support runtime opt-out via two environment variables without any settings-file changes. This is implemented in hooks/_lib/profile-gate.mjs.
Env vars
| Variable | Values | Behaviour | |||||
|---|---|---|---|---|---|---|---|
SO_HOOK_PROFILE | strict \ | standard \ | relaxed \ | minimal \ | off (full = strict) | Preset bundle (default standard). | |
SO_DISABLED_HOOKS | Comma-separated names | Disable individual hooks; overrides profile. |
The same two settings can live per host in owner.yaml (hooks.profile, hooks.disabled); env wins, and owner.yaml cannot disable a safety hook (#1881).
Profile bundles
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/hook-development/SKILL.md
Popularity
- Repository stars
- 52
- Repository forks
- 7
- Repository npm downloads, 7 days
- 1,302
- 7-day trend score
- 36
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 5 Oct 2026, a month ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kanevry/session-orchestrator/hook-development)