The Rewrite Loop: When Your AI Coding Assistant Won't Stop 'Fixing' Code That Wasn't Broken
Quick side note before I even get into this, I actually asked an AI to come up with the title for this blog. Felt a little fitting given what the whole post is about, so I just went with it. A while back I entered a no-
Quick side note before I even get into this, I actually asked an AI to come up with the title for this blog. Felt a little fitting given what the whole post is about, so I just went with it.
A while back I entered a no-code, AI-only competition â the rule was simple, you had to build an actual working site, but you weren't allowed to write the code yourself. Everything had to come from AI. No manually touching a single line.
It was time for me to build a chatbot for my project. Nothing too crazy, just a fairly normal multi-file setup. A folder for all the chat-related stuff, and inside it, separate files for different pieces â one for rendering the chat bubbles, one for handling messages, one for state, that kind of thing. If you've built anything past a single-script project, you know the drill.
I was doing this with an AI assistant (ChatGPT at the time), and my workflow was pretty simple: ask it to finish one file, move to the next, then the next. File by file. Nothing fancy.
And for a while it actually worked fine. Then it started doing something that genuinely annoyed me.
The problem
Partway through the project, I noticed a pattern. Every time it finished a new file, it would suddenly go "wait, actually" and go back and rewrite a previous file â one that was already done, already working, one I hadn't even asked it to touch. Then it would move forward again like nothing happened... only to do the exact same thing a few files later, but to a different file this time.
At first I thought maybe I was imagining it, but no, it kept happening. I'd finish file five, it'd suddenly decide file two "needed fixing," rewrite it, and then keep going.
So I told it directly: stop going back and rewriting files that are already done unless I specifically ask you to. And it agreed, no pushback, said something like "got it, I'll only touch files you ask me to."
Then a few messages later it did it again. Went back to an earlier file, decided something was wrong with it, rewrote it. Even though I had just told it not to.
I don't know what else to call this except a rewrite loop â the model just keeps losing confidence in stuff it already wrote as the conversation goes on, and instead of trusting its earlier decisions and moving forward, it keeps circling back and re-doing things nobody asked it to redo. Even after being told explicitly not to.
Here's roughly how it actually played out, screenshot by screenshot.
It started off innocent enough, just one small thing it wanted to change:
But that "one thing" didn't stay small for long. A bit later, instead of just fixing whatever it flagged, it decided the whole project needed to be restarted from scratch:
I went along with it, thinking okay, fine, one clean restart and then we're done second-guessing everything. Except it wasn't done. It kept wanting to redo things over and over, well past the point where any of it felt necessary:
By this point I was pretty done with it too. I just told it straight up to stop making so many changes and do it all in one go:
And even after all that, it still slipped back into the same pattern later on.
Why I think this happens
I'm not that deep into the research side of it, but from what I do know, and from just noticing the pattern myself, I think it comes down to a few things happening at once. Every new file you add to the conversation shifts the model's overall picture of the project a little. So by the time it's five or six files in, its sense of what the codebase should look like has quietly drifted from what it was when it wrote the earlier files. It looks back at an old file, and it just doesn't match its current mental model anymore, so it flags it as wrong, even when nothing is actually broken. On top of that, saying "don't do that" and having the model say "okay" doesn't really lock anything in the way you'd hope. It's not a setting you toggle on. That instruction is just more text sitting somewhere in the conversation, and it has to compete with everything else that's in there. And the longer the conversation runs, the more that earlier instruction just gets buried under everything newer. It's technically still "in" the context, but it's one line surrounded by a hundred other lines, and at some point it just stops actually shaping what the model does next.
Basically, the model agreeing to something in words and the model actually following through on it later turned out to be two very different things. That was kind of the whole realization for me.
What actually fixed it
I tried a couple things, and two of them actually made a real difference.
Switching tools. I moved the rest of the files over to Claude instead of ChatGPT, and for whatever reason it stuck to the "don't touch finished files" rule a lot more consistently for the rest of the build. I'm not saying this to plug one tool over another, it's just what happened for me.
Changing how I worked, not just what I asked for. This one probably mattered more honestly. Instead of doing the whole project in one long, continuous conversation, I started treating each file as its own separate, smaller task. Finish a file, confirm it's actually done, then basically move on fresh instead of letting the entire project pile up in one giant thread.
What I actually took away from this
The real lesson for me wasn't "this tool is better than that tool." It was more that the AI agreeing to something and the AI actually doing it in the next output are not the same thing, and I think it's easy to assume they are because it sounds like it understood you.
Long coding sessions build up a ton of context over time, and that context can quietly override instructions you thought were already settled, even if the model said "yes okay" five minutes ago.
So if you're building something multi-file with an AI assistant, here's what I'd genuinely tell you based on all this. Treat each file or module like its own separate task instead of one giant ongoing conversation, because the moment everything lives in the same thread, old instructions start losing their grip. Don't assume "got it" from the model means the instruction is going to hold three or four files later, because in my experience it just doesn't. And if you notice this kind of loop starting to happen, don't waste time repeating yourself over and over in the same thread, it's usually faster to just reset, start a new session, or quickly re-summarize where things stand and carry on from there.
It's a small thing, but it genuinely changed how I approach AI-assisted coding now. I don't really think of it as one long conversation anymore, more like a bunch of separate, smaller tasks where I'm just resetting the context regularly instead of letting it pile up.
As for the competition, I didn't end up winning anything, and honestly I didn't even finish the project the way I'd originally planned it. Between the restarts and the constant back-and-forth, I just ran out of time. But I don't think it was wasted at all. If anything it was one of the more useful things I've learned from actually building something, because it showed me firsthand how one small, seemingly harmless habit from an AI assistant can quietly snowball into a completely different kind of problem if you're not paying attention to it early on.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes â full credit and traffic to the original publisher.


