name: diagnosing-hooks
Goal: reduce any hook problem to a single concrete fix.
Note on trust: plugin hooks execute regardless of the marketplace they came from — third-party plugin hooks run just like built-in ones. Any "diagnostic-only until trusted" wording you may see for marketplace hooks is stale; a plugin's detail view marks each hook as runnable, and that is now true for all hooks.
hooks key in ~/.zcode/cli/config.json (or the workspace <repo>/.zcode/config.json / zcode.json), shaped as { enabled?, timeoutMs?, maxOutputBytes?, events: { <Event>: [ { matcher?, hooks: [...] } ] } }. These are disabled by default — configuration-file hooks must set hooks.enabled: true to run.hooks/hooks.json (or its manifest hooks field). Plugin matchers are appended after configuration matchers. When any plugin contributes a hook, the hook runner is enabled automatically.enabled: true they run unconditionally.{ "hooks": { "<Event>": [ { "matcher": "...", "hooks": [ { "type": "command"|"process", ... } ] } ] } }
(A plugin file uses the outer hooks wrapper; the configuration file uses hooks.events.<Event>. The inner array is the same.)
SessionStart, UserPromptSubmit, PreToolUse, PermissionRequest, PostToolUse, PostToolUseFailure, Stop. Any other name is an unsupported event. (Events such as Notification, SubagentStop, and PreCompact are not supported.)SessionStart → one of startup, resume, clear, compactPreToolUse, PostToolUse, PermissionRequest, PostToolUseFailure) → the tool name (Bash, Read, Write, Edit, Agent, …), with aliases Task ↔ Agent and Write/Edit ← ApplyPatchUserPromptSubmit → the prompt text; Stop → the response previewtype: "command": command (a shell string); optional shell, timeout (in seconds), timeoutMs (in milliseconds, takes precedence), and statusMessage. Note that async currently has no runtime effect.type: "process": command (an executable) plus args[] (an argument vector run without a shell, the most portable choice), timeoutMs (in milliseconds), and statusMessage.timeoutMs → timeout × 1000 → the configuration's timeoutMs → a default of 60000 ms.${CLAUDE_PROJECT_DIR} / ${ZCODE_PROJECT_DIR}, ${CLAUDE_SESSION_ID}; and, for plugin hooks only, ${CLAUDE_PLUGIN_ROOT} / ${ZCODE_PLUGIN_ROOT} and the plugin data directory. Note that a skill-directory variable is not valid in a hook and raises an error.0 passes, 2 blocks (a deny for PreToolUse/PermissionRequest), and any other non-zero raises an error. additionalContext is injected into the conversation; PreToolUse may return a permission decision of allow/ask/deny; Stop may request continuation (up to three times).hooks/hooks.json (or the manifest hooks field) for a plugin, and the hooks block of ~/.zcode/cli/config.json / the workspace config for configuration hooks.hooks.events.* but nothing fires. They are disabled by default and are enabled automatically only when a plugin hook is present. → Set "hooks": { "enabled": true, ... } in the configuration."bash" will not match Bash, and an invalid expression never matches. → Use the exact tool name or a correct expression (for example "Edit|Write"), or omit the matcher to match all. Remember the aliases Task → Agent and Write/Edit → ApplyPatch.permission denied, with a failed outcome. The script was installed without the executable bit. → Run chmod +x on it, or invoke it through an interpreter, e.g. {"type":"command","command":"bash \"${CLAUDE_PLUGIN_ROOT}/hooks/x.sh\""}, so the executable bit is irrelevant.${...} or an empty path. Only recognized variables are expanded; a skill-directory variable raises an error inside a hook, and ${CLAUDE_PLUGIN_ROOT} is available only for plugin hooks. → Use only supported variables, and ${CLAUDE_PLUGIN_ROOT} for plugin-relative paths.command's timeout is in seconds; process's timeoutMs is in milliseconds. timeout: 500 means 500 seconds; timeoutMs: 5 means 5 milliseconds. → Use "timeout": <seconds> for a command hook and "timeoutMs": <milliseconds> for a process hook.process hook accepts only command, args, and timeoutMs; a command hook accepts command, shell, timeout, and timeoutMs. → Match the fields to the type.async runs in the background — you set async: true but the session still waits. The async field has no runtime effect and hooks always run inline. → Do not rely on async; for background work, have the script daemonize itself.command hook runs through a shell, so POSIX syntax fails on Windows. → Prefer a process hook (an argument vector, no shell), or ship a polyglot wrapper script and keep hook scripts extensionless.deny decision. → Inspect the block's reason in the log; fix the script's exit code — return 0 to pass and reserve 2 for a deliberate block.hooks.enabled: true is set in the configuration or at least one plugin contributes a hook; otherwise no runner exists and every hook is skipped.hooks block directly.bash/node.0 plus valid JSON is healthy, 2 is a deliberate block, any other non-zero is a failure.