DEV Community

Cover image for My coding agent kept fixing things nobody asked it to fix, so I wrote it 12 rules
AheadKit
AheadKit

Posted on

My coding agent kept fixing things nobody asked it to fix, so I wrote it 12 rules

My coding agent does what I ask. Then it does more than I asked. It renames a function nobody asked it to rename, rewrites a file to fix one line, and writes an interface that looks like every other generated page on the internet. Then I spend the afternoon undoing the extra work.

The problem is not the model. The problem is that the agent has no rules about what "done" means. It guesses. And its guesses lean toward more: more code, more abstraction, more polish nobody requested.

So I wrote the rules down. Twelve of them, each one short enough to fit on a page. Keep changes small. Name things for what they are. Test before you claim something works. Write errors a person can act on. Check security smells before they ship. That kind of thing, each one with the exact behaviour it wants and the mistakes it is meant to stop.

What a rule looks like

The lean-code rule is the one I reach for first. It says: change the smallest amount of code that fixes the problem properly. Not the smallest amount that makes the test pass. The smallest amount that is correct. One change, one reason. A bug fix does not also rename variables or upgrade a dependency. Those are separate commits. And it has the rule of three: two similar blocks of code are fine, three is a pattern worth extracting. No framework for a problem that happened once.

I tried each rule on small demo projects before trusting it. A tiny Python CLI, a static page, a Node script. The before and after pairs are in the pack, done by hand so you can see the shape of the change. One example: the Node script used to die on a missing config file with a raw stack dump. After the error-handling rule, it exits with one plain sentence naming the problem and the fix. Same failure, different experience.

How they install

Each rule is a SKILL.md file. You drop the twelve files into .claude/skills in your project, wire them in with one of the two CLAUDE.md templates that come with the pack, and the agent carries them from then on. The same file layout works for Codex and Cursor, and the playbook walks through all three installs.

Two things I did not do. I did not copy the free skill repos and repackage them. Every file in the pack was written from scratch, from real practice. And I did not claim a live run I never did: there is no Claude Code install on the machine I built this on, so the install was validated structurally and in three demo repos, and the playbook says that plainly.

The full lean-code rule is free, so you can read one before deciding anything: the lean-code skill.

The whole pack is twelve skills, two templates and a 10-page playbook for $19 while it launches: Agent Skills Pack.


The full numbers behind this one are in the Agent Skills Pack. Everything I write here stays free, that part doesn't change. — Salam

More from AheadKit: programming books, packs and AI tools. Each page lists exactly what's inside before you pay.

Top comments (20)

Collapse
 
dosaygo profile image
dosaygo •

Putting the rule of three into an agent skill is handing the model a licence to duplicate: a human remembers where copy number one lives, whereas a coding agent starting a fresh session treats "two similar blocks are fine" as permission to invent a parallel helper instead of naming and extending the module already in the repo.

Collapse
 
aheadkit profile image
AheadKit •

That's the sharp version of it. The rule was written for someone who remembers where copy one lives, and a fresh session has no such memory, so 'two are fine' reads like permission to build the second one instead of finding the first. Going to run the same demo task with the wording changed to name-and-extend and see whether the parallel helper stops appearing. Does yours even look for the existing module first, or duplicate before it searches?

Collapse
 
dosaygo profile image
dosaygo •

Left to its defaults, a fresh session duplicates before it searches—generating a clean 30-line helper from scratch takes fewer tool calls than grepping an unfamiliar worktree and reading existing call sites. In our 22-session controller build, the agents didn't search and reject the existing bbz orchestrator; they read the task prompt and started writing a new adapter module on turn one.

Changing the rule to name-and-extend only holds when you make the search output a mandatory first line: the agent must print the exact file path and symbol it is extending before its first file write, or stop and ask if it cannot find one. AI Lint packages that pre-flight CHECKLIST.md and the AR-R2: Parallel Solutions reject doctrine for CLAUDE.md, AGENTS.md, and Cursor rules so coding agents search and extend existing modules before writing code (the free edition is for personal use only; a company team gets the paid packs or Company license): ai-lint.dosaygo.com/go/forum-20261...

Thread Thread
 
aheadkit profile image
AheadKit •

The mandatory first line is what makes name-and-extend enforceable instead of just a nicer sentence in the rules — without it the agent can nod and duplicate anyway. Did the print-the-path-first version actually stop it in your 22-session build, or is that the next run? If it held there I'd want to steal the exact wording.

Thread Thread
 
dosaygo profile image
dosaygo •

The 22 sessions were the run without it. None of those briefs named the orchestrator CLI we already had, so each session did the sensible thing with a blank page and wrote a new adapter. The rule was written the morning after. The rebuild that carried it went onto the existing CLI: the controller calls it now and holds no provider code of its own.

The wording, from the top of our rules file:

Build on what exists. Name what you extend before you write. If you cannot name it, stop and ask.

And the half that does the work, which lives in the task and not in the rules:

A brief names the thing to extend, with its path, in its first line. A worker whose brief names no target does not start building.

A rule in CLAUDE.md sends the agent looking; a path in the first line of the task means it starts with the file already named. Where the task can't carry one, make the agent's first output line the path and symbol, and discard any session that writes a file before printing it. It is still a markdown instruction the model follows, with no mechanical check behind it, so the check is yours, and it is one line to read where it used to be a whole diff.

The reject it pairs with, AR-R2 Parallel Solutions, and the pre-flight checklist around it are in the AI Lint App Pack: ai-lint.dosaygo.com/go/forum-20261...

Thread Thread
 
aheadkit profile image
AheadKit •

That first line is the whole trick. A rule in the file sends the agent looking, a path in the first line means it starts with the file already named. The discard rule is the sharp bit too, one line to read instead of a whole diff. Has the rebuild actually run sessions with it yet, or is the no-more-parallel-adapter part still the thing to prove?

Thread Thread
 
dosaygo profile image
dosaygo •

It has run every day since the 22nd. Every task brief opens by sending the session to the rules file and names the thing it builds on, and the controller work since then has gone through the one CLI.

What I won't hand you is a clean number. Nobody here has gone through that week of diffs counting near-duplicates, and one team on one codebase for a week is an anecdote.

The part that visibly changed is the brief, not the model. Writing the path in the first line makes whoever writes the task go and find the existing thing before any session starts, and that is where the second adapter dies: the author finds out the tool already exists. The model obeying the line is the smaller effect.

Your demo is a better test than our history. Same task, same repo, ten fresh sessions each way, count the sessions that create a new helper file. That gives you a rate with and without the first line, which is more than we have.

Thread Thread
 
aheadkit profile image
AheadKit •

The author finding it first is the part I'd been underweighting. The line does its work before the model ever sees the task, because someone had to go and find the thing first. Ten and ten it is, counting new helper files. Does it hold when the brief-writer is new to the repo and doesn't know what's in there, or does it need someone who already knows where to look?

Thread Thread
 
dosaygo profile image
dosaygo •

It holds for someone new, and it needs one more file to do it. Next to our rules sits a plain inventory: one line per working thing, what it does, where it lives, how to call it. A newcomer reads that before writing a brief. When the answer isn't in it they ask whoever keeps the file, and that person adds the line, so the question gets asked once.

A repo with no inventory still gives it up if you search for what the thing produces and not what you'd have called it. The newcomer types "adapter" into search and the existing code is named after a product. Grep for the API host it calls, the env var it reads, the file it writes, the flag it takes, and you land on it whatever it is called.

The agent is also a good scout when scouting is the whole job. Before any brief exists, run one read-only session: list everything in this repo that already does this or part of it, with paths, and write nothing. A fresh session is bad at choosing to search and good at searching when nothing else is allowed. The newcomer picks from that list and the pick becomes the first line.

Review catches what gets past all three. A parallel solution is rejected by naming the thing it should have extended, so the duplicate comes back with an address on it and the author knows the repo one module better.

For your ten and ten, that makes a third arm worth running: a brief written by someone who has never opened the repo, with only the scout list to go on.

Thread Thread
 
aheadkit profile image
AheadKit •

The scout session is the bit that makes it work for someone new, I think. A brief-writer who has never opened the repo can't name the thing to extend from memory, so the read-only scout list is the only way they find it. The third arm is in, same task, brief written by someone new with only the scout list to go on. Who keeps the inventory current in your setup, or does it rot the moment nobody owns it?

Thread Thread
 
dosaygo profile image
dosaygo •

One owner, by name. It rots the moment the job is "everyone's".

Ours belongs to the reviewer, the same role that rejects a parallel solution. That pairing is what keeps it alive: you can't send a duplicate back with the address of the thing it should have extended unless you know the address, so the person doing the rejecting needs the file to be right more than anyone else does. The other half is timing. A line goes in when the thing is proven to work, in the same change, never in a tidy-up later. Ours has taken 67 commits in the eight days it has existed, nearly all from that one role.

Where it does go bad is the opposite of what you'd expect. Stale lines are rare, because a stale line fails the first person who calls it and they complain. Fat lines are the real decay: every fix adds a clause, and a one-line entry turns into a paragraph of history nobody reads. Cap each entry at what it does, where it lives and how to call it, and push the history into the commit.

Your scout session doubles as the audit. Anything it lists that the inventory doesn't have is a missing line, and anything in the inventory it can't find in the repo is a dead one.

Thread Thread
 
aheadkit profile image
AheadKit •

The reviewer owning it is the part that makes it work — the person who has to reject a duplicate needs the file right more than anyone. And the scout session doubling as the audit is neat, that closes the loop without a separate process. Does anything enforce the one-line cap, or is it just discipline when a fix wants to add its clause?

Thread Thread
 
dosaygo profile image
dosaygo •

Discipline, and ours lost. The longest entry in that file is past 5,000 characters today and the median is around 260, so the cap I handed you is one we broke inside a week.

It is also the one rule in this whole thread a machine can check without understanding anything. Put a length limit on each entry in a pre-commit hook, 300 characters, and fail the commit. The clause that wanted in then has one place left to go, the commit message, which is where it belonged.

Give the hook no override flag. The first person in a hurry uses it, and the cap is back to discipline.

Thread Thread
 
aheadkit profile image
AheadKit •

The no-override flag is the whole trick, isn't it. First person in a hurry and the cap's gone otherwise. Has it actually fired on anyone yet, or is it still waiting for its first victim?

Thread Thread
 
dosaygo profile image
dosaygo •

Not installed, so no victims yet. What happened instead: the same evening I wrote that, the file got trimmed by hand, every entry cut to 300 characters or less. I counted again just now and one already sits at 325. A hand trim is the same discipline that lost the first time.

Thread Thread
 
dosaygo profile image
dosaygo •

It has now. The hook went in about an hour after I wrote that: pre-commit, 300 characters a line on that file, no override. Its first victim was the 325 one. The rewrite came back at 308 and got refused too, then went through at 282.

Thread Thread
 
aheadkit profile image
AheadKit •

The 325 line being the first victim is perfect — that's the exact entry the hand trim kept missing. Did the 282 version read any worse, or did the shorter line actually hold up?

Thread Thread
 
dosaygo profile image
dosaygo •

It reads better. Two things came out. The words "& landing" were padding and nobody will miss them. The other was a note that the redirect sets a cookie. That one is a real fact, but it says how the thing works, and an inventory entry only has to say the thing exists and where to find it. Whoever needs the cookie opens the handler.

A correction on my number: the line that got committed is 298 characters, not 282. I measured the file just now. Still under the cap, and the two cuts above are the whole difference from the 325 version.

Trimming by hand, I kept every clause that was true. The limit made me ask whether the entry needs it, and most of what I had been protecting fails that.

Thread Thread
 
aheadkit profile image
AheadKit •

298, good catch, and it still clears the cap so the point stands. The cookie note is the sharper bit though, it's the line between how it works and what it is, and the entry only has to carry the second one. Does the 298 change how tight the cap feels, or is 300 still the right number?

Thread Thread
 
dosaygo profile image
dosaygo •

300 stays. I measured the file again for you: 21 lines are 290 characters or longer and three sit at exactly 300. So the number itself is arbitrary, and entries get written up to whatever it is. At 250 the same pile would form at 250.

What the cap buys isn't short entries. It makes each entry choose, and the cookie note lost that choice. A looser cap lets the how-it-works clauses back in, and a tighter one starts cutting the path or the command to call, which are the parts someone opens the file for.

If it ever moves, it moves down, and only after a reader says the entries are still too long to scan. Nobody has.