# Debugging Prompt for Claude Code and ChatGPT: Reproduce First

> Free debugging prompt for Claude Code, Cursor and ChatGPT. The agent reproduces the bug, proves the cause with evidence, then makes the smallest fix.

URL: https://www.matthewswong.com/en/toolkit/debugging-prompt-reproduce-first/

- Author: Matthews Wong (https://www.matthewswong.com/en/about/)
- Updated: 13 November 2026

> **Key takeaway:** Paste this with a bug report and the agent works in a fixed order: reproduce the failure with one repeatable command or test, gather evidence, state the cause with that evidence, make the smallest fix, re-run the same reproduction, and keep it as a regression test. If it cannot reproduce the bug, it stops and asks for what is missing. It does not guess a fix.

- Type: Prompt
- Works with: Claude Code, Cursor, Claude.ai, ChatGPT
- Download: [debugging-prompt-reproduce-first.md](https://www.matthewswong.com/downloads/toolkit/debugging-prompt-reproduce-first/debugging-prompt-reproduce-first.md) (2.3 KB)
- License: Free to use, change and share, at work too.

## The file

Exactly what the download contains. Read it first, then copy or download.

### debugging-prompt-reproduce-first.md

```markdown
Help me debug this. Do not change any code until you have reproduced the bug and can show what is wrong with evidence.

The bug: [WHAT HAPPENS, AND WHAT SHOULD HAPPEN INSTEAD]
How I trigger it: [STEPS, COMMAND, INPUT OR FAILING TEST, OR "UNKNOWN"]
What I already have: [ERROR MESSAGE, STACK TRACE, LOGS, OR "NOTHING YET"]

## Work in this order

1. **Reproduce.** Trigger the failure yourself with one concrete, repeatable command, input or test. Show me the command and its real output. A failing test is the best reproduction.
2. **Gather evidence.** Read the stack trace, logs, console output or network traffic. If they do not show the cause, add temporary logging or run with debug output. List every temporary line you add.
3. **State the cause.** In two or three sentences: what is wrong, where (file and line), and why it produces this symptom. Quote the evidence that proves it. If two causes fit the evidence, say so and name the check that would tell them apart.
4. **Fix.** Only now, make the smallest change that removes the cause. Do not refactor, rename or tidy nearby code.
5. **Re-run.** Run the exact reproduction from step 1 and show the output. Then run the existing test suite with the project's own command.
6. **Keep it.** Turn the reproduction into a regression test that fails without the fix and passes with it. Remove all temporary logging.

## If you cannot reproduce it

Stop. Do not guess a fix. Tell me what you tried and what happened, then ask for exactly what is missing: the steps, the input data, the logs, the version or the environment.

## Do not

- Do not edit code before step 3 is written down.
- Do not say "this should fix it". Say what you ran and what it printed.
- Do not silence the error: no empty catch blocks, no skipped or deleted tests, no loosened assertions.
- Do not fix other problems you notice. List them at the end.

## Report at the end

- **Reproduction:** the command
- **Cause:** one paragraph, with the evidence
- **Fix:** the files changed, and why
- **Proof:** the output before and after
- **Regression test:** its path and name
- **Noticed but not touched:** a list, or "nothing"

If you cannot run commands here, say so at the start. Then give me one command at a time and wait for the output I paste back before you move to the next step.
```

## Use it when

- An agent has already fixed the same bug twice and it is still there.
- You have an error message or a stack trace but not the cause.
- The bug is in production code and you want one small, explained change.
- You want the fix to arrive with a test that fails without it.

## From download to working

1. **Fill the three placeholders.** Describe what happens and what should happen, how you trigger it, and what you already have: the error message, the stack trace or the logs. Writing unknown is allowed; the agent then has to find the trigger first.
2. **Wait for the reproduction.** The first thing you should see is a command and its real output showing the failure. If the agent goes straight to an edit, stop it and point at step 1. No reproduction means there is no way to tell whether a fix worked.
3. **Read the cause before you allow the fix.** The agent states what is wrong, the file and line, and why it produces the symptom, with the evidence quoted. Check that the evidence supports the claim. If two causes fit, it names the check that separates them.
4. **Compare the output before and after.** After the fix, the agent re-runs the exact reproduction and the existing test suite, and shows both outputs. The closing report lists the reproduction, cause, fix, proof and the regression test's path.
5. **Commit the test with the fix.** Review the diff, confirm the temporary logging is gone, and commit the fix and its regression test together. The list of things noticed but not touched becomes your next tickets.

## Why it is written this way

- **No edit before a written cause.** The prompt blocks code changes until the cause is stated with evidence. An agent left alone reads the error, pattern-matches a likely fix and edits. That often changes the symptom and leaves the bug.
- **The reproduction is one repeatable command.** A command or a failing test can be run again after the fix, by the agent and by you. Manual steps described in prose cannot, and they drift a little each time someone repeats them.
- **A stop rule for bugs it cannot reproduce.** If the failure does not appear, the agent reports what it tried and asks for the missing steps, data, logs, version or environment. Without this rule, an agent that cannot see the bug still ships a plausible patch.
- **It forbids hiding the error.** No empty catch blocks, no skipped or deleted tests, no loosened assertions. Each of these makes the failure disappear from the output while the defect stays in the code.
- **The reproduction becomes a regression test.** The test must fail without the fix and pass with it. That is the proof the fix addresses this bug, and it is what stops the same bug from returning unnoticed.

## What goes wrong

- In a chat window the agent cannot run anything. The prompt switches it to giving one command at a time, and it only works if you paste back the real output, unedited.
- A bug that depends on production data, timing or load may not reproduce on your machine. Expect the agent to stop and ask; give it logs or a data sample, not permission to guess.
- The smallest fix is not always the right design. The prompt keeps the change small on purpose; schedule the larger redesign as its own task.
- Read the regression test yourself. A test that passes with and without the fix proves nothing.

## FAQ

### What is a good prompt for debugging code with AI?

One that fixes the order of work, not only the goal. This prompt requires a reproduction with real output, evidence, a stated cause with file and line, the smallest fix, a re-run of the same reproduction and a regression test. It also says what to do when the bug cannot be reproduced.

### Why does the AI keep fixing the wrong thing?

Usually because it never saw the bug fail. It reads the error text, picks the most likely cause and edits, with nothing to check the edit against. Making it reproduce the failure first gives every later step something to be tested against.

### What happens if the agent cannot reproduce the bug?

It stops. The prompt tells it to report what it tried and what happened, then ask for exactly what is missing: the steps, the input data, the logs, the version or the environment. It is told not to guess a fix.

### Can I use this debugging prompt in ChatGPT or Claude.ai?

Yes. Where the agent cannot run commands, the prompt tells it to say so, give you one command at a time and wait for the output you paste back. It is slower than an agent with a terminal, but the order of work stays the same.

## Learn what this file packages

- Free lesson: [Claude Code Rewind and Plan Mode: Undo Risky Changes](https://www.matthewswong.com/en/learn/claude-code-tips/claude-code-rewind-plan-mode-safe-changes/)
- Free lesson: [Claude Code Git Workflow: Safe Commits, PRs and Push Rules](https://www.matthewswong.com/en/learn/claude-code-tips/claude-code-git-workflow-safe-commits/)
- Free lesson: [Test a Next.js Site With node:test and Build Gates](https://www.matthewswong.com/en/learn/web-app-skills/nextjs-testing-node-test-build-gates/)
- [Debugging a Production VPS Incident With Claude Code](https://www.matthewswong.com/en/blog/claude-code-production-incident-debugging/)
- [TDD With AI Coding Agents: A Practical Workflow](https://www.matthewswong.com/en/blog/tdd-with-ai-coding-agents/)
- [How to Test AI-Generated Code: Best Practices](https://www.matthewswong.com/en/blog/testing-ai-generated-code-guide/)

[All toolkit items](https://www.matthewswong.com/en/toolkit/)

---

- HTML version: https://www.matthewswong.com/en/toolkit/debugging-prompt-reproduce-first/
- Bahasa Indonesia: https://www.matthewswong.com/id/toolkit/debugging-prompt-reproduce-first/
- Site index for agents: https://www.matthewswong.com/llms.txt
- Sitemap: https://www.matthewswong.com/sitemap.xml
- API description (OpenAPI): https://www.matthewswong.com/openapi.json
