Expand description
kranz hook-guard — the command Claude Code lifecycle hooks invoke
inside worker sessions (ticket
.kranz/tickets/claude-code-hook-gate-projection.md, KRZ-302; the engine
side is kranz_engine::hook_gates, which also records the targeted
hooks schema version).
This is an INTERNAL plumbing command, never an operator surface: the
engine installs it into a worker session’s --settings JSON as a
PreToolUse hook on the file-writing tools. The Claude Code CLI pipes
the hook payload JSON to stdin; the guard judges the tool call’s target
path against the per-session spec file the engine wrote, appends a
structured record to the session’s record file, and exits:
- 0 — the write is in contract; the normal permission flow proceeds.
- 2 — BLOCK: stderr is fed back to the model as the refusal reason;
a
blockedrecord was appended (the engine folds it into ahook.gate.firedevent after the session). - 1 — the GUARD itself failed (unreadable spec, unparseable payload): a non-blocking error in Claude Code, so the action proceeds and a hook-error notice lands in the transcript. Fail-OPEN by design — a broken guard must never freeze a session, and the miss is still judged by the authoritative engine-side out-of-contract sweep.
The guard runs with the session’s already-cleared environment and reads nothing but the spec file and stdin — no new credential or env channel.
Functions§
- run_
hook_ guard - Run the guard: read the hook payload from
stdin, judge it against the spec atconfig, record the outcome, and return the process exit code. Split from the clap dispatch so tests drive it in-process.