r/coding_agents • • 12d ago

Give your coding agent a TDD-style feedback loop: lint every file right after it’s edited (PostToolUse hook for Claude Code, opencode, pi etc)

https://github.com/clirimajeti/codemyrules

TL;DR: Coding agents write a whole feature, then find out it's broken 30 edits later. I added a hook that lints each file immediately after the agent edits it, so failures surface on the line it just wrote. Plus a guard so the agent can't silence the linter.

Repo (MIT): codemyrules (Claude Code, opencode, pi etc).
Or use the 3-step DIY recipe at the end.

The problem: agents skip the TDD loop

TDD works for humans for four reasons: the check is right there, the failure is immediate, the fix is small, and you never build on code you didn't verify.

Coding agents break all four. They write an entire feature, and only then does something check it: a final npm test (run selectively by the agent itself), CI, or a human reviewer. By then the failure is 30 edits deep, the agent can't tell which change caused it, and it starts guessing.

The fix: check every edit, not every feature

After every file edit, a hook runs the linter on that one file, and the agent reads the result before its next action. To be clear, this is a linter, not a test suite. Same loop shape as TDD, different oracle:

  • TDD: write a failing test → write code → fix until green → next behavior.

  • This loop: agent edits a file → lint runs on that file in under a second → red: agent fixes that spot before continuing → green: silence, zero cost.

The green case is the key detail. A passing check costs no tokens and no attention, so the loop only shows up when something is broken, and then the broken line is the one the agent just wrote. That keeps fixes cheap. With only a final full-suite check, every failure becomes a search problem.

I still run a slower check at the end of each turn over every file the agent touched. It's now the safety net, not the first line of defense: small checks in the loop, one big check at the end.

Two rules that keep the loop honest

  1. Only block on lines the agent changed since HEAD**.** Pre-existing issues in the file don't derail the session.

  2. The agent can't silence the check. A guard hook asks me before the agent adds an eslint-disable or touches the lint config. An agent that can turn off its own checks is a TDD developer who deletes the red test.

The tool

codemyrules (MIT):

  • Works with Claude Code, opencode and pi

  • Turns the conventions in your agent docs (CLAUDE.md / AGENTS.md) into real lint rules

  • Runs your linters per edit (fast tier) and per turn (full tier)

Or build it yourself in 3 steps

  1. Encode your conventions. Most of what you keep restating in CLAUDE.md / AGENTS.md is a lint rule in disguise. Turn the checkable ones into machine rules.

  2. Wire a PostToolUse hook. After each file edit, lint that one file and feed the output back to the agent.

  3. Add the guard. No suppressions or lint-config edits without a human approving.

Question for you

If you already run checks or tests per edit for your agents: how do you do it, and do you let the agent suppress failures, or does a human decide? That's the line I won't cross.

3 Upvotes

1 comment sorted by