Skip to content
Source on GitHub (opens in a new tab)

Both hosts adapt hooks.json commands and http handlers to zelk.WithHooks; core remains an in-process Go API (core/hook). Files load from:

  • $XDG_CONFIG_HOME/zelk/hooks.json, falling back to ~/.config/zelk/hooks.json.
  • .zelk/hooks.json at the selected workspace root.

User hooks run automatically. Project hooks require trust of the exact file bytes, identified by SHA-256 together with the absolute workspace path. Trust records live in hook-trust/ under the host state directory. Moving a workspace or changing any byte requires trust again. A missing file means no hooks; a malformed, unreadable, oversized or unsupported file refuses startup, including an untrusted project file. A broken safety hook must not silently disappear. Neither host reads .claude/settings.json.

The TUI opens a scrollable startup review showing every project command (with control characters escaped) and the file digest. Press y to trust and run, or n / escape to continue without project hooks. Enter does not grant trust. No project callback, including SessionStart, runs before acceptance and a successful trust write. Declines last for the launch. Rebuilding an agent after changing MCP configuration does not open another terminal program: newly changed, untrusted project hooks are skipped until review on the next launch.

The CLI, exec, acp and job worker never prompt for project trust. They skip untrusted project hooks and warn once per resolved host configuration:

zelk hooks list
zelk hooks trust
# With a custom state directory, use it for both review/trust and execution:
zelk hooks -state /private/zelk-state list
zelk hooks -state /private/zelk-state trust
zelk exec -state /private/zelk-state 'run the tests'

trust explicitly authorizes the currently displayed commands without another prompt. Review scripts before invoking it. Trust covers the hook definitions, not the bytes of scripts they execute; changing a referenced script does not change hooks.json’s digest. Trusted scripts are the user’s own code.

Commands run outside the tool command sandbox, with the user’s full host environment. They can access the host’s files and credentials. Both ZELK_PROJECT_DIR and CLAUDE_PROJECT_DIR name the workspace. The working directory is the workspace, and the interpreter is /bin/sh -c; scripts requiring Bash must invoke it explicitly. Windows has no /bin/sh: there the interpreter is bash.exe -c, the Git for Windows bash the Bash tool uses (-bash names another). Without Git for Windows, a hook that names no shell runs in PowerShell, and one that asks for Bash fails. Under MXC, PowerShell is the default for session hooks, and zelk rejects trusted hooks that request Bash at startup. See the MXC enforcement contract. Paths in the payload and in ZELK_PROJECT_DIR are written the way the workspace’s are, with the drive and forward slashes (C:/work). Hooks cannot interact with a terminal through stdin, which contains one JSON object followed by a newline.

A command hook may name its shell with "shell": "bash" or "shell": "powershell", as in Claude Code; any other value is a configuration error. A PowerShell hook runs through the PowerShell that runs the PowerShell tool (7 or Windows PowerShell 5.1), without profiles, with -ExecutionPolicy Bypass for that process only. Its command runs in the global scope and reads the event from standard input, with [Console]::In.ReadToEnd() or $input. A failing last statement exits 1; exit 2 blocks as in Bash. Its error, warning and information streams reach the model as text. Where there is no PowerShell, a hook that asks for it fails as a command that can’t run.

The nesting and command protocol follow the Claude Code hooks reference, with the limitations below. For example:

{
"hooks": {
"PreToolUse": [{
"matcher": "Bash|Edit",
"hooks": [{"type": "command", "command": "./scripts/check-action.sh", "timeout": 10}]
}],
"UserPromptSubmit": [{
"hooks": [{"type": "command", "command": "./scripts/check-prompt.sh"}]
}]
}
}

A handler is type: "command" or type: "http" (below). Unknown events, fields and handler types (prompt, agent, mcp_tool) are load errors naming the file/event. Config files and each of stdout and stderr are bounded to 1 MiB. timeout is a positive number of seconds, including fractions, at most 86400; omission uses 60 seconds. The command runner owns its deadline; the library callback deadline includes five seconds for cleanup. On timeout or cancellation, the runner kills the whole process group and joins the shell and capture workers. Remaining group members are also killed after normal exit; background daemons are not supported.

onFailure is "continue" (the default) or "block", as in Claude Code. A failure is a timeout or cancellation, a command that can’t start, an exit code other than 0 or 2, output over the bound, or JSON that is malformed or can’t be honored. By default a failure is a non-blocking error: the action goes ahead (a tool call still passes through the normal permission flow), and the error becomes context where the event takes context, or a recorded reason on other gates. With "block" a failure does what exit 2 does: PreToolUse and PermissionRequest deny, UserPromptSubmit, PreCompact and PreModelSwitch block. It has no effect on Stop and SubagentStop, where a continuation can’t repair a hook that won’t run. A policy hook that must not let an action through when it stalls or breaks sets "onFailure": "block".

Omitted, empty and "*" matchers select everything. Tool events match tool names; SessionStart matches its source; SubagentStart and SubagentStop match the agent type. Exact names can be separated by | or ,, with surrounding spaces. The regular-expression subset representable by hook.Match is supported: literal text, .*, and optional leading ^ / trailing $. Regex matches are unanchored unless explicitly anchored, so mcp__.* selects MCP tool names. Other regex operators are rejected, including groups, character classes and escapes. These are not JavaScript regexes. A nontrivial matcher on any other event is rejected because its public core constructor cannot filter it.

User hooks precede project hooks. Events are sorted for stable registration; groups and commands retain file order. Every hook uses hook.WithName with a hash of its file path, event, group/command position, matcher, command and timeout. Changing one of those invalidates the old identity; resuming an unfinished invocation without its original definition fails closed. Gate results are durable and replay does not rerun completed invocations. Core combines decisions by restrictiveness and concatenates context in registration order. Multiple input rewrites fail closed. Config hooks apply to children via hook.WithChildren. Config has no async flag; observe-only events already use core’s bounded, best-effort observation path and cannot change decisions.

Every input includes session_id, transcript_path, cwd, hook_event_name, agent_type and zelk’s stable invocation_id. Children also have agent_id, equal to their session ID. transcript_path points to the native framed .zlog file under sessions/logs/, not Claude JSONL. Ephemeral hosts use an empty string. The core callback does not expose the live permission mode, a stop-hook continuation counter, parent transcript path, session title or model-switch costs; these fields are omitted rather than fabricated.

Event Additional input fields Supported output
SessionStart source (startup, resume, compact) context
UserPromptSubmit prompt block, context
PreToolUse tool_name, tool_input, tool_use_id allow/deny/ask, rewritten input, context
PermissionRequest tool fields, reason, permission_suggestions allow/deny
PermissionDenied tool fields, reason context becomes a model note
PostToolUse, PostToolUseFailure tool fields, tool_response (text); failure also error context; top-level block/reason becomes feedback
PostToolBatch common fields context
Stop, SubagentStop last_assistant_message, stop_reason block
SubagentStart prompt context
PreCompact trigger block (proactive compaction only)
PreModelSwitch model, provider block
PostModelSwitch model, provider context
InstructionsLoaded file_path, memory_type (Project), zelk_record observe only
SkillLoaded skill_name, source, zelk_record observe only
CwdChanged new_cwd, zelk_record observe only
Notification message, notification_type (zelk warning code), zelk_record observe only
SessionEnd reason (run outcome), zelk_record observe only; fires at run end
Interrupt reason, zelk_record observe only
PostCompact compact_summary, zelk_record observe only
WorktreeCreate name the host’s: prints the new worktree’s absolute path; one command, no matcher
WorktreeRemove worktree_path the host’s: removes that worktree

tool_input and permission suggestions contain zelk’s canonical tool schema and rule objects. Some permission-denied invocations do not carry arguments. zelk_record preserves the complete native observed event. Fields the callback does not provide (such as InstructionsLoaded’s load_reason, CwdChanged’s old_cwd, and PostCompact’s trigger) are omitted. Tool names are zelk’s actual names; no tool or argument renaming is attempted.

WorktreeCreate and WorktreeRemove replace git for the worktrees zelk makes: -worktree, the model’s EnterWorktree and isolated subagents. The host runs them itself, from the project’s trusted file or else the user’s, never the loop. Any exit but 0 fails the operation. zelk can’t tell whether a worktree a hook made holds work, so it removes one only through WorktreeRemove, with the user’s or the model’s explicit consent, and never automatically. See the host README.

An http handler posts the event’s input, the same JSON a command reads on standard input, to url with Content-Type: application/json, as Claude Code’s does:

{"type": "http", "url": "https://policy.example.com/hooks/pre-tool",
"headers": {"Authorization": "Bearer $POLICY_TOKEN"},
"allowedEnvVars": ["POLICY_TOKEN"], "timeout": 10, "onFailure": "block"}
  • url is http or https, with no credentials in it: the trust review shows it, so a secret goes in a header.
  • headers values may name variables as $NAME or ${NAME}, from the hooks’ environment, but only those allowedEnvVars lists; any other is empty, so a header carries nothing the hook wasn’t given. The trust review lists the header names and the variables a hook may send.
  • A 2xx answer is a command’s exit 0: an empty body changes nothing, and a JSON object decides as a command’s stdout does. Any other answer is a failure: a non-2xx status, a body that isn’t a JSON object, a connection that fails, the timeout, a body over 1 MiB. A failure is non-blocking unless the hook sets "onFailure": "block". There is no exit 2: an endpoint blocks by answering a decision.
  • A redirect isn’t followed (a 3xx is a failure), so the input reaches no one but the url the user trusted.
  • Posts go through the host’s proxy and certificates (proxy and certificates).
  • timeout defaults to 60 seconds, as for commands (Claude Code’s is 600).
  • WorktreeCreate and WorktreeRemove take commands only: the host needs a path a command makes. Claude Code’s managed-settings controls (allowedHttpHookUrls, httpHookAllowedEnvVars) have no zelk equivalent: zelk’s managed policy can turn hooks off altogether ("hooks": false), and project hooks run only after the user trusts them.

Exit 0 succeeds; empty stdout leaves normal flow unchanged. A single stdout JSON object can return decisions. Plain stdout adds context on SessionStart, UserPromptSubmit and PostModelSwitch; elsewhere it has no decision effect. Exit 2 uses stderr as the reason: gates deny/block, completed tool events add feedback, and events without a blocking output report an error through core. Other exit codes leave flow unchanged; stderr becomes context where the event supports it; other gates retain the diagnostic as a recorded reason without a blocking decision, and observation callbacks report the error through core. In particular, a missing script’s shell exit 127 is non-blocking; policy scripts should return 2. Those other exit codes are failures, so "onFailure": "block" turns them into exit 2’s decision. Unlike Claude Code, PermissionRequest exit 2 denies. Exit-2 stdout is discarded.

{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Use the deployment pipeline"}}

For PreToolUse, permissionDecision accepts allow, deny or ask; permissionDecisionReason, updatedInput (JSON) and additionalContext map to the corresponding typed output. Allow still passes through normal permission ceilings. Legacy top-level decision: "approve" / "block" is also accepted. PermissionRequest accepts allow/deny, including Claude’s nested hookSpecificOutput.decision with behavior and message. ask or updatedInput at PermissionRequest is unsupported and denies the request.

Top-level decision: "block" and reason block UserPromptSubmit, Stop, SubagentStop, PreCompact and PreModelSwitch. Stop blocks request continuation; core bounds these to three per run. On completed tool events, block/reason becomes feedback, since the tool already ran. additionalContext (nested or legacy top-level) is accepted only for events with context in the table.

continue: false maps to the event’s deny/block with stopReason as its reason; it does not terminate the entire agent. It is unsupported for other events. systemMessage is a warning for the user that the model never sees: it is recorded with the hook’s decision and shown where the hook ran (a notice in the TUI, a ! line in the CLI’s progress), on every event but SubagentStart and the observe-only ones, where nothing records it. A failure is shown the same way, as <Event> hook failed: <why>. Fields only Claude Code’s display uses are accepted and do nothing, so the hook’s decision stands: suppressOutput, terminalSequence, and UserPromptSubmit’s sessionTitle and suppressOriginalPrompt. On PermissionRequest, interrupt is accepted and the denial holds, though zelk can’t stop the agent from a permission hook, and updatedPermissions is accepted and the allow covers this call alone, since zelk keeps no rule a hook writes. Result replacement (updatedToolOutput, updatedMCPToolOutput), initialUserMessage, retry control and all other fields are unsupported, which is a failure. Unknown decisions, mismatched hookEventName, conflicting decisions and malformed JSON are failures, so they deny or block only under "onFailure": "block". Other callback errors follow the core event’s error semantics: context-only events ignore the failed contribution, observation failures cannot undo an event, and reactive compaction cannot be blocked. See the core hook design notes.

From cmd/zelk, run go test -race ./internal/host/... for parsing, payload and output mapping, trust and host construction. go test -race -tags=integration ./internal/host ./internal/host/hooks additionally exercises real shell scripts, process-group termination, cancellation, output bounds and hook decisions in a real agent. The hosts test CLI trust/warnings and the TUI startup review without providers or credentials.