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

0

u/[deleted] 27d ago

[removed] — view removed comment

1

u/Present_Giraffe_5224 27d ago

Thanks. Deletion-only hunks and quoted names are covered by tests now. Diagnostics on lines you didn't touch are a deliberate trade-off: only errors on changed lines block, so the agent never fixes unrelated legacy code, and the end-of-turn check plus CI catch the rest.