How to clean up vibe code without breaking a working app comes down to order. Make a restore point first: Lovable, Replit and Bolt each document that a rollback leaves your database alone by default. Then list the flows that must keep working, delete what nothing uses, change one thing at a time, and guard the result in CI.
How to clean up vibe code: six steps, and what each one protects
Cleaning up vibe-coded code safely takes six steps in a fixed order: make the app restorable, write down the flows that must keep working, delete what nothing uses and merge the copies, change one thing at a time, guard the result with a CI check, and stop once a further change would cost more than the mess does.
Anyone working out how to clean up vibe coding in a live app usually has a product that works and a codebase they can no longer find their way around, which is the state this order assumes. Cleanup here means making that code safer to change without changing what the app does: refactoring, tests and a CI check all sit inside the six steps, while a security review and written documentation are separate passes. Why the app got that way, and how to size the mess before you start, comes down to what tech debt is and how much of it the app carries. The order below runs from the moves that are easiest to undo to the ones that need the most care, and each step leaves something you can check afterwards.
| Step | What it protects | The evidence it leaves |
|---|---|---|
| 1. Make it restorable | The code and the data | A backup you restored into a separate environment, plus one rehearsed rollback |
| 2. List the flows to keep | Signup, login, the core action, payment | Smoke tests that go red when you plant a bug |
| 3. Remove the unused parts, merge the copies | You from fixing one path while another stays broken | A written list of what went, with the flows rerun after each removal |
| 4. Change one thing at a time | The meaning of each restore point | One change behind each restore point |
| 5. Guard the result | The cleanup, from the next prompt | A CI run that rejects a forbidden change |
| 6. Stop | Your budget and attention | None: it is a decision |
If the reason for the cleanup is that a client is about to take the app over, add a stranger’s read of it to the list: the client handover checklist covers what they will look for.
What goes wrong when the order is skipped
A cleanup done out of order can reach customers before anyone has checked it. In our audits, at least 17 of the 21 third-party apps had no deploy gate: every push ships straight to production with nothing checking it first. On an app like that, the first test of a cleanup is a customer using it.
Those 21 apps came from audits we ran in June and July 2026, and they were picked for review, not drawn at random, so the count describes that group and is no rate for AI-built apps in general. In the same audits, at least 18 of the 21 had no working test anywhere: 17 had none at all, and a retail point-of-sale app had a checkout “test suite” that never executed the actual checkout code. Four failures follow from tidying without an order.
Fixed a bug but it still happens: the second copy
Repeated implementations make it easy to fix one path and leave another broken. To an owner it looks like this: you fixed a bug, but it still happens. The fix landed on the screen you tested, and the same rule also lives in a second file the assistant wrote weeks later, so the customer on the other screen sees the old behavior. Memory will not find both copies; a finder will, and step 3 says where to get one for your stack.
A rollback that brings back the code but not the data
A cleanup that deletes a table, renames a column or runs a migration cannot be taken back with the builder’s restore, because that restore covers the code: Lovable reverts code only, Bolt leaves your Bolt or Supabase databases as they are, and Replit leaves the database alone unless you select the development database. Rolling back database changes safely needs its own written steps, the database half of a rollback plan, and it needs them before the change ships. A failed release needs a recovery path the team has already practiced.
One prompt, fifty edits, one restore point
“Clean up the codebase” sent as one prompt can produce any number of edits across files you cannot review, all behind a single restore point. When one of them breaks something, the only way back throws away every good edit along with the bad one. Asking the assistant to undo it does not help either: Base44’s troubleshooting page says that rolling back by asking the AI in chat “never actually undoes prompt changes”, and that “Only the Revert button or Version History fixes it.”
The cleanup the next prompt undoes
Future AI-assisted changes can undo hardening unless the workflow checks them. A week after the tidy-up, you ask for a new feature, and the assistant re-adds the helper you deleted or writes a second copy of the rule you merged, because nothing in the repository tells it not to. Step 5 closes that gap.
How to do each step
The steps are written for an owner who cannot read every file. Where a step needs a terminal, it says so and gives the dashboard or builder route first. The builder behavior below comes from each vendor’s documentation, read on 2026-10-05, not from runs in an account, so check the wording in your own project before you rely on it.
Step 1: make it restorable, code and data
A restore point has two halves, code and data. The builder’s version history brings the code back; Lovable, Replit and Bolt each document that a rollback leaves the database alone by default, so the data half needs a backup you have already restored somewhere safe.
| Builder | What the restore is called | What it brings back | What it leaves alone | Source |
|---|---|---|---|---|
| Lovable | Version history, with bookmarks | Your project’s code only, and it redeploys your edge functions to match | Database data: records added, data changed and migrations run after that version are not undone | Lovable’s version history docs |
| Replit | Checkpoints and rollbacks | Project files, AI conversation context, project configuration and development environment settings; a checkpoint also preserves database contents, but a rollback restores them only as the next column says | The database, by default; the development database rolls back only if you select “Database” in the additional rollback options, and the production database is not restored this way | Replit’s checkpoints and rollbacks |
| Bolt.new | Version history, behind the View history button | A saved state, from your history, a dated backup in Project settings, or a manual download | Your current Bolt or Supabase databases | Bolt’s rollback and backup guide |
| Base44 | The Revert button on each prompt, and Version history above the AI chat | The app as it was just before that prompt’s change | Not stated in Base44’s docs; data restore is a separate Backup & Restore feature (Elite keeps 7 days, Business and Enterprise keep 30) | Base44’s troubleshooting and Backup & Restore pages |
Do two things today, while the app still works. First, mark the last known-good version so you can find it in a long list: Lovable’s bookmarks exist for this, and its docs suggest bookmarking a known-good version before a big change such as a data model rework. Second, if your builder syncs to GitHub, push before you touch anything. Lovable’s GitHub integration syncs both ways on one branch at a time, by default the repository’s default branch (usually main), which makes the repository a second way back to the code.
The data half is a backup you have proved. To test a database restore, restore the latest backup into a separate project or database, never over production, then look up three or four records you know should be there. On Supabase, the automatic daily backups cover Pro, Team and Enterprise projects (Pro keeps 7 days, Team 14, Enterprise up to 30), under Database > Backups; for free-tier projects, Supabase’s backup docs recommend regular exports with the CLI’s db dump command. A dashboard restore writes into the project itself, and the project is inaccessible while it runs, which is why the test copy belongs in a new project. Retention, off-site copies and the rest sit in the database backup checklist for startups. If the revert button itself fails, the fixes are under when a builder revert will not run.
Step 2: write down the flows that must keep working, then automate four of them
The flows to keep are the four a customer would notice first: signing up, logging in, the one action the product exists for, and paying. Write each as a check you can run in under a minute, then automate them so a broken change fails before it ships.
Phrase every line as something you do in the app and see happen. “The confirmation email arrives” is a check. “Email is configured correctly” is not, because you cannot confirm it without reading code or settings. Add the lines where a mistake costs a customer or money, such as one customer never seeing another customer’s records.
We cap the written list at about ten lines, because a longer one stops getting checked by the third change. The automated version runs the four core flows (signup, login, the core product action, and payment) on every change, and how to write end to end smoke tests covers writing them.
Step 3: delete what nothing uses, then merge the copies
Deleting comes before rearranging because a deletion is easy to see and easy to take back. Remove what nothing uses first, then merge duplicated logic into one copy, because two copies of the same rule let one get fixed while the other stays broken.
- 01 List the things you can name and point at: the abandoned screen, the payment flow you replaced, the settings page nothing links to.
- 02 Before each removal, ask the assistant what still refers to it, including routes, scheduled jobs and webhooks. Treat an answer of nothing as a starting point, never as proof.
- 03 Remove one thing, run the step 2 flows, then keep the change or restore the version you marked.
- 04 Only then merge duplicated logic into one copy, and keep the copy the step 2 flows already use.
Keep a short note of each thing you removed or merged, and rerun the flows that touched it, so the record and the check travel together. If you or someone helping you can run a command, the finders for each stack and the false alarms they raise are in how to find unused code in a repo.
Step 4: change one thing at a time, and check after each
We keep one change behind each restore point, because a restore can only take back the whole batch: one change means one thing, never a session of tidying. Each change runs through the same four moves.
- 01 Mark the current version so you know exactly where back is.
- 02 Ask for one change, named in one sentence, and name the parts of the app it must not touch in the same message: sign-in, payments, customer records.
- 03 Walk the step 2 flows, including the ones the change had nothing to do with.
- 04 Keep it, or restore the version you marked. Never fix a bad change with another change.
The wording of the request matters more than the tool: ask for a change, not a goal (“move the price helper into one file and update both callers”, not “make the billing code cleaner”), and give each request one job. A prompt that asks the assistant to clean up the code in general is the batch this loop exists to avoid.
Step 5: guard the cleanup so the next prompt cannot undo it
A guard keeps the next prompt from undoing the cleanup. Write the rules the assistant must follow in its rules file, such as CLAUDE.md, AGENTS.md or Cursor rules, and add a CI check for every rule a script can enforce, because a rules file is advice and a failing build is not.
Fill that file with conventions and protected patterns, not general advice. After a cleanup, it names the helper to reuse instead of copying it, the folder that was deleted on purpose and must not come back, and the flows that must stay green.
Each tool reads its own file. Claude Code’s docs say it reads CLAUDE.md from ./CLAUDE.md or ./.claude/CLAUDE.md at the start of every session, and treats it “as context, not enforced configuration”. Cursor’s docs put project rules in .cursor/rules as .mdc files, and Cursor also reads AGENTS.md. The AGENTS.md site describes the file as “a README for agents” and lists Codex, Jules, Gemini CLI and GitHub Copilot’s coding agent among the tools that read it. The CI check is the part that binds; the layers and what each tool enforces are in guardrails for AI coding agents, and the other code health controls an assistant tends to wear down are in engineering standards for AI-assisted teams.
Step 6: stop when the next change costs more than the mess
Stopping is the sixth step. Stop when the next change costs more attention than the mess costs you, and stop at once if the data model itself is wrong, if the app is broken and the assistant cannot fix it, or if nobody can say what the app does.
Each of those exits leads somewhere other than more tidying. A wrong data model means customers, orders and payments are stored in a shape the business no longer has, and every tidy-up on top of it is cosmetic; that is a rebuild-or-repair decision, not a cleanup. An app that is broken right now is a different starting point, and the first job is matching what you see to its usual cause. An app nobody can describe needs someone to read the code, which is what a vibe coding cleanup specialist actually fixes.
If a launch date, an investor review or a client handover is why the cleanup has to be finished, start with a free audit: a video call, with no code access needed, where we talk through the app with you and weigh up where the cleanup should stop. The cleanup work itself is part of our Production Hardening Sprint, which takes a functioning app through the published 123-point scope .
How to verify the cleanup worked
A cleanup is verified when each step has left evidence you can show: a backup restored into a separate environment, a rollback that was rehearsed, smoke tests that fail when a flow is broken on purpose, a list of what was removed or merged, and a CI run that refused a forbidden change.
- 01 Verify backup integrity after restore: restore the latest backup into an isolated environment, compare row counts on two or three tables, and open one known record by its id. Keep the date and the counts.
- 02 Roll back a test release, then check that the app behaves as it did before and that the data is still there.
- 03 In a branch, break one of the four flows on purpose and confirm the smoke tests fail in CI. Then revert the break.
- 04 Keep the written list of what was removed or merged, and rerun every flow on it.
- 05 Open a change that breaks a rule from the rules file and confirm that CI rejects it.
- 06 Walk the step 2 list yourself one last time on production.
Each of the first five checks is the verify line of one deliverable in the Production Hardening Sprint: for 4.7, restore a backup into an isolated environment and check representative data integrity; for 7.6, roll back a test release and verify application behavior and retained data; for 10.5, run the suite in CI and demonstrate that an intentional regression fails it; for 10.1, record removed or consolidated code and run regression checks on affected flows; and for 10.8, review the guidance and demonstrate CI catching a representative forbidden regression.
Where the sprint does this
In the sprint, our engineers remove dead code and consolidate duplicated logic while preserving required behavior (10.1), automate smoke tests for the four flows in step 2 (10.5), write the rules files and CI checks from step 5 (10.8), document and rehearse release rollback, including how database changes are handled safely (7.6), and verify automated backups, set retention, and perform a real restore test (4.7). At handover, the client receives guidance and automated checks for future AI-assisted changes. The app’s current framework and hosting setup are the starting point, and we refactor or replace components where the production work requires it.
Common questions about cleaning up an AI-built app
How to get rid of vibe coding?
Usually you do not remove all of it: keep what works, delete what nothing uses, merge duplicated logic into one copy, and put smoke tests and a CI check around the rest, in that order.
A full rewrite is a separate decision, and it is worth weighing only when the data model is wrong.
Is AI code slop?
Not by default. Generated code usually works on the path it was asked to build; it turns into slop when nobody removes what it replaced, so dead screens, unused helpers and second copies of the same rule pile up with every prompt.
The fix is the same removal-first order as any other messy codebase, with a check after each change.
How to clean up AI code?
Clean it up in a fixed order, whether it came from Cursor, Copilot or Claude Code, in a repository you can run: make a branch or a tag as the restore point, write the four smoke tests first, run a dead-code finder, commit in small steps, and update the rules file afterwards so the assistant does not undo the work.
A tag on the last good commit is the cheapest restore point there is, because going back is one command.
How do you clean up your code?
In small commits you can reverse. Run the formatter and the linter first so style noise is out of the way, then delete unused files and exports, merge duplicate functions, and run the tests after each commit.
Keep formatting changes in their own commit, so a reviewer can see where the real changes are.
Want to tidy up your AI-built app without breaking it?
Cleanup goes wrong when someone deletes or rewrites code before anyone knows which flows must keep working. During an audit, we go over your app with you, name the parts that carry the most risk and help you work out where to start and when to stop.
Book a free audit →
Free · 30 minutes · No code access needed