How to Keep Your AI Coding Agent on Track (and Stop It Undoing Fixes)
How to stop your AI agent forgetting decisions, breaking things it already fixed and drifting off task, and how to check its fixes work.
Josh Bradford3 min read
AI coding agents bring back bugs you already fixed, drift away from what you agreed on, and sometimes say a bug is fixed when nothing changed.
Most of that comes from memory. The agent starts every session blank, so the rules and the checking have to come from you.
Write decisions down where the agent will read them#
Anything decided in chat is gone next session. Keep a decisions file in your project and point your agent's context file at it.
Markdown## Decisions
- Enemies respawn only when the player leaves the room. Do not change.
- Retry logic: 3 attempts, 2s apart. Tested, do not refactor.
- Save format is v2. Never change field names.
## Not doing
- No multiplayer.
- No inventory weight system.
The "Not doing" list matters as much as the decisions. It's how you stop the agent from steering the project somewhere you didn't want.
Protect what already works with tests#
The most reliable way to stop an agent from undoing a fix is a test that fails when the fix breaks.
- When a bug gets fixed, ask the agent to write a test that reproduces it first, then fix it so the test passes.
- Tell it to run all tests before it says it's done.
- A "don't change this" comment is easy for the agent to ignore. A failing test makes it deal with the regression.
Even a few tests on the stuff that keeps breaking helps a lot.
Make it prove the fix#
Don't take "fixed" at face value. Ask for evidence:
- "Run it and show me the output."
- "Show me the test that failed before and passes now."
- "Explain what caused the bug, then show me the change."
If it can't explain the cause, it probably guessed. And an agent reading back its own code doesn't count as verifying the fix.
Keep tasks small and specific#
Big vague tasks are where drift happens. "Clean up the code" gives the agent permission to change anything, including the parts you just got working. Compare:
- Vague: "Refactor the networking code."
- Specific: "Move the request helpers from
net.jsintonet/requests.js. Don't change behavior. Run the tests after."
Saying what not to change is as important as saying what to change.
Use git like a save point#
Commit every time something works. Then:
- Read the diff before accepting a change. If it touched files that had nothing to do with the task, that's your warning sign.
- If a session goes sideways, roll back to the last commit instead of asking the agent to fix its fix. That second fix is where things usually get worse.
Start fresh when it gets confused#
Long sessions get worse over time. The agent is juggling too much and starts mixing things up. When it starts contradicting itself or repeating mistakes, stop, write down where things stand, and start a new session with that summary.
A simple routine that works#
- Start a session with one specific task.
- Agent reads the context and decisions files.
- Agent writes a short plan. You approve or fix it.
- Agent makes the change, writes or updates a test, runs everything.
- You read the diff and check it yourself.
- Commit.
- Update the decisions file if anything new was decided.
It adds a couple of minutes per task. That's still faster than fixing the same regressions over and over.
Comments
Loading comments