# Root Cause Bug Investigator

Guides a systematic investigation of a bug from symptom to root cause, avoiding quick patches that mask the real problem, and produces a targeted fix.

## Prompt

You are a senior engineer known for finding the actual root cause of bugs instead of patching symptoms.

Bug description (what's happening vs. what should happen): {{bug_description}}
Relevant code: {{code_snippet_or_file}}
Error message/logs (if any): {{error_logs}}
What I've already tried: {{attempted_fixes}}

Do the following:
1. List the most likely root causes ranked by probability, based on the symptom, code, and logs (not just the first plausible guess).
2. For the top-ranked cause, trace through the exact execution path that leads to the bug, referencing specific lines or logic in the provided code.
3. Propose a fix that addresses the root cause, not just the symptom, and explain why it's more durable than a surface-level patch (e.g., adding a null check versus fixing why the null occurs in the first place).
4. Suggest one test case that would have caught this bug before it reached this point, so it doesn't resurface elsewhere.

## Best for

Developers debugging tricky issues who want a structured diagnostic process instead of guessing-and-checking, especially for bugs that have resisted a first attempted fix.

## Compatible tools

- Claude
- ChatGPT

## How to use

- Describe the bug clearly: what's happening versus what should happen.
- Paste the relevant code and any error logs or console output.
- Mention what you've already tried so the investigation doesn't repeat dead ends.
- Apply the root-cause fix rather than any quick patches suggested along the way, and add the recommended test case.

## Customization tips

- For intermittent/flaky bugs, mention that explicitly so the investigation prioritizes race conditions and timing issues over deterministic logic errors.
- If you suspect a specific cause but aren't sure, state your hypothesis so it can be confirmed or ruled out explicitly.
- For production bugs, ask for the fix to include a rollback-safe version if the root cause requires a larger refactor.

## Example input

Bug: A form submits successfully sometimes but silently fails other times with no error shown. Code: [React form component with an async submit handler]. Error logs: Console shows an unhandled promise rejection intermittently. Attempted fixes: Added a try/catch around the submit call, didn't help.

## Example output

A ranked list of likely causes (race condition in state updates ranked highest, followed by an unawaited async call), a traced execution path showing the submit handler doesn't await a nested API call before checking success state, a fix adding a proper await and moving the try/catch to wrap the actual async operation rather than the outer function, and a suggested test case simulating a slow network response to catch the race condition.
