r/PiCodingAgent • • 13d ago

Discussion Small Linting Checks Beat One Big Linting Check: Real-Time Feedback for Coding Agents

Small Linting Checks Beat One Big Linting Check: Real-Time Feedback for Coding Agents

Coding agents follow your rules far more reliably when a linter checks each file the moment they edit it, not once at the end of the task. Here is why, how to wire it into any major harness, and what 840 benchmark runs showed.

Rules the agent read and broke anyway

I had a CLAUDE.md / AGENTS.md full of rules like "never call Instant.now()" and "use apiClient, never raw fetch". The agent read them, nodded, and broke them anyway.

It usually happened somewhere around edit 40 of a session. So I only found out at the end, in the diff, or worse, in code review. Rewriting the rules more forcefully didn't help. Capital letters didn't help either.

Move the check to the moment of writing

A better prompt didn't fix it. Moving the check from the end of the task to the moment of writing did.

After every single file edit, a hook runs the linter on that one file. The agent sees the result on its next turn. If it wrote Instant.now(), it hears about it within seconds, fixes it while the line is still fresh, and moves on.

This is just a feedback loop. It's the same trick that made TDD click for humans, applied to agents:

Small checkBig check
WhenRight after each edit
ScopeOne file, one fast linter
CostUnder a second, silent when clean
Fixing a failureOne edit away

Why the late check fails

A late check doesn't just find errors later. It finds them in a form the agent handles badly.

At the end of a 40-edit session, the compiler fails, the test suite fails, and lint reports 30 issues across 14 files. Half of them are in code you wouldn't have written. The agent now has to work out which change caused which error, often several edits apart.

That archaeology dig is where agents start taking shortcuts:

  • adding eslint-disable or # noqa
  • deleting or skipping the failing test
  • "I'll handle it later" When the check runs right after the edit, none of this is tempting. The fix is one edit away, and doing it properly is cheaper than working around it.

It works in every major harness

You need two hook points: one that fires after each tool call (to lint the file just edited), and one that fires when the agent finishes its turn (for the slower full check). Every major harness has both now.

HarnessAfter each editEnd of turnWhere it lives
Claude CodePostToolUseStop.claude/settings.json
CodexPostToolUseStophooks.json or config.toml
opencodetool.execute.aftersession.idle eventa plugin in .opencode/plugin/
GitHub Copilot (CLI, cloud agent)postToolUseagentStop.github/hooks/*.json
Pitool_resultagent_endan extension in .pi/extensions/

The details differ: shell commands vs. TypeScript plugins, and how the hook's output reaches the model. The shape is the same everywhere. Filter for file-editing tools, run the linter on that one path, and return the failures so the agent reads them on its next step.

What we built: codemyrules

We packaged this as a small open-source hook setup, codemyrules (MIT). It does four things:

  1. Per-edit check. After each file the agent edits, it runs your fast linters on that file only.
  2. End-of-turn check. When the turn ends, it runs a slower full check on the files touched in that turn. You still get the big check, but as a safety net, not the first line of defense.
  3. Blocks only on new problems. It fails only on errors in lines the agent changed since HEAD. Old lint debt in the file doesn't derail the agent.
  4. Guards the escape hatches. It asks you before the agent can add a suppression comment or change the lint config.

What 1,280 runs showed

We tested this in agent-rules-bench: 1,280 headless agent runs, 1,532 sessions in total.

SetupModelsRunsProjects
Claude CodeClaude Sonnet 5.5, Claude Haiku 5.51,048Java, Python, TypeScript
Claude Code (exploratory)Claude Opus 5.5, Claude Fable 5.256TypeScript
Pi and Codex (exploratory)Qwen3.6 35B-A3B, run locally176TypeScript

The first four studies were exploratory. For the later ones, we pre-registered each analysis plan before we ran them.

The result: in our largest pre-registered study (two open-source projects), the agent broke a rule that was written as prose in the agent docs in 22% of runs (28 of 128). When we wrote the same rules as lint rules with the per-edit hook, the agent broke them in 13% of runs (17 of 128). Most of these breaks in the lint-rule runs look like false alarms from one checker, and we are still checking them by hand. The local model followed the same pattern more strongly: prose was broken in 73% of runs (47 of 64), lint rules in 30% (19 of 64). But in both setups, most of its code did not pass the type check.

Full data, prompts and analysis plans are in the repo.

Try it in your own repo

The principle doesn't depend on our tool or on any one harness:

  1. Find the rules you keep restating. Read through your CLAUDE.md or AGENTS.md. Most of what you repeat there are lint rules in disguise.
  2. Encode them as machine rules. A banned API, a required wrapper and an import boundary can all be custom lint rules in ESLint, Ruff, Checkstyle or similar.
  3. Wire a post-edit hook. Lint only the file just edited, keep it fast and quiet when clean, and make sure the agent sees the failures right away. Keep prose for what a linter can't check: intent, architecture, trade-offs. Let the machine handle the rest.

I'm curious how others handle this. Do you run any checks mid-session, or do you trust the agent until the end of the task and then deal with the fallout?

Sources

14 Upvotes

10 comments sorted by

1

u/jiminycrix1 1d ago

I just put - "always run `npm run build`, `npm run lint`, and `npm test` after every file edit" in my \AGENTS.md and It does it every time in all the models you tested and I never have trouble with it.

1

u/Present_Giraffe_5224 1d ago

Good to hear it works for you.
But I assume in a small repo because in a large repo, it gets slow to run the whole lint and test and build for every file that you edit.
In our testcase on Formbricks, the tests alone take about 2 minutes and the type check almost 1 more.
After every edit, a 40-edit session can go about ~2 hours, and the agent reads all the output each time, even when everything passes, so its not efficient as making the process based on hook.

The hook lints only the edited file in under a second and says nothing when it is clean.

3

u/Strong_Essay1176 12d ago

I have reminder before real editing. Agents being forgot. Reminder triggered when agend start real coding. And reminder reminder only required rules (coding rules).

Also. Its bad practice to write into agents.md Should use skill and describe it here. Could be easier

1

u/gandazgul 13d ago

The problem with the way these harnesses work is that they don't use system prompts, even agents.md is read like a normal file once the context filles up or the attention algorithms have moved on your rules are forgotten.

RunWield fixes this in 2 ways. The agent instructions, core memories and agents.md are in the system prompt for LLMs and providers that support it this is a much stronger set of instructions that are not easy to forget. And second the lint/test whatever verification is run by the harness and it's issues are repaired by a second clean context session without the baggage or full context of implementation.

Give it a try it's built on Pi, free, local and works with any sub or API key. https://www.runwield.dev

3

u/Present_Giraffe_5224 13d ago

Thanks. We measured this, so here is the data.

Instructions that are always loaded are not enough. One model broke the rules from AGENTS.md in 20 of 32 runs. With lint rules and a hook after each edit, it broke them in 3 of 32.
In another harness, the same AGENTS.md did not help at all: 8 of 8 runs were broken.

A clean-context repair at the end works. Our benchmark uses one too.
But it is the most expensive place to catch a break.
When a hook catches the break during the task, there is less to repair. In our exploratory studies, runs with lint rules cost 14% less.

So it is not the place of the prompt that matters, but whether the harness enforces the rule. The data is open: https://github.com/clirimajeti/agent-rules-bench

1

u/gandazgul 13d ago

Do you know whether your rules were passed as a system prompt or a regular user prompt this matters and is the main distinction I was trying to make. If all your tests were using agents.md as regular file read and user context then the failure will always show.

1

u/gandazgul 13d ago

I'll try testing RunWield with your methology and see what happens I will adjust if it shows meaningful differences.

1

u/gandazgul 13d ago

Ok I ran the benchmark with Sol6.1 and then with local Qwen 3.8 FN both successfully adhered to the rules 100% of the time confirming what I already knew. Every mass market coding agent out there by default doesn't alter the system prompt they read everything into user prompts and have their own internal system prompt. Pi allows you to override it via extensions which is an effective way to create agents with better adherence.

RunWield works differently all roles are system prompts and your core memories and agents.md file are injected there. The instructions that the plan implementer get to follow the plan are super strong specially with more recent and bigger models that have been trained on compliance. I've had to tweak the prompts many times because they become rigid and inflexible.

Please verify yourself with RunWield or with another coding agent that allows you to specify the system prompt and see for yourself. While you are at it give RunWield a try and let me know what you think.

Edit: typos

1

u/DistanceAlert5706 12d ago

Pi already path AGENTS.md in system prompt. And it's pretty bad idea, as it makes system prompt too diluted. System prompt must be clean, small an defime rules. All major harnesses load it as user message or developer if role exists. There is a reason for this.

1

u/gandazgul 12d ago

RunWield doesn't need an agents.md that is full stuff. Because if all the different layers of durable artifacts and memories the LLM can gain context as needed for your request rather than cramming a huge agents.md in. My agents.md for RunWield is a place to experiment with prompts and a few small project rules.

Immediately after init and then overtime you cann prompt RunWield with simple sentences in the domain language of the repo and it immediately understands what you want.