Skip to content

Read/Glob PreToolUse hook: substring ext match misses .astro and false-fires on .json #1463

Closed

Description

@marketechniks

Summary

The Read|Glob PreToolUse hook installed by graphify claude install (and codebuddy install) matches file extensions by substring search over the concatenated file_path + pattern + path string. This produces two opposite failures:

  1. False negative — .astro / .vue / .svelte never nudge. These extensions aren't in the exts tuple, so on Astro/Vue/Svelte projects (where they're the primary source type) a Read or Glob of a component never triggers the graphify hint. Only the Bash/grep hook ends up covering those projects.
  2. False positive — .json matches .js. The check is any(e in s for e in exts), and the substring .js is contained in .json, so reading package.json, tsconfig.json, etc. fires the "run graphify first" nudge spuriously. More generally, any path containing a listed ext as a substring over-fires.

Location

graphify/__main__.py → _READ_SETTINGS_HOOK (the inline python3 -c payload). Referenced by _install_claude_hook and the codebuddy installer, so both platforms inherit the bug. Reproduced on graphifyy==0.8.49.

The current payload reduces to:

s = (file_path + ' ' + pattern + ' ' + path).lower().replace('\\','/')
hit = 'graphify-out/' not in s and any(e in s for e in exts)   # substring match

Repro

# fires, but should be silent (.json contains .js)
echo '{"tool_input":{"file_path":"package.json"}}' | bash -c '<the installed Read|Glob hook command>'

# silent, but should fire (.astro not in exts)
echo '{"tool_input":{"pattern":"**/*.astro"}}'     | bash -c '<the installed Read|Glob hook command>'

Proposed fix

Extract the real trailing extension per value (segment after the last /, then after the last .) instead of substring-searching, and add the framework extensions:

import json,sys
d=json.load(sys.stdin); t=d.get('tool_input',d)
exts=('.py','.js','.ts','.tsx','.jsx','.astro','.vue','.svelte','.go','.rs','.java','.rb','.c','.h','.cpp','.hpp','.cc','.cs','.kt','.swift','.php','.scala','.lua','.sh','.md','.rst','.txt','.mdx')
vals=[str(t.get('file_path') or ''),str(t.get('pattern') or ''),str(t.get('path') or '')]
j=' '.join(vals).lower().replace(chr(92),'/')
tails=[('.'+x.rsplit('.',1)[-1]) for v in vals if v for x in [v.lower().replace(chr(92),'/').rsplit('/',1)[-1]] if '.' in x]
sys.stdout.write('1' if 'graphify-out/' not in j and any(tl in exts for tl in tails) else '')

package.json → tail .json (not in exts, silent); **/*.astro → tail .astro (matched, fires); the graphify-out/ suppression is preserved and every branch still fails open.

Verification (8/8 after fix)

input before after expected
Bash grep -r … fire fire fire
Bash npm run build silent silent silent
Read src/x.ts fire fire fire
Glob **/*.astro silent (bug) fire fire
Read Hero.astro silent (bug) fire fire
Read package.json fire (bug) silent silent
Read graphify-out/GRAPH_REPORT.md silent silent silent
Read netlify.toml (no code ext) silent silent silent

Environment

  • graphifyy 0.8.49, Python 3.13, Windows 11.

Happy to open a PR with the above change if useful.

Activity

  1. safishamsi commented on Jun 25, 2026

    @safishamsi
    Member

    Fixed on v8 in 9b583a0 (via #1464, thanks @marketechniks). The hook now matches the real trailing extension instead of substring-scanning, so .json configs no longer false-fire (.js was matching as a substring) and .astro/.vue/.svelte now nudge correctly. Verified by running the actual hook command against both cases. Ships in the next release.

  2. added a commit that references this issue on Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions