Expand description
mushroomdb intercept — the optional PreToolUse hook body (experimental).
Claude Code runs this before a Grep, handing it the tool call as JSON on
stdin. When the pattern is a bare identifier the graph already holds as a
symbol, the search is a question explore answers exactly — the definition,
the callers and the callees, in one reply — where the grep returns every
line the name appears on and leaves the reading to the model. Exit 2 with a
message on stderr is Claude Code’s way of saying so: the tool call is
blocked and the message reaches the model.
§Why it is this conservative
A hook that blocks a search wrongly is far worse than one that never fires,
so decide answers Some only where the graph provably has the better
answer:
- The pattern must be a bare identifier ([
is_identifier]). Anything with regex syntax in it —.,*,|, an anchor, a space — is a search, not a name, and the graph has no opinion about it. - It must be at least three characters.
idmay well be a symbol, and a grep for it is still almost certainly not a request for that symbol. - It must resolve to at least one
Symbolnode, through the same lookupcontextuses for a bare name, so theexplorethe message points at is one that will actually answer.
Everything else — a store that will not open, a payload that will not parse, a missing field — is silence and exit 0, like every other hook this binary writes.
Functions§
- decide
- Whether this
Grepshould be redirected, and what to say if so. - run_
intercept - The whole hook body: parse the payload, open the store, decide.