r/codereview • u/Present_Giraffe_5224 • 27d ago
[JavaScript/Node] Review my Claude Code hooks that lint every file an agent edits (~330 lines, zero deps)
I built codemyrules, an open-source agent skill that turns the rules in AGENTS.md / CLAUDE.md into ESLint or ast-grep rules. The part I'd like reviewed is the feedback loop: three small Node scripts that run as Claude Code hooks, plain ESM, no dependencies, tests with node:test.
guard.mjs(PreToolUse, 68 lines): asks the user before the agent adds aneslint-disable/@ts-ignore/noqaetc. or edits a lint config.lint-edited.mjs(PostToolUse, 39 lines): runs the fast linters on the edited file and blocks only on errors in lines changed sinceHEAD.lint-turn.mjs(Stop, 40 lines): runs all linters on every file edited in the turn.lib.mjs(181 lines): diff hunk parsing, linter output parsing, config, the secret-file deny list.
Code: https://github.com/clirimajeti/codemyrules/tree/main/skills/codemyrules/scripts
What I'd especially like eyes on:
- The suppression regex in
guard.mjs**.** Can you think of a way an agent could silence a rule that it misses, or a false positive that would annoy you? parseHunksinlib.mjs**.** It parsesgit diff -U0output to find changed lines. Edge cases I've missed (renames, binary files, odd file names)?- Speed. The PostToolUse hook runs after every single edit. Anything obviously slow?
- Failure modes. A broken hook must never block the agent forever or leak a credential file. Anything that could?
Run the tests with node --test skills/codemyrules/scripts/test/*.test.mjs. Honest feedback welcome.
0
Upvotes
View all comments
Show parent comment
1
u/Present_Giraffe_5224 27d ago
Thanks! Those were the right areas to poke at. Timeouts are now a hard kill with a shared budget, and a broken or slow linter is reported as a note and treated as clean, so it never blocks. Renames, paths with spaces and quoted names all have tests now. Suppressions in Markdown docs are skipped. One inside a string literal in code still asks, which I'd rather keep than miss a real one.