Expand description
The Claude Code PreToolUse hook protocol: turn a stdin envelope into a
steering decision.
Functions§
- classify
- Classify one tool call — its
tool_nameandtool_inputobject — into theSteerthat serves it, orNoneto allow. TheBashcommand is classified byanalyze; the harness’s ownGrep/Glob/Readcalls are steered from their structured fields. Shared byprocessandlog_record; an unhandled tool or a missing field yieldsNone. - decision
- Build the
PreToolUsedecision JSON for aSteerundermode. - log_
record - Build a structured log record for one
PreToolUseenvelope: which tool ran, itsBashcommand, the call’scwd/session_id, and what the hook decided undermode. Unlikeprocessthis also records the silent allows — the raw material for spotting shell idioms that should have been steered toctbut currently are not. Lenient: a malformed envelope still yields a record of what could be read. No timestamp is stamped here, so the record stays deterministic; the caller adds the time and appends it as one JSONL line. - pipeline_
nudge_ decision - The generic pipeline nudge for a
Bashenvelopeprocessdid not steer: a warn-only decision (never a deny) prompting the agent to reach for actcall instead of a shell pipeline.Noneunless the command is a pipe with no specific steer (seesuper::pipeline_nudge). - post_
record - Build a structured log record for one
PostToolUseenvelope — the call as it actually executed (event: "post"), paired with whether it usedct. Logged alongside theprerecords in the same daily file so an analysis can correlate a steer decision with the follow-up call bysession_idand time. Lenient, and stamps no time (the caller does). - process
- Process a raw
PreToolUsestdin envelope. Returns the decision JSON to print, orNoneto allow silently. Fail-open: any parse error, an unhandled tool, or a missing field all yieldNone.