Repository navigation
Description
TL;DR: graphify claude install registers the PreToolUse "search" guard with matcher "Bash" only, but current Claude Code searches code content through its dedicated Grep tool, not Bash. So the guard never fires on Grep, and the agent greps the codebase without ever being nudged to run graphify query first, silently bypassing the knowledge graph.
How I found this
Whenever I use Codex, I watch it reach for graphify on its own before it starts exploring. With Claude Code I never once saw it do that, even though everything was installed and configured correctly. That gap is what sent me digging, and it turned out not to be a Claude quirk but a hole in the guard that graphify installs.
Summary
The Claude Code search-nudge hook was changed from matcher Glob|Grep to Bash in ee1df22 ("Fix PreToolUse hook for Claude Code v2.1.117+"), on the stated premise that "Grep and Glob tools removed in CC v2.1.117; searches now go through Bash." That premise does not hold for current Claude Code. Grep and Glob are still first-class tools, and content search is routed to the dedicated Grep tool, not through Bash.
The result is a regression: the search guard matches a tool the agent no longer uses for search, and never fires on the tool it does use, so the graphify-first nudge is silently dead for the most common exploration path.
I am Claude Code in this session. I have separate tool schemas for Bash, Grep, Glob, and Read, and I invoked the Grep tool repeatedly during this very investigation. It ran ripgrep and returned matches without ever going through Bash. My Bash tool's own description even says: "IMPORTANT: Avoid using this tool to run find, grep... use the appropriate dedicated tool." - Claude Code
So current Claude Code actively routes content search to Grep and away from Bash, the exact opposite of the assumption behind the "Bash"-only matcher.
The exact line
graphify/install.py:300-305, _claude_pretooluse_hooks():
return [
{"matcher": "Bash",
"hooks": [{"type": "command", "command": f"{exe} hook-guard search"}]},
{"matcher": "Read|Glob",
"hooks": [{"type": "command", "command": f"{exe} hook-guard read"}]},
]
Claude Code's matcher is a regex tested against the tool name.
"Bash" matches the tool Bash and does not match Grep. Grep appears in neither matcher, so a Grep call is matched by no graphify hook and the guard never runs. The read guard is fine. Glob is wired into "Read|Glob" and a pattern like */.py fires the read nudge, so among the native tools, only Grep is orphaned.
Repro
graphifyy 0.9.18 (uv tool install), any Claude Code with the dedicated Grep tool:
1. graphify . (or any repo with graphify-out/graph.json)
2. graphify claude install
3. Inspect .claude/settings.json. The search hook is {"matcher": "Bash", ...}, no Grep.
4. In Claude Code (CLI), ask a question that triggers a content search. The agent uses the Grep tool, no additionalContext nudge is injected, and graphify query is never suggested.
Actual: Grep calls bypass the guard entirely and the graph is silently skipped.
Expected: a content search via Grep gets the same "run graphify query first" nudge that a Bash rg/grep gets.
Suggested fix
This is not a clean one-liner, and I want to flag that up front so the PR actually fires rather than just widening the matcher:
- Matcher (necessary, not sufficient), install.py:301: "matcher": "Bash" becomes "matcher": "Bash|Grep".
- Guard body (also required). The kind == "search" branch at graphify/cli.py:130-135 only inspects t.get("command", ""). The Grep tool's tool_input has no command, it carries pattern, path, and glob. So with only the matcher change, Grep calls reach the guard, read an empty command, and still never nudge. The branch needs to treat a Grep-shaped input (has pattern, no command) as a search.
- Idempotency. Add the new matcher string to the four dedup tuples (install.py:1630, 1653, 1804, 1818), or the fix itself will append a duplicate block on upgrade instead of replacing in place.
PR should fold a regression test that feeds a Grep-shaped {"tool_input": {"pattern": "...", "path": "."}} into hook-guard search and asserts the nudge. tests/test_search_hook.py currently only exercises the Bash command shape, which is why this slipped through.
Activity
chore: begin 0.9.20 cycle + changelog for #1986/#1987/#1990/#1991/#1983
fix(install): fire the search nudge on Claude Code's Grep tool, not j…
Merge remote-tracking branch 'upstream/v8' into v8-custom
chore: CLAUDE.md 进版本控制 + .gitignore 移除 CLAUDE.md 规则
fix(install): fire the search nudge on Claude Code's Grep tool, not j…
chore: begin 0.9.20 cycle + changelog for Graphify-Labs#1986/Graphify…