DEV Community

Daniel Imaino
Daniel Imaino

Posted on Originally published at repomemory.dev Fully Autonomous

How to stop AI coding agents repeating reverted changes

AI coding agents repeat reverted changes because the reason for the revert isn't anywhere they look. The code shows only what is there now, not what was tried and taken out. To stop it, write the reason down as a lesson where every agent checks before a change, and tell agents to check. With RepoMemory, that means a record_entry when the change is reverted, a recall before the next change, and three lines in AGENTS.md or CLAUDE.md.

Why it happens

Say someone added a captcha to checkout in March, and completed orders fell 5%, so it was reverted. In October someone asks an agent to "stop bots on checkout". The agent sees a checkout with no captcha and adds one. The lesson is still around, but the agent doesn't see it:

  • the revert commit says "Revert 'Add captcha'", with no reason;
  • the reason is in a PR comment, a Slack thread or someone's head;
  • a "don't add a captcha" line in CLAUDE.md might be there, but a file that collects every such story stops being followed once it's long.

Record the lesson when you revert

The agent that does the revert, or you, records what happened and what to do instead:

curl -s https://api.repomemory.dev/v1/record \
  -H "X-API-Key: $REPOMEMORY_KEY" -H "Content-Type: application/json" \
  -d '{"project":"acme/shop","kind":"lesson",
       "title":"Captcha on checkout cut completed orders 5%",
       "body":"Shipped a captcha on the checkout page in March and reverted it after two weeks: completed orders fell 5%. Bots only spike on release days.",
       "tags":["checkout","captcha"],"agent":"claude-code"}'
Enter fullscreen mode Exit fullscreen mode

Put the words someone would use for the change in the title and tags ("captcha", "checkout"). Recall matches words, so a title in the change's own words is what makes it findable.

Recall before the next change

Before planning, the agent searches with words about the change:

curl -s https://api.repomemory.dev/v1/recall \
  -H "X-API-Key: $REPOMEMORY_KEY" -H "Content-Type: application/json" \
  -d '{"project":"acme/shop","query":"add a captcha to checkout"}'
Enter fullscreen mode Exit fullscreen mode

The lesson comes back, and the agent can propose rate limiting on release days instead. Recall is free and unmetered on every plan, so agents can do it before every change.

Make it automatic

Agents use the same operations as MCP tools. Connect the server (the docs cover Claude Code, Cursor, Codex, VS Code and Claude.ai) and add this to AGENTS.md or CLAUDE.md:

## Project memory (RepoMemory, project "acme/shop")
- At the start of a session, call `brief` for the project: it returns every guardrail, the open tasks and the latest decisions. Never break a guardrail.
- Before planning a change, removing code that looks unneeded or retrying an approach, call `recall` with words about the change. Follow what it returns.
- When a change is reverted, a fix took real digging, or you choose one approach over another, call `record_entry` (kind lesson or decision) saying what happened, why, and what to do instead, with your name in `agent`.
Enter fullscreen mode Exit fullscreen mode

"Removing code that looks unneeded" is in there on purpose: agents also undo fixes by tidying away a line that looks pointless. A lesson recorded when the line was added stops that too.

For rules that must never be broken

If a lesson has become a rule, record it as a guardrail instead. brief returns every active guardrail at the start of each session, whatever the agent is about to do, so the rule doesn't depend on a search matching it.

When the lesson stops being true

If bots are later blocked at the CDN and a captcha is no longer the question, retire the lesson with a reason, or record a new decision with supersedes set to its id. Recall then leaves the old one out, and an agent won't refuse a change the team has agreed to.

Try it

The free plan has 300 new entries a month and needs no card. Create a key on the API keys page, then run npx @plexsicity/repomemory init in the repository.


First published on repomemory.dev. I build RepoMemory, so weigh my take on it accordingly.

Top comments (0)