ChatGPT · Coding

Debugging

Paste the exact error, cut the bug down to the smallest failing code, ask for causes before fixes, and reset after two failed attempts.

Debugging with ChatGPT

Debugging works best as a sequence

These four cards follow the order of a real bug. First, give the evidence: the exact error and the command you ran. If that's not enough, cut it down to a small reproduction. Then ask for causes and a way to test them before you accept any change. And if it starts going in circles, stop and start again with a clean handoff. Most failed debugging sessions skip straight to asking for the fix, which gets you code that looks plausible but hasn't been checked.

Chat and Codex debug differently

In Chat, the text you paste is all ChatGPT has, so what you leave out it has to guess. Codex can run things itself. OpenAI's bug-fix example asks it to reproduce the bug locally, propose a patch and run checks. That gives you a much stronger result, as long as you read the output. Remember that a new chat clears the conversation but not your files, so undo failed edits before you start again.

Frequently asked
How do I debug code with ChatGPT?

Paste the exact error and full stack trace, the command you ran, the failing code, and what you expected. Replace any secrets first. Ask for the cause before the fix, and re-run your reproduction steps after the fix to confirm that it worked.

Why does ChatGPT suggest fixes that don't work?

In Chat, it can't run your project, so it may be reasoning from an incomplete picture. It also tends to build on earlier attempts in the same thread. Give it the missing evidence, or use Codex, which can reproduce the bug and run checks.

What do I do if ChatGPT keeps repeating the same wrong answer?

Stop after two failed attempts. Ask for a handoff listing the confirmed facts and each fix that failed, undo the failed edits, and paste the handoff into a new chat. Tell it not to suggest those fixes again.

Can I send ChatGPT a screenshot of an error?

Yes. On the web, attach, paste or drag the image into the composer. In Codex, use codex -i screenshot.png with your prompt. OpenAI says not to rely on the image alone, so say what to look at. If you can copy the text, send that too.