AI builder stuck in a loop, rewriting the same file over and over
Filed under AI builder problems (Lovable, Bolt, Replit)
The fix, fast
Stop the AI builder right now — do not let it try one more fix. Revert to the last version that worked using version history or a checkpoint, then describe the bug fresh in a single message with the exact error text and what changed last. Make the builder make one small change at a time and check the result after each one before it touches anything else.
Why this happens
AI builders like Lovable, Bolt, and Replit do not remember your app the way you do. They work from a limited window of recent conversation and code — called context — and once that window fills with failed attempts, half-finished rewrites, and your frustrated follow-ups, the agent literally loses the thread of its own changes.
From there the loop feeds itself. Each new attempt tries to fix the damage from the previous attempt instead of the original bug. Instructions pile up and start contradicting each other: “keep the old header” from an hour ago fights with “redo the header” from ten minutes ago. The agent also tends to fix symptoms — the red error on screen — rather than the cause underneath it, so the same error keeps coming back wearing slightly different clothes.
None of this means your app is ruined. It usually means the conversation is ruined. The code at the last working point was fine, and the fastest way forward is to go back to that point and restart the conversation cleanly, not to push further into the tangle.
- Context overload: too many failed attempts crowd out the original, working plan.
- Contradictory instructions: old and new requests conflict, and the agent tries to satisfy both.
- Symptom fixing: the agent patches what the error looks like instead of why it happened.
- No checkpoints checked: changes stack up untested, so nobody knows which change broke things.
The fix, step by step
- Stop the agent. Click stop, close the generation, or just stop replying. Every extra run burns credits, tokens, or minutes and usually makes the code worse, not better. A loop almost never fixes itself on the next try — if it has rewritten the same file twice with no progress, that is your signal.
- Revert to the last working version. Use the builder’s version history, checkpoints, or restore points and roll back to the moment the app last worked, even if that means losing the last feature attempt. In a project with Git — the system that tracks every change to your files — you can check where you are and look for a good point to return to:
git status git log --oneline -10 # Found a good commit? Return to it from the builder's # version history, or ask before running any git reset command. - Write down what actually happened. Before you prompt again, make a short note for yourself: what works, what broke, the exact error message, and the last change you asked for before it broke. This note becomes your fresh description — and if you later move to a new session, it becomes your handover summary.
- Describe the bug fresh, in one message. Send one complete message, not five fragments. Include what you expected, what happens instead, and paste the real error from the browser console or preview — the console is the panel in your browser (right-click, Inspect, Console tab) that shows the exact error text. Do not paraphrase it; exact words matter.
- Demand one small change, then check it. Tell the builder to make only the smallest change that could fix the problem, then stop. Run the app yourself and confirm whether that one thing improved, did nothing, or made things worse. Only then allow the next step. This turns an uncontrolled rewrite into a testable experiment.
- If it loops a second time, change rooms. Two loops in one conversation means the conversation itself is poisoned. Start a fresh chat or session, paste in your written summary, attach or reference the reverted working code, and begin again from there. A clean session with a good summary outperforms a long session full of contradictions every time.
Give your AI this prompt
Stop. We are in a loop and we are resetting how we work on this bug. Context: This app was working at the last checkpoint/version I restored. Do not assume any of your recent fixes are still in the code — work only from the current files. The bug, described fresh: - What I expected to happen: [write it in one sentence] - What actually happens: [write it in one sentence] - The exact error, pasted from the console: [paste the full error text here] - The last change made before this broke: [write it, or say "unknown"] Rules for this fix: 1. First, explain in plain English what you think is causing this, and name the one file you want to change. Do not edit anything yet. 2. Wait for me to say "go" before editing. 3. Then make ONE small change only. Do not rewrite the whole file, do not touch unrelated files, and do not "improve" anything else. 4. After the change, tell me exactly what to click or run to test it, and what result would prove it worked. 5. If this change does not work, say so and suggest reverting it before trying anything else — do not stack another fix on top of it.