{"slug": "make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first", "title": "Make Claude Code prove its fix: turn any bug report into a failing test first", "summary": "A developer published a reusable Claude Code prompt that forces the coding agent to convert any bug report into a failing test before patching code, requiring the agent to show the failure output, apply a minimal fix, and report the test name, before/after results, and a one-line root cause. In a worked example, a cart discount bug produced a test failing at $60 actual versus $80 expected, confirming the coupon was applied twice; a minimal fix in the recalculation path turned it green and the regression test remained in the suite.", "body_md": "The most dangerous sentence in AI-assisted coding is \"this should fix it.\"\n\nThe agent patches something, the code compiles, everyone moves on — and the bug comes back two weeks later wearing a different hat. The fix was never proven. It was just plausible.\n\nHere is the prompt I now paste before any bug fix in Claude Code. It forces test-first discipline on the agent:\n\nTurn this bug report into a failing test first: [BUG_REPORT]. The test must fail for the reported reason — show me the failure output. Then fix the code minimally until it passes, and run the surrounding suite ([TEST_COMMAND]). Report: test name, the failure before, the pass after, and the one-line root cause.\n\n**\"Failing test first\"** — the agent has to reproduce the bug in code before it is allowed to touch the fix. No reproduction, no patch.\n\n**\"Must fail for the reported reason\"** — tests can fail for the wrong reason (bad setup, wrong import). This line makes the agent check that the red test is actually *your* bug.\n\n**\"Show me the failure output\"** — proof, not a summary. You see the red with your own eyes.\n\n**\"Fix minimally until it passes\"** — minimal is doing real work in that sentence. It stops the agent from \"improving\" three unrelated files on the way.\n\n**\"Report: failure before, pass after, one-line root cause\"** — the fix arrives with its own evidence attached, and the root cause has to fit in one line. If it can't, the agent doesn't understand it yet.\n\nBug report: \"discount shows twice in the cart.\"\n\nThe new test fails with total $60 actual vs. $80 expected — the coupon is applied twice. A minimal fix in the recalculation path turns it green, and the surrounding suite passes. The fix arrives with proof: red, then green. And the regression test stays in the suite, so this bug can never silently return.\n\nThat last part is the real compounding effect: every bug fixed this way leaves a test behind. Your suite grows out of real failures, not imagined ones.\n\nReproduce first. Demand the failure output. Fix minimally. Require the proof. It works for debugging, for reviews, for refactors — anywhere an agent might otherwise hand you confidence instead of evidence.\n\nThis prompt is one of 12 in my Debugging & Review Mini-Pack (root-cause analysis, git bisect walkthroughs, flaky-test autopsies, security-first review, and more), each with fill-in variables and a worked example:\n\nContent first, pitch second — but if the prompt above saves you one 3 A.M. debugging session, the packs will pay for themselves.", "url": "https://wpnews.pro/news/make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first", "canonical_source": "https://dev.to/minoru-iwasaki/make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first-1pbf", "published_at": "2026-11-24 03:08:10+00:00", "updated_at": "2026-11-24 03:12:44.281006+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["Claude Code", "Anthropic"], "also_reported_by": [], "takeaway": "Requiring a coding agent to write a failing test that reproduces the reported bug, show the failure output, and fix minimally before reporting a one-line root cause turns plausible patches into proven fixes and leaves a regression test behind.", "recommendation": {"advice": "Before letting a coding agent patch a bug, prompt it to write a failing test that reproduces the reported reason, show the failure output, fix minimally, and report the before/after results and root cause.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first", "markdown": "https://wpnews.pro/news/make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first.md", "text": "https://wpnews.pro/news/make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first.txt", "jsonld": "https://wpnews.pro/news/make-claude-code-prove-its-fix-turn-any-bug-report-into-a-failing-test-first.jsonld"}}