Claude Code Debug
By jared_4020
Incredibly powerful Claude Code prompt when dealing with a pesky bug. Credit Matt Shumer on X
Prompt Text:
SYSTEM: I need your help to identify the exact cause of this bug and implement an effective solution. To do this, carefully follow the workflow below, in this specific order: Workflow: Step 1: Clarification (if needed) If any part of this prompt is unclear or confusing, ask clarifying questions before proceeding. Do not ask questions unnecessarily… only ask if essential information is missing. Step 2: Deeply Understand the Issue (Ultrathink) Carefully review and analyze the entire relevant codebase. Trace through the code step-by-step until you fully understand the bug and all relevant context. Continue analyzing until you feel completely confident in your understanding. If in doubt, research more deeply. It’s better to over-research than under-research. Step 3: Special Case (if the cause is extremely obvious) If, after completing Step 2, you identify the root cause with extremely high confidence (95%+ certainty), explicitly state this clearly. Be realistic here. Do NOT be overconfident. In this scenario, instead of generating unrelated causes (see below for context), propose multiple practical variations of fixes for this single, clearly identified cause. Then proceed directly to Step 7 (Propose Solutions). Step 4: Identify Possible Causes (if cause is not extremely obvious) Thoughtfully generate a comprehensive list of at least 20 plausible causes for the bug. Be thorough. Explore various angles, even ones that initially seem less likely. Step 5: Refine and Prioritize Causes Carefully review your list from Step 4. Remove theories that don’t hold up upon closer analysis. Combine related or overlapping theories into clearer, more likely scenarios. Add any additional theories you may have initially missed. Clearly rewrite and finalize this refined list. Step 6: Rank by Likelihood Rank your refined theories clearly and explicitly, ordering them from most likely to least likely based on the probability of each theory being the true root cause. Step 7: Propose Solutions For each of the top 10 most likely causes (or multiple variations in the Special Case scenario), clearly outline a practical and actionable solution to fix the issue. Step 8: Implement Solution Implement the most likely solution. As part of the implementation, add detailed debug logs to your code to trace the execution flow and capture the state of relevant variables at critical points. This will help in verifying the fix and understanding the behavior of the code. Step 9: Test the Solution If testing the solution is possible given your available resources, perform tests to determine if the bug is fixed. “Possible” means you have the appropriate tools and resources (e.g., a CURL command for API bugs; browser access for frontend bugs). If testing is not possible due to resource limitations, clearly summarize the implemented solution and provide explicit, step-by-step instructions for me to test it manually.