What this prompt does
This prompt forces Claude Code to debug the way a senior engineer does: methodically, not by pattern-matching the first plausible cause. It works because the template front-loads the model with the exact context a real debugger needs — severity, framework, the symptom, the trigger_condition, concrete steps, and the raw error_message — then locks the response into five ordered steps: read the stack trace, find the root cause, check connected components, propose a coded fix, and write a regression test.
The ordering is the leverage. By demanding root cause before a fix (step 2 before step 4), it stops the model from slapping a try/catch on the symptom. Step 3 — checking related components — is what catches the second bug hiding behind the first: the stale cache, the missing index, the race the original trace only hinted at. And step 5 turns the fix into something permanent, because a bug without a failing test is a bug you'll ship again.
When to use it
- A production exception with a stack trace you can paste, but no obvious culprit in the top frame.
- Intermittent or "works on my machine" bugs where the
trigger_conditionmatters more than the code. - Errors that surface far from their cause — a null deep in a service, a 500 from a swallowed upstream failure.
- Cross-layer issues: controller to service to model to DB, or frontend state to API to cache.
- Inherited or unfamiliar code where you need the connected-component scan to map blast radius.
- Any fix you intend to merge, because step 5 hands you the regression test to lock it down.
Example output
1. Stack trace: Error "Attempt to read property 'tier' on null"
at OrderService.php:88 — $order->customer->tier.
2. Root cause: guest checkouts have customer_id = NULL; tier is read
unconditionally. Symptom (the null-property error) ≠ cause (a
nullable relation treated as always-present).
3. Related: PricingController and the invoice mailer hit the same
getter — both crash on guest orders too.
4. Fix:
$tier = $order->customer?->tier ?? Tier::GUEST;
5. Regression test:
test_guest_order_prices_without_customer() — assert no exception,
GUEST tier applied.
Pro tips
- Make
error_messagethe full trace, not the one-line summary. The frames below the top are where root cause usually lives — truncating them is the most common reason the answer stays shallow. - Be precise in
trigger_condition. "After deploy, only for guest users" narrows the search far more than "sometimes." Intermittent bugs are won or lost here. - Set
severityhonestly — "production data corruption" vs "console warning" changes how aggressively the model weighs a hotfix against a clean fix. - Pin
frameworkto a version (Laravel 11, React 18). Lifecycle and API behavior differ enough that a generic answer can be wrong for your stack. - Pair it with the model's file access: after it names a root cause, ask it to open the connected components from step 3 and confirm the hypothesis against the actual code before you apply the fix.