Problem
Why your AI coding agent keeps bringing back bugs you already fixed
TL;DR
- Agents start each session without knowing why a strange line of code exists.
- "Cleaning up" that line brings the old bug back.
- Write the decision down where every agent reads it, and lock the fix with a test.
You fixed a race condition last month with a small delay and a comment. Today an agent removed both, because the code "looked unnecessary". The bug is back, and nobody remembers why the fix was there.
Why it happens
- Every session starts fresh. The agent sees code, not history. A defensive check looks like dead weight.
- Comments get ignored or rewritten. "Don't remove this" in a comment is easy to tidy away along with the code.
- The decision lives in someone's head, a closed PR or a Slack thread the agent never sees.
Give your agents a memory
1. Log the decision where agents read it
stet decide "Keep the 50ms retry delay in the sync worker" \
--why "Without it, two workers race and duplicate invoices (bug from Oct)"
Stet adds it to the decision log and to AGENTS.md and CLAUDE.md, so Claude Code, Cursor and Codex see it at the start of every session.
2. Lock the fix with the test that proves it
stet lock add "No duplicate invoices under concurrent sync" \
--cmd "npm test -- tests/sync/concurrency" --protect "src/sync/worker.ts"
If an agent removes the fix, stet check fails and stet guard flags the protected file, with the decision right there to explain why.
3. Write the test the moment you fix the bug
Every fixed bug is a behaviour worth locking. It takes a minute and it's the cheapest insurance you'll ever buy.
A habit that compounds
After a few weeks, your decision log becomes the answer to "why is it like this?" for agents and new teammates alike. stet handoff turns it into an onboarding pack.
FAQ
Why does Claude Code undo my previous fixes?
It does not know why the fix exists. Without a recorded decision and a test that proves the fix, the code looks unnecessary and gets simplified away.
How do I give an AI coding agent memory across sessions?
Keep decisions in a file every agent reads at the start of a session, such as AGENTS.md or CLAUDE.md, and keep it current. Stet's stet decide writes decisions there automatically.
Are code comments enough to stop agents removing fixes?
Not reliably. Comments are easy to rewrite along with the code. Pair the decision with a test and a protected path so removal is flagged.
Put guardrails on your AI coding agent
Stet is a free, open-source CLI and MCP server for Claude Code, Cursor, Codex and Copilot. It runs locally: no account, your code never leaves your machine.
npx stet-cli init · Install · Setup guide · GitHub