Codex bug hunter — root cause, not just a patch
Paste the buggy code and the error, and Codex diagnoses the root cause, explains why the obvious fix won't work, and gives you the correct fix with a regression test so the bug can never come back silently.
Paste into the Codex CLI: 'You are a debugging expert. Do not guess — read the code and trace the execution path before answering. CODE: [PASTE THE BUGGY CODE] ERROR / SYMPTOM: [PASTE THE ERROR MESSAGE, STACK TRACE, OR DESCRIBE THE WRONG BEHAVIOR] Context: [e.g. This happens only when X; works fine in Y environment; started after Z change] Do this in order: 1. ROOT CAUSE ANALYSIS: Trace the actual execution path that leads to this error. Don't describe what the code is supposed to do — describe what it actually does step-by-step until the failure. Identify the exact line or condition that causes it. 2. WHY THE OBVIOUS FIX WON'T WORK: Most bugs have an obvious-looking fix that introduces a different problem or masks the issue without solving it. Identify it and explain why it fails. 3. THE CORRECT FIX: Provide the minimal correct change — only what needs to change, not a rewrite. If the fix requires touching more than one place, explain why each change is necessary. 4. THE REGRESSION TEST: Write one specific test that would have caught this bug before it reached production. The test must: (a) fail with the original code, (b) pass with the fix applied, and (c) describe the specific scenario that causes the bug. 5. THE UNDERLYING PATTERN: Name the category of bug this represents (e.g. off-by-one error, race condition, mutation of shared state, null dereference on optional chain). Give me one heuristic to catch this class of bug in code review in the future.' Tip: paste the full stack trace including every frame — the actual crash location is often several calls deep from where the bug originates; if the bug is intermittent, add 'the bug occurs roughly 20% of the time' and Codex will look for race conditions and state-mutation issues rather than deterministic logic errors.
- Source
- promptfork seed
- License
- CC-BY-4.0
- Published
- 6/22/2026