Opt-in Claude Code hook that requires a CodeGraph query before Grep/Glob (`codegraph gate-hook`)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
Research direction
Review the proposed branch and start with src/hooks/gate.ts and src/bin/codegraph.ts, comparing the new hook with the existing prompt-hook. Run tests/gate-hook.test.ts and tests/frontload-hook.test.ts, then check the README.md and CHANGELOG.md updates. Done means the opt-in hook gates searches only as described, passes its tests and type check, and leaves installation unchanged; the issue author has already implemented a branch.
Written by the indexing model from the issue text.
Description
Problem
In an indexed project, Claude Code still often answers code questions with Grep/Glob or rg/grep/find through Bash instead of CodeGraph (#1279). #1696, fixed in #1697, made the codegraph_explore schema available from the first turn with alwaysLoad, which raises the odds the model can pick it. Some users want a guarantee instead: no text search until the index has been asked once.
prompt-hook front-loads context for structural prompts, but nothing currently stops a session that skips it and greps first.
Proposal
A small, opt-in Claude Code hook next to prompt-hook: codegraph gate-hook, hidden like prompt-hook.
PreToolUse(Grep|Glob|Bash): in an indexed project (findNearestCodeGraphRoot), denyGrep,Glob, and Bash commands whose search head isrg/grep/find/fd/ag/ack. The deny reason tells the model to callcodegraph_explore(orcodegraph explore|query|node) first.PostToolUse/PostToolUseFailure(mcp__.*codegraph.*|Bash): a CodeGraph MCP call or acodegraph explore|query|node|…Bash command writes a per-session marker. From then on, text search is allowed again for literals and non-code files.- Never in the way:
- It is off unless the user registers it.
codegraph installis not changed. - It does nothing outside an indexed project.
- A pipe target such as
pnpm test | grep FAILis not a search head. - Searches whose target is inside
node_modulesare allowed, but a repo-wide search that only excludesnode_modulesis still gated. - Like
prompt-hook, it never breaks a session. Any error, malformed stdin or TTY exits 0 with no output, andCODEGRAPH_NO_GATE_HOOK=1turns it off.
- It is off unless the user registers it.
- Telemetry:
gate-hook-denyandgate-hook-allowcounters only, no payload content.
I have run the same behavior for a while as a local Python hook, and it reliably makes sessions query CodeGraph before searching.
Implementation ready for review
Branch on my fork: https://github.com/BGamboa13/codegraph/tree/feat/gate-hook (one commit, feat(hooks): add opt-in gate-hook to require a CodeGraph query before text search)
| File | Change |
|---|---|
src/hooks/gate.ts |
Pure logic: runGateHook, isSearchHead, isCodegraphCommand, isIndexed |
src/bin/codegraph.ts |
Hidden gate-hook command (kill-switch, TTY guard, stdin, telemetry), mirroring prompt-hook |
__tests__/gate-hook.test.ts |
12 tests |
README.md |
Opt-in settings snippet next to the hooks docs |
CHANGELOG.md |
[Unreleased] › New Features entry |
Verification, on Node 24.21.0 with env -i and an empty HOME:
- RED: before the module existed, the suite failed to load.
- GREEN:
vitest run __tests__/gate-hook.test.ts __tests__/frontload-hook.test.tspasses 60/60.tsc --noEmitis clean. - Built CLI:
dist/bin/codegraph.js gate-hookprints the deny JSON for a Grep payload in an indexed temp repo, and exits 0 silently on garbage stdin.
Out of scope: installer integration (codegraph install offering the hook). It could follow in a separate PR if you want it.
Would you take this? I'll open the PR from that branch once you're OK with the approach, and adapt names or behavior to what you prefer.
- Dominant language
- C
- Stars
- 73.2k
- Forks
- 4.7k
- Avg merge
- 2h 13m
- Merged PRs (30d)
- 418
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from colbymchenry/codegraph
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
colbymchenry/codegraph#2634 ·
Maintainers usually reply within 1 day
-
Windows: bundled Node v24.16.0 can abort at exit (nodejs/node#56645); please bundle Node >= 24.20.0Possibly taken @Ancienttwo claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
colbymchenry/codegraph#2617 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Under an hour Newbie friendliness 72/100
colbymchenry/codegraph#2482 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
colbymchenry/codegraph#1900 · 2 comments · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
colbymchenry/codegraph#1700 ·
Maintainers usually reply within 1 day
All issues in colbymchenry/codegraph
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
OpenPrinting/cups#1772 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
antoxa2584x/nfsu2-sw#44 · 1 reaction ·
Maintainers usually reply within 1 day