Debuly

Guide · Coding

How to debug code faster with AI: a step-by-step guide

Find and fix bugs with an AI assistant: how to share errors and stack traces, steps, six tools compared on pricing and limits, and mistakes to avoid.

By the end of this guide you will have taken a real bug, from an error message or a wrong result to a verified fix, with an AI assistant doing the legwork of reading the code, proposing causes and drafting the change. The job is done by an AI coding assistant, either a chat window you paste code into or an assistant that lives in your editor or terminal and can see your project.

If you want to debug code with AI, the key choice is how much of your project the assistant can see. This guide shows a repeatable method and compares six tools from our Coding category.

Key takeaways

  • Give the assistant a minimal reproduction, the exact error text or stack trace, and the relevant code, then ask for causes before asking for a fix.
  • The main decision is context: a general chat assistant, an editor assistant, a terminal agent, or a tool that searches your whole codebase.
  • Free plans exist but have caps. For example, GitHub Copilot's free plan is capped at 2,000 inline suggestions a month, and Cursor's free plan has limited agent and chat requests.
  • Never apply a fix you do not understand. Reproduce the bug, add a test, and review the change yourself before it ships.

What you need before you start

  • A bug you can trigger. Know the steps that make it fail, and write them down.
  • The exact error. Copy the full message, stack trace or log lines rather than paraphrasing them.
  • Access to the code. An editor or terminal where the assistant can read the relevant files, or the pieces you are willing to paste into a chat.
  • A way to run the code. You need to run the program or tests yourself to confirm the result.
  • Version control. Work on a branch so every change the assistant makes can be reviewed or reverted.
  • Time. A straightforward bug usually takes under an hour; a deep one takes longer.
  • Difficulty. Easy for chat, moderate for agents that edit files.
  • Data care. Remove secrets, API keys and personal data from anything you paste into a tool.

Which kind of AI tool fits this job

Pick by how much of the project the assistant has to understand to find the cause.

A chat assistant for isolated problems. Claude is a general assistant for chat, writing, analysis and coding on web, desktop and mobile. It suits a stack trace plus a short code excerpt you paste in. Its free plan does not include Claude Code, and usage limits apply on every plan.

An assistant inside your editor. GitHub Copilot answers questions in chat, suggests code as you type and can work as an agent that edits files. Cursor is an AI-first code editor built around an agent that plans and carries out multi-step programming tasks. Both keep the conversation next to the code.

A terminal or IDE agent for larger problems. Claude Code takes a job such as fixing a bug and works through the project while you steer and review. It runs in a terminal, in VS Code and JetBrains extensions, and from GitHub and Slack, with checkpoints and sandboxing for safer edits.

Whole-codebase context. Cody uses Sourcegraph's search to pull relevant APIs, symbols and usage patterns from local and remote repositories into answers. It is sold as part of Sourcegraph Enterprise.

Apps you build with AI. Dyad is an open-source desktop app builder whose agent mode checks build errors, runs tests and debugs from logs, which helps when the bug is in an app you generated.

Step 1: Reproduce the bug and capture the evidence

A reliable reproduction is what separates a good diagnosis from a guess.

  1. Trigger the failure and note the exact steps, inputs and environment.
  2. Copy the full error message and stack trace.
  3. Note what you expected to happen and what happened instead.
  4. Shrink the case if you can, by removing code and inputs that do not affect the failure.

Check it worked by being able to trigger the bug in a few steps, on demand.

Step 2: Choose where to ask

You end this step with the right tool open and the right amount of the code visible to it.

  1. For one function and one error, a chat assistant such as Claude is enough.
  2. For a bug that spans files, use an editor assistant or agent such as Cursor or GitHub Copilot, so it can read the project.
  3. For a large or unfamiliar codebase, consider a terminal agent like Claude Code or a search-backed tool like Cody.
  4. Check the plan limits in the comparison table below before you rely on a free tier for a long session.

Check it worked by asking the tool to summarize what the failing file does, and confirming the summary is correct.

Step 3: Give the assistant the full picture

Good prompts contain the symptom, the evidence and the code.

  1. State the goal in one sentence, such as "this endpoint returns an empty list when the filter is set".
  2. Paste the exact error text or stack trace.
  3. Include the failing function and the code that calls it, or point the tool at the files.
  4. Say what you have already tried, so it does not repeat those ideas.
  5. Ask for likely causes ranked by how well the evidence supports them, not for a fix yet.

Check it worked by reading the reply and finding that it cites your actual line numbers, names or error text.

Step 4: Test the hypotheses one at a time

The aim is to confirm a cause before you change anything.

  1. Take the most likely cause and ask how to prove or disprove it, such as a log line, a breakpoint or a small test.
  2. Add that check yourself and run it.
  3. Paste the result back and ask the assistant to update its diagnosis.
  4. If it keeps suggesting the same thing, give it new evidence rather than asking again.

Check it worked by landing on one cause that your own run supports.

Step 5: Apply a fix and read the diff

Let the assistant draft the change, then review it as you would a colleague's.

  1. Ask for the smallest change that addresses the confirmed cause.
  2. In an agent tool, keep edits on a branch. Claude Code offers checkpoints for safer edits.
  3. Read the whole diff. Look for unrelated changes, deleted checks and swallowed errors.
  4. Ask the assistant to explain anything you do not follow, and do not merge code you cannot explain.

Check it worked by being able to describe the fix and why it works in your own words.

Step 6: Prove the fix and add a regression test

A fix is only done when the original failure cannot return unnoticed.

  1. Re-run your reproduction steps and confirm the failure is gone.
  2. Ask the assistant for a test that fails without the fix and passes with it.
  3. Run the full test suite, not only the new test.
  4. Try nearby inputs and edge cases to make sure you have not moved the bug.

Check it worked by seeing the new test fail on the old code and pass on the new.

Step 7: Record what you learned

A short note saves the next debugging session.

  1. Write a commit message that states the cause, not just the change.
  2. Add the reproduction and the test to the issue or pull request.
  3. If the bug was a pattern, such as a missing null check, ask the assistant where else it might occur, and review what it finds yourself.

Check it worked by having a teammate read the commit message and understand the cause.

Tools for this job compared

Tool Good fit for Pricing Stated limits
Cursor An AI code editor with an agent, plus a CLI Freemium, paid from $8/mo (checked 24 Oct 2026) Free plan has limited agent and chat requests; third-party model usage is billed separately at API list price
GitHub Copilot Chat, completion and agents in VS Code, JetBrains, Visual Studio and the CLI Freemium, paid from $10/mo (checked 23 Oct 2026) Free plan is capped at 2,000 inline suggestions per month; usage beyond included credits requires purchasing more
Claude Pasting errors and code into chat on web, desktop and mobile Freemium, paid from $17/mo (checked 24 Oct 2026) Usage limits on every plan, with a session limit that resets every five hours; free plan excludes Claude Code
Claude Code Terminal, IDE and web agent that works through a project Paid Cloud sessions, the desktop app and Slack need a claude.ai subscription; API usage billed per token
Cody Questions that need context from many repositories Contact sales Supported on Sourcegraph Enterprise; Visual Studio support is experimental
Dyad Debugging apps built with an AI app builder on your desktop Freemium, paid from $20/mo (checked 24 Oct 2026) Free plan's Basic Agent capped at 20 messages per day; web search and image generation need Pro

Prices and plan limits change, so confirm the current terms on each vendor's site before you subscribe.

Common mistakes to avoid

  • Pasting a vague description. "It crashes" gives the assistant nothing to work with, so it guesses. Fix it by pasting the exact error, the stack trace and the code involved.
  • Accepting the first fix. An assistant can produce a change that hides the symptom without removing the cause. Fix it by confirming the cause in Step 4 and testing in Step 6.
  • Sharing secrets. Logs and config files often contain keys, tokens or personal data. Fix it by redacting them first and checking the vendor's data terms for your plan.
  • Letting an agent edit without a safety net. Multi-file edits are hard to unpick. Fix it by working on a branch and reviewing every diff before you commit.
  • Skipping the regression test. Without one, the same bug returns quietly. Fix it by asking for a test that fails without the fix.

How we put this together

This is an evidence-based guide built from each tool's listing in our directory, which is compiled from the vendor's own site and pricing page. It is not a review based on using the tools. We don't rank tools, and nobody paid to be included. Some outbound links may be affiliate links; see our disclosure.

Frequently asked questions

Is there a free way to debug code with AI?

Yes, with caps. GitHub Copilot has a free plan limited to 2,000 inline suggestions per month, Cursor has a free tier with limited agent and chat requests, Claude has a free plan with usage limits, and Dyad's core app is free with a capped Basic Agent. Heavier sessions usually need a paid plan.

Can AI find the cause of a bug on its own?

It can often propose likely causes from an error message and the code, but it can be wrong. Treat its answer as a hypothesis, test it by running the code, and confirm the fix with a test before you rely on it.

Which tool is good for debugging in the terminal?

Claude Code runs in a terminal and also in VS Code and JetBrains extensions. Cursor and GitHub Copilot both list a command-line tool as well. Check each vendor's site for the current setup.

Is it safe to paste my code into an AI tool?

Check first. Policies differ by vendor and plan, and your employer may restrict what you share. Remove secrets and personal data, and read the data terms for the plan you use.

How long does debugging with AI take?

It depends on the bug, and the vendors do not publish typical times. Reproducing the problem, checking the fix and writing a test usually take longer than the suggestion itself.

Compare more options in our Coding category. If your fix needs a safety net, see how to write unit tests with AI.

Related guides

Related categories