Skip to main content

Module hooks

Module hooks 

Source
Expand description

Claude Code hook logic — all of it server-side.

These run behind marshal’s own plain-HTTP listener (http_listener), not myko’s MCP endpoint: the hook command on every platform is a dumb curl one-liner that POSTs Claude Code’s raw hook JSON and prints the text/plain response back into the agent’s context.

curl -sS --max-time 5 -X POST \
  "$URL/hook/session-start?host=$(hostname -s)&operator=$USER" \
  --data-binary @- || true

No client-side scripts, no jq/bash, no per-platform port — the register / fetch / ack / format work happens here, once, in Rust.

host / operator ride in the query string because the daemon is remote and can’t know the client’s hostname or user; the curl command expands them locally (the only platform-specific bit, $VAR vs %VAR%). Everything else (session_id, cwd) is in the hook body.

Caller identity for the read/ack commands is carried by the commands’ asSession field (self-identify), since this internal context has no WS client_id.

Functions§

dispatch
Dispatch a POST to a /hook/* path. Returns Some(text) (possibly empty) for a known hook route — the listener writes it as the text/plain body — or None for an unknown path (→ 404).