Skip to main content

Module hook

Module hook 

Source
Expand description

The Claude Code PreToolUse hook protocol: turn a stdin envelope into a steering decision.

Functions§

classify
Classify one tool call — its tool_name and tool_input object — into the Steer that serves it, or None to allow. The Bash command is classified by analyze; the harness’s own Grep / Glob / Read calls are steered from their structured fields. Shared by process and log_record; an unhandled tool or a missing field yields None.
decision
Build the PreToolUse decision JSON for a Steer under mode.
log_record
Build a structured log record for one PreToolUse envelope: which tool ran, its Bash command, the call’s cwd/session_id, and what the hook decided under mode. Unlike process this also records the silent allows — the raw material for spotting shell idioms that should have been steered to ct but 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 Bash envelope process did not steer: a warn-only decision (never a deny) prompting the agent to reach for a ct call instead of a shell pipeline. None unless the command is a pipe with no specific steer (see super::pipeline_nudge).
post_record
Build a structured log record for one PostToolUse envelope — the call as it actually executed (event: "post"), paired with whether it used ct. Logged alongside the pre records in the same daily file so an analysis can correlate a steer decision with the follow-up call by session_id and time. Lenient, and stamps no time (the caller does).
process
Process a raw PreToolUse stdin envelope. Returns the decision JSON to print, or None to allow silently. Fail-open: any parse error, an unhandled tool, or a missing field all yield None.