Diagnose
A discipline for hard bugs and regressions. Skip phases only when explicitly justified. All questions and findings reported to the user must be in Portuguese (pt-BR).
When exploring the codebase, use the project's domain glossary from .claude/CONTEXT.md to get a clear mental model of the relevant modules, and check docs/architecture/ for decisions in the area you are touching.
Re-validation loop: after every hypothesis, fix, or change, re-run the reproduction and the regression checks before declaring the bug resolved.
Phase 1 — Build a feedback loop
This is the skill. Everything else is mechanical. If you have a fast, deterministic, agent-runnable pass/fail signal for the bug, you will find the cause — bisection, hypothesis-testing, and instrumentation all just consume that signal. If you do not have one, no amount of staring at code will save you.
Spend disproportionate effort here. Be aggressive. Be creative. Refuse to give up.
Ways to construct one — try them in roughly this order
- Failing test at whatever seam reaches the bug — unit, integration, e2e.
- Curl / HTTP script against a running dev server.
- CLI invocation with a fixture input, diffing stdout against a known-good snapshot.
- Headless browser script (Playwright / Puppeteer) — drives the UI, asserts on DOM/console/network.
- Replay a captured trace. Save a real network request / payload / event log to disk; replay it through the code path in isolation.
- Throwaway harness. Spin up a minimised version of the problem in a new project, then debug that.
Ask the user in Portuguese when you need more data:
Preciso de um exemplo minimo que reproduza o erro. Voce consegue me fornecer:
1. O comando ou acao que dispara o problema.
2. A saida ou mensagem de erro exata.
3. O ambiente (local, CI, staging, producao).
➡️ Se nao tiver, vou tentar construir um caso de reproducao sozinho.
Phase 2 — Minimise the problem
This is the skill. If you cannot reproduce the bug in isolation, you cannot fix it. If you cannot minimise the problem, you cannot reproduce it. If you cannot reproduce it, you cannot fix it.
Ways to minimise — try them in roughly this order
- Remove code until the bug disappears. Add it back in small chunks to find the culprit.
- Remove data until the bug disappears. Add it back in small chunks to find the culprit.
- Remove configuration until the bug disappears. Add it back in small chunks to find the culprit.
- Remove dependencies until the bug disappears. Add them back in small chunks to find the culprit.
- Remove environment until the bug disappears. Add it back in small chunks to find the culprit.
Phase 3 — Hypothesise
This is the skill. If you cannot explain the bug, you cannot fix it.
Ways to hypothesise — try them in roughly this order
- Check the obvious. Is the bug in the code you are looking at? Is it in the code you are calling? Is it in the code calling you?
- Check the documentation. Is the bug in the docs you are looking at? Is it in the docs you are calling?
- Check the logs. Are the logs telling the truth? Are they masking the real error?
- Check the tests. Is the bug in the tests you are running? Are they covering the real path?
- Check the codebase. Are there other call sites with the same pattern?
Report the hypothesis to the user in Portuguese:
Hipotese atual: [DESCRICAO_DA_HIPOTESE].
Vou validar com [ACAO_EXPERIMENTAL]. Se confirmar, o proximo passo e [PROXIMO_PASSO].
Concorda ou quer que eu teste outra hipotese primeiro?
Phase 4 — Instrument
This is the skill. If you cannot see the bug, you cannot fix it.
Ways to instrument — try them in roughly this order
- Add logs around the suspect seam.
- Add metrics to measure the suspect behaviour.
- Add traces to follow the request path.
- Add assertions to fail fast on invariants.
- Add tests that reproduce the bug before the fix.
Phase 5 — Fix
Do the smallest, safest change that removes the root cause. Avoid band-aids. If the fix touches many files, present the plan to the user in Portuguese before editing.
Raiz do problema: [RAIZ].
Correcao proposta: [DESCRICAO_DA_CORRECAO].
Arquivos afetados: [LISTA].
Posso aplicar a correcao e depois rodar os testes?
Phase 6 — Regression-test and re-validate
This is the skill. If you cannot verify the fix, you cannot call it done.
Required checks
- Reproduction fails before the fix, passes after.
- Add a regression test for the fixed bug.
- Run the affected test layer (unit, integration, E2E).
- Run a lightweight regression on neighbouring flows.
- Remove or revert instrumentation that is no longer needed.
Report the result in Portuguese:
Correcao aplicada em [ARQUIVOS].
- Teste de reproducao: [PASS/FAIL]
- Testes de regressao: [PASS/FAIL]
- Testes afetados: [PASS/FAIL]
O bug esta resolvido. Quer que eu abra uma Issue para documentar a causa raiz com /create-issues?
Re-Validation Loop
Diagnosis is iterative. After every change, re-run the reproduction. If the bug moves or changes, go back to Phase 3. Do not declare the bug fixed until the reproduction passes and the regression suite is green.
Common Mistakes
| Mistake | Fix |
|---|---|
| Fixing without a reproduction first | Build a reproduction before changing code. |
| Skipping minimisation | Minimise first, or you fix symptoms, not the cause. |
| Removing instrumentation too early | Keep it until the fix is verified. |
| Not adding a regression test | Every fixed bug deserves a test. |
| Declaring done without re-validation | Re-run the reproduction and the suite. |
References
qa-analyst— for test planning and bug reportinggrill-me-with-spec— for producing specs when the bug reveals missing requirementsimprove-codebase-architecture— when the diagnosis reveals structural seams that need deepening