Documentation
¶
Index ¶
- func ContextKey(inp *protocol.HookInput) string
- func Dispatch(store hookcore.StateStore, r io.Reader, w io.Writer) error
- func DispatchBytes(store hookcore.StateStore, req []byte, w io.Writer) error
- func HandleBash(r io.Reader, w io.Writer) error
- func HandleGlob(r io.Reader, w io.Writer) error
- func HandleGrep(r io.Reader, w io.Writer) error
- func HandlePostCompact(r io.Reader, w io.Writer) error
- func HandlePreCompact(r io.Reader, w io.Writer) error
- func HandlePreToolUse(r io.Reader, w io.Writer) error
- func HandleRead(r io.Reader, w io.Writer) error
- func HandleSessionStart(r io.Reader, w io.Writer) error
- func HandleWrite(r io.Reader, w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextKey ¶ added in v0.1.4
ContextKey returns the state-store key for one hook invocation.
It is deliberately NOT the session id. Claude Code reports a subagent's tool calls under the PARENT's session_id, but a subagent has its own context that is thrown away when it finishes — nothing it reads ever reaches the parent. Keying the file cache on session_id alone therefore lets a subagent's read deny the parent's, handing back "no re-read needed" for content the parent never saw. That is the one failure this cache must not have: a deny cannot be downgraded to a safe passthrough, because there is no content in hand.
Splitting the key keeps each context honest, and still lets a subagent dedup against its own earlier reads.
func Dispatch ¶
Dispatch is the single PostToolUse entry point. It decodes the event once and routes by tool name: Read and Write keep their file-specific handlers; every other tool (Bash, Glob, Grep, mcp__*, anything new) flows through the generic pipeline so it gets dedup / delta / noise-strip / squeeze / structural summaries for free — no per-tool hardcoding. store is the pipeline's session and cache backend (the on-disk cache for the CLI, an in-memory store for a future daemon).
func DispatchBytes ¶
DispatchBytes is Dispatch for callers that already hold the whole request in memory (the daemon, via a pooled read buffer): it decodes with a single json.Unmarshal instead of wrapping the bytes in a json.Decoder, avoiding that decoder's extra buffering/streaming layer on the hottest path. Pool safety is unchanged — json.Unmarshal, like the Decoder, copies every string out of req, so nothing routeInput retains aliases the pooled bytes.
func HandleBash ¶
HandleBash is retained for backward compatibility. PostToolUse routing now goes through Dispatch, which handles Bash (and every non-Read/Write tool) via the generic pipeline.
func HandleGlob ¶
HandleGlob is retained for backward compatibility; Glob is handled by the generic pipeline via Dispatch (buildGlobTree is its tool-specific step).
func HandleGrep ¶
HandleGrep is retained for backward compatibility; Grep is handled by the generic pipeline via Dispatch (buildGrepSummary is its tool-specific step).
func HandlePostCompact ¶
HandlePostCompact runs after compaction completes. It injects a manifest of previously-read files into the fresh context, so Claude knows what's been read without re-reading.
func HandlePreCompact ¶
HandlePreCompact runs before Claude Code performs context compaction. It records CompactedAt in the session state so subsequent reads know to serve full content (since compaction erased the context).
func HandlePreToolUse ¶
HandlePreToolUse intercepts Read tool calls before execution. If the file's mtime matches the cached mtime and the file was seen after the last compaction, it denies the read with an §unchanged§ marker — the file is not read at all, saving I/O and output tokens.
func HandleRead ¶
HandleRead processes a PostToolUse hook call for the Read tool. It reads the hook JSON from r, applies delta/unchanged logic, and writes the hook output JSON to w.
func HandleSessionStart ¶
HandleSessionStart runs at session start (after compaction or fresh session). If there is an existing state file from a previous compacted session, it injects the file manifest. Otherwise it's a no-op.
func HandleWrite ¶
HandleWrite compresses Write/Edit/MultiEdit tool responses. Claude just wrote this content — no need to see the full file (Edit's echo even embeds the entire pre-edit originalFile). Also caches the written file for delta tracking on the next Read.
Types ¶
This section is empty.