Skip to main content

Module hook

Module hook 

Source
Expand description

hook subcommand.

Reads a PreToolUse JSON event on stdin (the contract Claude Code uses for hooks: see docs/specs/SPEC_STREAMING_BASH_RUNNER_2026_05_11.md §5). If the event is a Bash invocation whose command hasn’t already been wrapped, emit an updatedInput.command that invokes agentmux-bashwrap exec with the original command base64-encoded into argv. Idempotent — if the command is already wrapped, pass through with no rewrite.

All errors degrade to a pass-through response so a hook failure never blocks Claude’s tool execution.

Structs§

PreToolUseInput 🔒
Subset of the PreToolUse payload we care about. Extra fields are ignored (serde default).
ScanResult 🔒

Enums§

OutKind 🔒

Constants§

WRAPPED_PREFIX 🔒
WRAPPER_BINARY 🔒

Functions§

build_response
Build the hook response for a PreToolUse payload. Public for testability — callers in tests feed in a payload string and assert the response shape without going through stdin.
is_dev_null 🔒
Strip one layer of matching surrounding quotes for the /dev/null check.
is_space 🔒
passthrough 🔒
read_word 🔒
Read one shell word (quote-aware) starting at/after from, skipping leading spaces. Returns the word’s byte range, or None if there’s no word.
record_response
The hook’s response when the CLI’s shell prefix is this wrapper: record the Bash call for the prefix process to claim (prefix.rs), and answer nothing, so the CLI runs the call exactly as the model made it, its permission rules and checks included. A call that can’t be recorded still runs; it just isn’t streamed. docs/specs/SPEC_BASH_STREAMING_VIA_SHELL_PREFIX_2026_10_10.md §2.2.
run_pretooluse_bash
scan_redirect 🔒
Quote/group-aware scan for a single top-level trailing output redirect. Returns None on any bail condition (see the module comment above).
shell_quote 🔒
Quote a value for embedding in a shell argv position.
skip_spaces 🔒
tee_redirect_rewrite 🔒
Rewrite a recognized trailing redirect to a tee pipeline, or None to pass the command through unchanged.