You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Agent bypasses the graph by Read-ing files: PreToolUse hook only catches Bash grep, not the Read tool (help wanted) #1114
graphify's core value prop is: once graphify-out/graph.json exists, the coding agent should answer codebase questions with graphify query / path / explain (a scoped subgraph) instead of grepping or reading raw files. Today that's enforced by a PreToolUse hook (graphify/__main__.py, _SETTINGS_HOOK) that fires before Bash search commands and nudges the agent toward graphify query:
case "$CMD" in
*grep*|*rg\ *|*ripgrep*|*find\ *|*fd\ *|*ack\ *|*ag\ *)
[ -f graphify-out/graph.json ] && echo '{...additionalContext: use `graphify query` instead...}' ;;
esac
The gap: it only matches Bash search commands. The most common way an agent actually avoids the graph is invisible to it:
The native Read tool — an agent that answers "how does X work?" by reading 20-30 files one at a time never runs a Bash command, so the hook never fires and the graph is bypassed entirely.
Bash content reads — cat, head, tail, sed -n, awk over many files dodge the search-tool match too.
So a graph can exist and still be ignored on exactly the questions it's meant to answer.
Ask (help wanted)
Extend the enforcement so the agent is nudged toward graphify query when a graph exists and it's about to browse raw files, not just when it greps:
Add a PreToolUse hook on the Read tool (and Glob) that fires only when graphify-out/graph.json exists, injecting the same "query first" additionalContext.
Broaden the Bash matcher to include multi-file content reads (cat/head/sed/awk) — but only when multiple paths / a glob are involved, so single-file reads don't trigger.
Design constraint: don't spam
Firing on everyRead is noise that trains the agent to ignore the nudge. Scope it:
Gate on graphify-out/graph.json existing (already the pattern).
Prefer nudging when the Read/glob targets a source or doc file (not configs, not files already inside graphify-out/).
Keep it a nudge (additionalContext), never a block — legitimate reads must still go through.
Scope / why it's low-risk
This is hook configuration in graphify/__main__.py + tests — it touches no skill-file content, so it can't break the extraction pipeline.
Testable: assert the generated settings/hook JSON includes a Read-tool matcher and that the command emits the nudge only when graph.json exists.
Verify the equivalent for the non-Claude enforcement paths (the always-on AGENTS.md / Cursor-rules text already says "query first … instead of raw grep output" — extend that wording to cover reading files, not just grep).
Fixed and released in 0.8.30. A Read|Glob PreToolUse hook (5cc7ec8) now nudges toward graphify query when graphify-out/graph.json exists and the agent reads a source/doc file outside graphify-out/ (the Read-tool path the Bash search hook never saw). It never blocks and fails open. Closing note for the record.
Activity
close the Read-tool graph bypass with a Read/Glob PreToolUse hook
safishamsi commentedon Jun 2, 2026
Fixed and released in 0.8.30. A
Read|GlobPreToolUse hook (5cc7ec8) now nudges towardgraphify querywhengraphify-out/graph.jsonexists and the agent reads a source/doc file outsidegraphify-out/(the Read-tool path the Bash search hook never saw). It never blocks and fails open. Closing note for the record.close the Read-tool graph bypass with a Read/Glob PreToolUse hook