Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Opt-in Claude Code hook that requires a CodeGraph query before Grep/Glob (`codegraph gate-hook`)

Abierto
#2,313 1 comentario 0 reacciones 0 asignados Ver en GitHub

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
Área
cli, tooling

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), deny Grep, Glob, and Bash commands whose search head is rg/grep/find/fd/ag/ack. The deny reason tells the model to call codegraph_explore (or codegraph explore|query|node) first.
  • PostToolUse / PostToolUseFailure (mcp__.*codegraph.*|Bash): a CodeGraph MCP call or a codegraph 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 install is not changed.
    • It does nothing outside an indexed project.
    • A pipe target such as pnpm test | grep FAIL is not a search head.
    • Searches whose target is inside node_modules are allowed, but a repo-wide search that only excludes node_modules is still gated.
    • Like prompt-hook, it never breaks a session. Any error, malformed stdin or TTY exits 0 with no output, and CODEGRAPH_NO_GATE_HOOK=1 turns it off.
  • Telemetry: gate-hook-deny and gate-hook-allow counters 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.ts passes 60/60. tsc --noEmit is clean.
  • Built CLI: dist/bin/codegraph.js gate-hook prints 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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de colbymchenry/codegraph

Todos los issues de colbymchenry/codegraph

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.