Stop prompting after the third failed try on the same error. To fix AI-generated code the tool keeps failing on, collect what it has not been given: the exact error text, the last version that worked, what changed since, and what the logs recorded. A bug that survives three prompts is usually missing evidence, not missing wording.

How to fix AI-generated code when the AI tool cannot

AI-generated code that the tool cannot fix needs evidence before another attempt: the exact error, a reliable way to reproduce it, the last working version and the logs from the moment it failed. With those, a person or the tool can find where the failure starts instead of guessing.

The habits that keep an AI-assisted codebase workable over months belong to engineering standards for AI-assisted work. This page covers the narrower moment: the app is broken for real users, and the tool says it is fixed.

We’d stop at the third attempt for a plain reason. An AI coding tool answers what it is told and what it can see. When the third try returns the same failure, the missing piece is information the tool does not have, and the tenth prompt walks into the same gap in different words. AI-generated code here means the code an AI tool wrote from your instructions, the code behind the app that broke. If what broke is a site’s front end, fixing AI-generated website code is the same job and needs the same evidence.

Before anyone, person or tool, tries again, write down these five things:

  1. 01 The exact error text, copied, not paraphrased.
  2. 02 The steps that make it happen every time.
  3. 03 The last version that worked, and the date of it.
  4. 04 What changed between that version and now.
  5. 05 What the logs or the error tracker recorded at that moment.

Each item closes a gap the tool would otherwise fill with a guess. An app that still works and has only grown messy needs a different set of steps, the ones for cleaning up an app that still works.

Five failures that need evidence, not another prompt

These five are our own grouping of why a prompt stops working, in the order an owner can usually check them.

FailureWhat you seeEvidence that settles itControl that stops it coming back
The fix is written but never wired inThe tool reports success; the changed file is never called, so nothing on screen movesThe diff, plus one click through the broken pathA smoke test on that path
Nothing recorded what happenedThe error is gone by the time anyone looksNone exists yet; it has to be captured the next timeError tracking
The green check proves nothingThe build passes and the feature still failsA test that runs the feature itselfSmoke tests on the core paths
The failure is not in the codeA missing setting, an expired key, a provider limit or bad dataThe environment settings and the provider’s dashboardNone in the code; check the settings first
Each fix moves the breakFixing one place breaks anotherThe history of changesA rules file, plus a CI check that fails when a change breaks a rule

We audited 21 third-party apps in June and July 2026, and 17 of the 21 had no error tracking or alerting: when a user hits an error, nothing records it. Those apps were chosen for review, not drawn at random, so the count describes that group rather than AI-built apps at large. In the same audits, at least 18 of the 21 had no working test anywhere: 17 with literally none, plus a retail POS whose checkout “test suite” never executed the actual checkout code.

If your failure sits in row 2, 4 or 5, or nobody on the team can read the logs and the diff, that is the point to hand it to someone, and a free audit is where we talk through what broke, and what changed just before it, with you. In the Production Hardening Sprint, deliverable 10.5 automates smoke tests for signup, login, the core product action, and payment flows; 6.3 installs error tracking such as Sentry with protected source maps, environment labels, and alerts; and 10.8 provides CLAUDE.md, AGENTS.md, Cursor rules, or equivalents describing conventions and protected patterns, with CI checks for enforceable rules.

The first failure is the quickest to rule out. A tool can edit a file, describe the edit and report success while no code path ever reaches the new lines, so one click through the broken path after each claimed fix settles it. The fourth sits outside the code entirely: a key that expired, a setting that exists in preview but not in production, or a provider limit returns the same error however often the code is rewritten.

What to do in the next hour

Work through these in order. None of them needs you to read code.

  1. 01 Stop the AI tool from making further edits to the app.
  2. 02 Put users back on the last version that worked, if your builder or host can roll back.
  3. 03 Write down the evidence list from the first section.
  4. 04 Check settings, keys and provider dashboards before touching the code.
  5. 05 Put the failure into one sentence a person can test: which account, which page, what happens.
  6. 06 Hand that sentence and the evidence to whoever fixes it, person or tool.

The first step protects the evidence. Every extra edit on a broken app stacks new changes on top of the original break, and the diff that would have shown the cause gets harder to read with each one.

The fifth step is the easiest to skip. A vague report such as a broken checkout cannot be tested. A precise one can: a new customer who pays by card sees a blank page after the payment step, every time. Whoever picks up the work starts from that sentence instead of rediscovering it.

When a single change caused the break, getting back to the version before the AI edit has its own steps. Each builder’s loop differs too, so the Lovable fix loop, a Replit app that keeps breaking and a Base44 app that will not load each start somewhere else. Matching what you see to a likely cause, and what to have ready before anyone helps, is set out under getting a vibe-coded app fixed.

AI code fix tools: what they repair and what they cannot see

AI code fix tools repair what they are shown: a pasted snippet or a scanner’s finding in the repository. Neither a paste box nor a scanner sees the running app, its settings or its data, so these tools suit a known bug in a known file, not a failure nobody has located.

Kind of toolWhat you give itWhat it can fixWhat it cannot see
Paste-box code fixers, such as OneCompiler’s Code FixerThe code and its programming language; an error message is optionalBugs and errors in the pasted code; it returns corrected code with an explanationAnything not pasted into the box, such as the rest of the app, its settings and its data
Scanner-driven fixes, such as Sonar’s AI CodeFixCode that SonarQube Server or SonarQube Cloud has already analyzedA select set of the bugs, vulnerabilities and quality issues the analysis found; security hotspots are flagged for human review rather than automatic changesAnything its static analysis did not flag
The AI coding tool itself: Cursor, Claude Code, GitHub Copilot or the builder’s agentYour prompt and the repositoryAny change you can describeLogs, settings and data it was never given or connected to

A paste-box tool is the quickest code fix when you already know which function is wrong. OneCompiler’s Code Fixer asks for the code and its language, takes the error message as an option, and returns corrected code with an explanation of what was wrong. Without the error message or the expected behavior, a paste box has less to work from, and the tool’s own tips ask for the full error or stack trace and for expected versus actual behavior. Whether there is a free code fixer available depends on the tool: OneCompiler’s pricing page lists a Free plan, “Free forever”, with 50 credits a day, and its Code Fixer page states no price of its own.

Sonar’s AI CodeFix starts from the other end. It suggests code fixes for issues found by SonarQube Server and SonarQube Cloud, and delivers them in IDEs, pull requests and CI/CD pipeline checks. That kind of AI code repair works on what the scanner flagged; an expired key or a missing production setting is nothing static analysis of the code can point at.

The AI coding tool you already use can fix AI code across the whole repository, but it sees only what you give it or connect. For a live failure, that means handing it the evidence list rather than a fresh description of the symptom.

Our verdict on all three: each works best when you already know where the bug is, and most of the five failures above are not that. Having a person read AI code before it ships, with evidence that it is safe, is a separate job: checking AI-written code before it ships. Bots that comment on every pull request have their own comparison, AI code review tools compared.

After the fix: how to keep it fixed

A fix stays fixed when a test fails the moment the bug returns, an error tracker records the next failure with its context, and a rules file tells the AI tool which parts it must not touch. Without those three, the next prompt can undo the fix unnoticed.

Each check below is one you can run and watch fail. The failure is the evidence you keep.

  1. 01 Put the bug back on a branch and confirm the smoke test on that path fails in CI; keep the failed run.
  2. 02 Send a test error from the app itself and confirm the tracker shows a stack trace pointing at your own code and the right environment label; keep the event.
  3. 03 Mark the fixed part as protected in the rules file, make a change that breaks the rule, and confirm a CI check fails; keep the failed check.

For the second check, Sentry’s JavaScript setup guide suggests a button that throws an error when clicked, and warns that errors triggered from your browser’s developer tools are sandboxed and will not trigger its error monitoring. Sentry’s docs on issues describe an issue as similar events grouped by a fingerprint; on the issue details page, the Stack Trace section shows the line of code that the event errored on. The environment label comes from the environment option passed to Sentry.init.

The smallest suite that catches a broken signup, login or payment is laid out in smoke tests for signup, login and payments. Making production errors point at real lines of your code is covered in stack traces you can actually read, and the rules file with its CI check in guardrails an AI coding agent cannot skip.

In the Production Hardening Sprint, deliverable 10.5 is verified this way: run the suite in CI and demonstrate that an intentional regression fails it. Deliverable 10.8 is verified by reviewing the guidance and demonstrating CI catching a representative forbidden regression.

Common questions about fixing code an AI wrote

How to fix AI code?

We’d stop prompting once the same error has survived three tries, then collect the evidence: the exact error, the steps that reproduce it, the last version that worked and what the logs recorded. Check settings and provider dashboards before the code, then make one fix with that evidence in hand and confirm it on the path that broke.

Is there an AI that can help me fix my code?

Yes, for a known bug in a known file. Paste-box fixers such as OneCompiler’s Code Fixer take a snippet and an optional error and return corrected code, and Sonar’s AI CodeFix suggests fixes for issues its static analysis found. A failure nobody has located yet needs evidence from the running app before any tool can help.

What to do if your code is not working?

Get users back on the last version that worked if you can, then write down the exact error and the steps that cause it. Check what changed since that version and what the logs say, then change one thing at a time and test the broken path after each change.

Is AI generated code any good?

It is as good as whatever checks it. Code nobody tested tends to work until a user takes a path nobody tried, which is why a smoke test on signup, login and the core action matters more than who or what wrote the code.

Can you help me fix my code?

Yes: a person who can read the code and see the failure can usually fix what the AI tool could not, once the error, the steps and the logs are in hand. AxonBuild runs a free audit, where we talk through the failure and what it needs with you.