Skip to content

hook-guard: Read/Glob PreToolUse nudge has no session-scoped rate limit — fires on every matching call #2984

Open

Description

@yotamleo

Summary

The hook-guard search / hook-guard read PreToolUse nudge has no per-session (or per-file, or N-per-session) throttle, so within one agent session the identical "MANDATORY: run graphify query ..." line is re-emitted on every matching tool call — including repeated reads of the same file.

Data

Measured over 10,506 Claude Code session transcripts from a single repo (all-time), with graphify 0.9.48 wired as a PreToolUse hook on Read/Glob:

Metric Value
hook-guard search / hook-guard read firings 1,739
Distinct sessions those firings landed in 42
Resulting graphify query / graphify explain calls 21
Conversion ~1.2%
Est. cost ~55 tokens/firing → ~95K tokens

So ~98.8% of the emitted nudges were pure context tax. The tokens land in the agent's context window, which is the scarce resource the hook is trying to help the agent spend well.

Why #1840 doesn't cover this

#1840 (closed) scoped the nudge to the graph's own project root and softened the language on a stale graph. That fixed a real and different problem — nudging on files outside the graph. It did not add any throttle: the numbers above were measured on 0.9.48, i.e. after #1840 shipped, and the same file read still re-fires the identical line every single call within a session.

The two are orthogonal: #1840 controls whether a given call is in scope, this asks for how many times an in-scope reminder is worth repeating.

Request

A session-scoped rate limit on the nudge, independent of the #1840 project-membership fix. The agent only needs to be told once per session that a graph exists — after that it either used it or decided not to, and repetition changes neither.

Reasonable shapes, roughly in order of how cheap they are to implement:

  1. Once per session per subcommand — emit for the first in-scope read and the first in-scope search, then stay silent. Claude Code delivers a JSON PreToolUse payload on stdin that already carries a session_id, so there is a stable key available for the state without asking the host for anything new.
  2. N-per-session (default 1–2), with an env var or config key to tune.
  3. Once per session per file — more permissive, still cuts the repeat-read case that dominates the 1,739.

Happy to send a PR for (1) if that shape is agreeable — it looked like a small amount of state keyed off the existing hook payload rather than anything structural.

Environment

  • graphify 0.9.48
  • Host: Claude Code, hook-guard wired as a PreToolUse hook on Read and Glob

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions