There's a pattern I see all the time. Someone builds an app with Cursor or ChatGPT. It mostly works but has a few bugs. They ask the AI to fix the bugs. It introduces new bugs. They ask it to fix those. Repeat until the codebase is a tangled mess that neither the AI nor the developer understands anymore.
If you're in this loop right now, here's how to break out of it.
Why AI Fixes Often Make Things Worse
AI coding tools don't have memory of your full project context the way a developer does. When you paste in a bug and ask for a fix, the AI is working with a narrow window. It might fix the symptom but break something else because it doesn't see the bigger picture.
It also tends to over-engineer fixes. You have a simple null check issue and the AI rewrites your entire component with three new abstractions. Now you have more code to debug, not less.
The fundamental problem: AI is great at writing new code. It's mediocre at debugging existing code, especially code it wrote in a previous session without the same context.
Strategy 1: Stop Asking the AI to Fix the AI
This is the most important mindset shift. After two failed fix attempts with the same AI tool, switch approaches entirely.
Instead, try:
- Read the code yourself. Even if you're not a developer, you can often trace the logic. Follow the data from where it enters the app to where it breaks.
- Add console.log statements. Put
console.log('checkpoint 1', variableName)at key points in the code. Run the app and check the console. You'll see exactly where things go wrong. - Use a different AI. If ChatGPT wrote the code, try pasting the bug into Claude. If Cursor wrote it, try Copilot. Different models catch different things.
Strategy 2: Undo Until It Works
If you're using Git, this is easy. Run git log --oneline to see your recent commits, find the last one where the app worked, and check it out. Then compare what changed.
If you're not using Git, start using it today. Even just running git init and committing before every major change gives you an undo button that will save you hours.
# See your recent history
git log --oneline
# Go back to a working state
git checkout abc1234
# Compare what changed
git diff abc1234 HEAD
Tip: Before asking the AI for any change, commit your current working state. That way you can always go back.
Strategy 3: Give the AI Better Context
If you're going to keep using AI to debug, at least give it a fighting chance. Most people paste in one file and say "fix this." That's not enough.
Include in your prompt:
- The exact error message (full stack trace, not just the summary)
- What you expected to happen vs. what actually happened
- The relevant files, not just the one with the error. If it's an API issue, include both the frontend call and the backend route.
- What you already tried and why it didn't work
- Your tech stack (Next.js 14, Supabase, TypeScript, etc.)
The more context you give, the better the fix. Think of it like going to a doctor. "It hurts" gets you nothing. "Sharp pain in my lower right abdomen that started after eating, worse when I press on it" gets you a diagnosis.
Strategy 4: Fix One Thing at a Time
When you have multiple bugs, don't try to fix them all in one prompt. Fix one, test it, commit it, then move to the next. This way:
- You can easily revert if a fix breaks something else
- The AI has cleaner context for each fix
- You build confidence by seeing things actually get resolved
Strategy 5: Learn the Patterns
You don't need to become a full developer, but knowing a few common patterns will make you 10x better at working with AI tools.
Learn these concepts and you'll debug 80% of issues yourself:
- Async/await: Most API bugs come from not waiting for data to load before trying to use it
- Null/undefined checks: The code tries to use something that doesn't exist yet
- State management: In React, if the UI isn't updating, you're probably mutating state directly instead of using the setter function
- Environment variables: Different between local and production, and they're the cause of most "it works on my machine" issues
- CORS errors: Your frontend and backend are on different domains and the browser is blocking the request. Fix it on the server, not the client.
When to Call in Backup
Sometimes the codebase is too far gone. If you've been going in circles for more than a day, the cost of your time is already more than what a developer would charge to fix it properly.
Things I commonly see that need professional help:
- Authentication that sort of works but has security holes
- Database queries that are painfully slow
- Payment flows that fail silently
- Apps that work locally but crash in production
- Codebases where every fix creates two new bugs
The goal isn't to be able to fix everything yourself. The goal is to know when to push through and when to hand it off.
Going in circles with AI-generated bugs?
Tell me what's happening. I'll take a look and let you know if it's a quick fix or something bigger.
Email David