r/codereview • • 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 an eslint-disable / @ts-ignore / noqa etc. 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 since HEAD.
  • 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:

  1. 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?
  2. parseHunks in lib.mjs**.** It parses git diff -U0 output to find changed lines. Edge cases I've missed (renames, binary files, odd file names)?
  3. Speed. The PostToolUse hook runs after every single edit. Anything obviously slow?
  4. 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

7 comments sorted by

View all comments

Show parent comment

1

u/CCodeSI 27d ago

Thanks, and impressive turnaround! The before/after snapshot around Bash is a better fix than what we suggested: it catches the change no matter how it was made, and it doesn't re-flag the user's own uncommitted suppressions. 70ms per call is a fair price for that.

Comparing only the lint sections of package.json and pyproject.toml is a nice touch too, a guard that asks on every dependency bump would get turned off within a day.