Opt-in Claude Code hook that requires a CodeGraph query before Grep/Glob (`codegraph gate-hook`)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- node.js, typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C
- Estrellas
- 73.2k
- Forks
- 4.7k
- Merge medio
- 2 h 16 min
- PR fusionados (30 d)
- 423
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de colbymchenry/codegraph
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
colbymchenry/codegraph#2634 ·
Los mantenedores suelen responder en 1 día
-
Windows: bundled Node v24.16.0 can abort at exit (nodejs/node#56645); please bundle Node >= 24.20.0Posiblemente ocupada @Ancienttwo la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
colbymchenry/codegraph#2617 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Invalid regular expression: /\boperator++\s*(?:<[^<>()]*>)?\s*\(/: Nothing to repeat (v1.6.2)Abierto
Dificultad 2/5 Menos de una hora Aptitud para principiantes 72/100
colbymchenry/codegraph#2482 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
codegraph ui - does not workAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
colbymchenry/codegraph#1900 · 2 comentarios · 5 reacciones ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
colbymchenry/codegraph#1700 ·
Los mantenedores suelen responder en 1 día
Todos los issues de colbymchenry/codegraph
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
micropython/micropython#19786 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
vercel-labs/zerolang#442 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
mewencode: base256[] and base128[] are indexed out of bounds by a non-ASCII octetPosiblemente ocupada @kazu-yamamoto la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
kazu-yamamoto/Mew#276 ·
Los mantenedores suelen responder en 1 día