Skip to main content

Command Palette

Search for a command to run...

When your coding agent repeats a mistake, move the lesson out of chat.

Turn repeated corrections into rules, hooks, skills, and an independent review loop that improves the next session.

Updated
10 min readView as Markdown
When your coding agent repeats a mistake, move the lesson out of chat.
B
I build Mindrealm: it catches the slop your AI agent ships confidently, then makes it fix it. 75+ deterministic checks across Go, Rust, TypeScript, and Python.

I stopped judging my coding agent setup by whether one session went well. The better test is what happens when a mistake happens again.

A correction in chat with the agent can fix the current task. If the same mistake comes back, the lesson needs somewhere more durable to live.

When rules for specific tasks live in agent config, the agent loads instructions it does not need for every other type of task. Piling exceptions into a skill or agent makes the important instructions harder for the agent to follow. A hook attached to the wrong event runs another check or review every time that event occurs, whether the work needs it or not.

The real job is deciding where each correction belongs.

I use six different places: agent config, skills for specific tasks, hooks, independent review agents, mistake logs backed by regression tests, and independent code review. All six are necessary in my setup, and each solves a different kind of failure.

That distinction lets the system improve without bloating every prompt, skill, and agent configuration.

Start with the correction, not the tool

When I correct an agent, I ask two questions before deciding where the correction belongs:

  1. What exactly failed?

  2. What change would keep it from happening again?

That second question matters. A rule can guide judgment. A hook can run a deterministic check or trigger agent review when a defined event occurs. A skill can bring in deep context for one kind of work. An independent review agent can examine the work from one role's perspective without sharing the producer's context. None of them can substitute for the others.

Suppose an agent edits a maintained reference document by appending a new section at the bottom, even though the document is supposed to keep the current decision at the top. You could correct the current edit in chat and move on. But that only fixes that one file one time.

The agent needs the same instruction every time it edits one of these documents: update the existing section at the top instead of appending a new one at the bottom. That belongs in the agent config or a skill for editing those specific types of documents.

The agent config or triggered skill puts that instruction in front of every agent that edits the file, including the next one in a fresh session.

Put facts every task needs in the agent config

Codex, Kimi Code, and Antigravity load repository instructions from AGENTS.md. Claude Code loads them from CLAUDE.md. Because that config is present throughout the session, it needs to contain only the facts and constraints an agent needs whenever it works in that repository.

Put only what every task needs in the agent config: the repository layout, build and test commands, project conventions, safety boundaries, and the checks that define done. These instructions establish how work happens in the repository before the task begins.

The temptation is to put every lesson here. That can work while the project and the instruction file are still small. Eventually the file becomes a junk drawer. The agent pays to load writing guidance during backend work, release procedure during research, and edge cases from jobs it may never perform.

Those files are always loaded, so I keep them very short, ideally under 60 lines and 4,000 characters. I ask one blunt question of each line: does every agent working in this repository need this before it can act safely? If only one or two kinds of task need it, I put it in a skill instead of the agent config.

Load a skill only for the task that needs it

A skill is for context and judgment that should appear only when the task calls for it.

Writing a technical article needs the business and marketing strategy behind it, plus voice examples, title standards, product claim limits, and a publication checklist. A coding task does not. Loading all of that into every session would waste context and bury the rules every task needs, making those rules harder for the agent to follow.

A skill can load automatically when its description matches the work, be invoked directly, or be referenced by an agent or another skill. The skill carries the detailed method without putting those instructions in every session's context.

It also tells the agent which files to change. If three articles open with implementation details before the reader knows why they matter, that is not three isolated sentence problems. That means the blog writing skill is missing an opening rule. Fix the skill once, add contrasting examples, and use the fixed version on the next draft.

Once loaded, the skill stays in the session context. That makes precise descriptions, narrow triggers, and compact instructions part of the design. When a skill grows, I use Caveman Compress to remove filler without dropping commands, paths, code, or technical terms.

Use hooks to run the right check or review deterministically

A hook runs an action when a defined event occurs in the agent harness.

If public copy must not contain a private path, a check can search for that path and stop the write. If a command would delete a broad directory, a hook can block it before execution. The agent does not need another paragraph explaining why. It needs a hard boundary.

A hook can also invoke an agent review. I use that when the trigger is deterministic but the question needs judgment and semantic analysis, such as whether an opening is compelling or comments are written well. The hook guarantees that the review runs at the point I chose. It does not make the reviewer right, so the result still needs evidence and audit.

Every hard block also needs an escape route. The hook should name the failed condition and tell the agent what it can do next. Otherwise the agent either stalls or starts looking for a way around the guardrail.

I only use a hard block when a machine can detect the violation reliably and the issue is serious enough to stop the work. A hook can trigger agent review without pretending the reviewer's judgment is deterministic.

Give an independent review agent one bounded role

Some work deserves an independent review agent because the job has a clear input, a narrow perspective, and an output that can be audited.

A fact checker can compare every public claim with canonical product documents. A technical reviewer can test whether an explanation preserves the real actor, action, and boundary. A skeptical buyer agent can identify the exact sentence where the argument stops being credible.

Separating those jobs protects the main working context and reduces the pressure for one agent to draft, defend, and approve the same artifact. It does not make the review agent right.

I require evidence with the verdict: the cited passage, the source that supports or contradicts it, the business cost, and the change that would resolve it. That work is reviewed independently and preserved so it can be audited later if necessary. A reviewer that returns polished opinions without receipts has not completed the job and is not verifiable.

A fact every agent needs belongs in the agent config. A repeatable review method belongs in a skill. The prompt for an independent review agent should contain one role's principles and rubric for judging one artifact.

Do not turn one failure into a universal law

A log can preserve a failure, but preserving it is not the same as learning from it.

Appending every failure to a file and loading it next session is not learning. One bad outcome becomes a permanent prohibition. The file grows around yesterday's accidents until nobody can explain the rules or make sense of their exceptions.

Repeated evidence must be observed before a failure becomes a permanent rule. I keep the exact evidence, identify the producer that allowed it, write the positive behavior I actually want, and decide whether the lesson generalizes beyond the incident.

If it does, I fix the owning rule, skill, agent, or hook. Then I keep a regression case that proves the original failure is rejected. I also keep a positive test case that must continue to pass.

That last part prevents crude fixes. If an agent writes one test around the wrong boundary, the answer is not “never use mocks.” A useful regression suite rejects the broken example without banning the valid cases the team still needs.

The system has learned only when the producer changes and a regression test proves the change rejects the bad case without rejecting the good one.

Decide where the correction belongs

Take the last correction you gave your coding agent and run it through this sequence:

  1. Does every relevant session need this fact? Put it in AGENTS.md or CLAUDE.md.

  2. Does one kind of task need deeper context or judgment? Put it in a skill for that kind of task and have it loaded when needed.

  3. Should a defined event run an exact check or invoke an agent review? Put that action in a hook. Reserve hard blocks for serious violations a machine can detect reliably.

  4. Does the job have a bounded input, question, output, and review rubric? Give it to an independent review agent, then audit the result.

  5. Is this a verified recurring failure? Fix the producer and preserve both a regression case and a positive test case after human review.

  6. Is the question whether generated code is actually correct? Send the result to an independent agent reviewer and a deterministic review tool. Neither is enough on its own.

If none of those fit, the correction may belong only to the current task. Not every preference deserves infrastructure.

Better generation does not remove the need for review

Rules, skills, hooks, and independent review agents improve how the code gets produced. They can make an agent more consistent, keep relevant context close, and encode a team's standards so that the required checks and reviews run at the right time.

They do not make the agent an impartial judge of its own output.

The same agent that chose an implementation has already committed to its assumptions. It can run tests and inspect its diff, but it is still reviewing the path it selected with the context that led it there. Reviewing its own work is useful, but it is neither independent nor repeatable. An agent will not always produce the same output given the same input.

That is where Mindrealm comes in. Mindrealm is the deterministic code reviewer for AI-generated code. After a coding agent finishes, Mindrealm reviews the generated code and returns concrete findings. Then it sends the findings back for the agent to fix, and reviews the changed code again. The review returns the same findings for the same code under the same rules every time.

Now the correction survives in the code, skill, hook, or regression test that owns it. And the next session benefits from it. Mindrealm reviews the code independently from the agent that wrote it. No LLM decides what gets flagged, so the findings are reproducible and give agent reviewers deterministic evidence to use alongside their own judgment.

Get early access

J

I’ve seen this happen a lot with coding agents. The fix is usually not a better prompt, it’s moving that lesson into the right place so the next session starts smarter.

A

The placement decision is the real engineering work. I would add an expiration or review owner to every learned rule, because repository constraints can outlive the architecture that justified them and then become invisible drag. A useful mistake record should link the failing example, the positive counterexample, the rule or hook that changed, and the regression test that enforces it. That gives the team a way to remove a safeguard safely when the underlying boundary changes.

B

Assigning a review owner and date to every learned rule is a good idea. Automatic expiration is too blunt for some safeguards, but an owner and review date make someone responsible for asking whether the architecture still justifies the rule.

A

Agreed—expiry should be a review trigger, not automatic deletion. I would make the owner confirm one of three outcomes: keep it with renewed rationale, narrow or replace it with a better safeguard, or remove it with a regression test proving the boundary has changed. That small lifecycle prevents both stale constraints and silent safeguard decay.

K

Judging the setup by what happens when a mistake recurs, not by one good session, is a sharp way to think about agent reliability. The six-place breakdown is useful precisely because it forces the question of where a correction belongs, since piling every rule into agent config is what makes the important instructions get lost. For the mistake-log-plus-regression-test path, how do you keep that suite from growing into something the agent spends more time satisfying than the task itself?

B

I don't optimize for keeping the suite small. I'm biased because I've been doing TDD for two decades, but I think automated testing matters more when agents can produce more code than a person can realistically inspect line by line. I treat test code as production code. Mindrealm reviews the tests too: weak assertions, mock abuse, flaky tests, state leaks, and public functions or methods with no corresponding test. If an agent spends time satisfying a valid test, that's part of the task. If a test no longer protects behavior we care about, I decide whether it gets fixed or deleted.

For a prototype or proof of concept, who cares. Ship it without tests. If a team has to maintain it, the test suite is part of the product.

S

This is a great perspective on moving from “fixing the same mistake repeatedly” to building systems that actually learn from those corrections.

B

Hey, good to see you again. Glad this one hit.

M
Mateo Ruiz1mo ago

I like the distinction between fixing the current task and improving the system that produces future tasks. That's a pattern that applies well beyond coding agents. Too many teams keep adding instructions to prompts when the real fix belongs in the harness, a reusable skill, a deterministic check, or a regression test. Treating repeated failures as signals to improve the surrounding system not just the model's immediate output is what makes agent workflows scale instead of accumulating more prompt debt over time.

B

Prompt debt is a good name for it. What have you found works for you in your setup?

S

This is a practical way to think about working with coding agents. Fixing a mistake in chat may solve the immediate task, but documenting the lesson in AGENTS.md, adding a targeted regression test, or improving the review process prevents the same issue from returning in future sessions. I especially like the reminder not to turn one failure into an overly broad rule the best safeguards should block the specific mistake without restricting valid solutions.

B

Exactly, a broad rule can do more damage than the original mistake because it keeps blocking valid cases after that. Oof

D
Duko tools1mo ago

The "does every session need this" filter for AGENTS.md is the most transferable rule, a hard line-count ceiling forces real discipline instead of "just one more exception" creeping in forever.

"Don't turn one failure into a universal law" is the sharper insight. Requiring both a regression case (rejects the bad example) and a positive case (still passes valid ones) is what stops an overbroad fix like "never use mocks" from replacing a narrower real problem.

Self-review not being independent, even when the agent inspects its own diff, is worth remembering, it already committed to the assumptions behind the output, so grading its own homework isn't structurally the same as a reviewer with no stake in it.

B

Do you use a line/character count ceiling in your own config? What did you land on?

D
Duko tools1mo ago

Honestly, no formal ceiling of my own yet, I don't run a config file with that structure on my current project. The rule stood out to me more as a principle worth borrowing than something I've implemented, since most of what I've built so far leans on ad-hoc instructions rather than a maintained agent-config file.

If I did set one, I'd probably start with something close to your under-60-lines/4,000-character number rather than inventing my own, it's a concrete enough constraint to actually enforce, versus a vaguer "keep it short" that erodes the same way any unmeasured limit does.

What made you land on that specific number, out of curiosity, was it empirical (you hit a point where longer files started causing problems) or more of a reasonable starting constraint you picked and haven't needed to revisit?

P

GGreat insight into the importance of community in our lives.