Turns a bug report into a fix contract backed by evidence - reproduces the bug on the product as a user would (a tools.e2e item, or the public interface the report names), finds the root cause in the code, and writes a one-part fix Change under .bdk/runs (issue.md with the proposal, the reproduction as an acceptance scenario and the root cause as a key decision, created on the tracker when the report is not an issue; plan/parts/01.md) plus debug/diagnosis.md. Writes no Change when the bug doe...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Diagnose Bug?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/broneq-diagnose-bug)
---
name: diagnose-bug
description: 'Turns a bug report into a fix contract backed by evidence - reproduces the bug on the product as a user would (a tools.e2e item, or the public interface the report names), finds the root cause in the code, and writes a one-part fix Change under .bdk/runs (issue.md with the proposal, the reproduction as an acceptance scenario and the root cause as a key decision, created on the tracker when the report is not an issue; plan/parts/01.md) plus debug/diagnosis.md. Writes no Change when the bug does not reproduce, and no plan part when the fix is too large for one. Never edits code or tests. Use when asked to diagnose, reproduce or find the cause of a bug, to prepare a fix without making it, or when /bdk:debug reaches the diagnosis.'
argument-hint: "[<bug report> | <issue>] [--name <change>]"
allowed-tools: Bash(${CLAUDE_PLUGIN_ROOT}/bin/bdk *) Bash(git status *) Bash(mkdir -p *) Bash(cd *) Bash(curl *) Read Write Edit Glob Grep AskUserQuestion
---
Current BDK configuration of this project:
!`"${CLAUDE_PLUGIN_ROOT}/bin/bdk" config show`
Arguments: $ARGUMENTS
# Diagnose a bug
Reproduce the reported bug on the product first, then find why it happens, then write the fix as a one-part Change that `/bdk:execute` can build test-first. You write only the fix Change and its files under `.bdk/runs/<change>/`: never code, tests, docs or another Change. Run `bdk` always as `"${CLAUDE_PLUGIN_ROOT}/bin/bdk"`, each command on its own, without `;`, `&&` or pipes. Read and search with Read, Glob and Grep.
When the block above says `BDK not configured: run /bdk:setup` or `BDK configuration invalid`, write nothing, reply with that line and stop. If it shows the command instead of its output, run `"${CLAUDE_PLUGIN_ROOT}/bin/bdk" config show` first.
## 1. Read the report
- An issue reference (`#42`, `42`, an issue URL): name the Change first (below), then `"${CLAUDE_PLUGIN_ROOT}/bin/bdk" tracker fetch <ref> --run <change>`, and read the report from `.bdk/runs/<change>/issue.md`. When it fails, quote the error and stop. With `tracker.kind` other than `github`, read the issue as `tracker.instructions` say.
- Any other text: the report as the user wrote it.
- The report must hold a symptom you can observe: what the user did and what went wrong. Without one, ask for it (`AskUserQuestion` when available, else in your reply) and write nothing until it comes.
Name the Change: `--name <change>` or a name the user gives; else `fix-<slug>` (two to four kebab-case words of the symptom), from an issue `<number>-fix-<slug>`. When `.bdk/runs/<change>/issue.md` exists before your fetch, stop and name it: it is another fix in progress. `C` is `.bdk/runs/<change>/`, the run directory `R` is `C/debug/`; run `mkdir -p` for it.
Done when you hold the symptom (input, action, expected, observed as reported) and the Change name.
## 2. Reproduce as a user
Before you read the code for a cause, make the bug happen on the product.
1. Pick the way in. A `tools.e2e` item of the configuration whose `driver` reaches the symptom (`cli` for a command, `http` for a request, `browser` for a page): start it with its `env` and `start`, wait for `ready` (a URL: `curl -sS -o /dev/null -w '%{http_code}\n' --retry 30 --retry-delay 2 --retry-connrefused <url>`; a command: run it until it exits 0), drive the steps of the report, and stop what you started (`TaskStop`) when done. Without an item, use the closest public interface the report names: the command a user runs, or the exported function called from a one-off `node -e` (or the project's language) script. Say which in the reproduction.
2. Work where the product cannot touch the repository: when it writes files to its working directory (a data file, a cache), run it in a scratch directory `R/scratch/` (`cd <abs R>/scratch && <command>`, with the product's absolute path).
3. Run the steps exactly as reported, then once more with the smallest input that still shows the bug.
Write `R/reproduction.md`:
```markdown
Result: reproduced
Way in: tools.e2e cli (node bin/tally.js)
## Steps
1. `node /abs/project/bin/tally.js add 5` in .bdk/runs/fix-total-crash/debug/scratch -> `Added 5.00`, exit 0
2. `node /abs/project/bin/tally.js total` -> exit 1
## Expected
`Total: 5.00`, exit 0 (README.md:6)
## Observed
exit 1, stderr `TypeError: total.toFixed is not a function` at bin/tally.js:20
```
The first line is `Result: reproduced` or `Result: not-reproduced`. Expected comes from what the project states (an acceptance test, an ADR, the docs; name it), else from the report.
When the observed behaviour matches the expected one, the bug did not reproduce: write `R/diagnosis.md` with `Status: not-reproduced` and the steps you ran, create no Change, and go to step 7.
Done when `R/reproduction.md` exists and says `reproduced`, or you stopped at not-reproduced.
## 3. Find the root cause
Follow the evidence from the symptom to its cause: the line the error names or the output comes from, the data it gets, and the caller that produced that data. Read every caller and callee you follow; do not stop at the line that throws when the wrong value comes from elsewhere. Do not guess a cause the code does not show: when nothing explains the observation, write `Status: blocked` with what you read into `R/diagnosis.md` and go to step 7.
The fix covers this one bug. A **related defect** you find on the way - another bug, or data the bug already wrote that fixing the cause does not repair (records or files it already saved wrong) - is not part of it: note each one (what, where, why the fix leaves it) for steps 5 to 7, and do not size, plan or test it. It gets its own Change, which the user starts.
Then size the fix: the lines it changes, every reference to each symbol it changes (Grep the code and the tests), and the test file that covers the code (a neighbouring `*.test.*`, or the tests' directory for a new one).
Done when you can name the root cause with its file and line, the files the fix touches, the test file, and any related defects.
## 4. Decide the fix fits one part
The fix is **too large** when it needs more than `plan.part.max-tasks` tasks or `plan.part.max-files` files (defaults 5 and 10), or a choice between fixes with different behaviour that the user should make (two readings of the expected behaviour, a breaking change of an interface others use). Then write steps 5 and 6 without the plan part, with `Status: too-large`.
Done when you know whether the fix is one part.
## 5. Write the fix Change
The spec of the fix is the issue's body, three sections:
- `## Proposal`: the bug in one or two sentences and the reproduction (`.bdk/runs/<change>/debug/reproduction.md`); `### Intent` quoting the report's symptom word for word; `### Acceptance` with `AC-1`, the expected behaviour of the reproduction; `### What changes`: the fix in a few bullets; `### Out of scope`: each related defect.
- `## Acceptance scenarios`: one `### <name>` scenario, the reproduction with its exact input and expected output (`- WHEN` / `- AND` / `- THEN` lines), so the implementer tests it and the review's E2E check drives it. None for a related defect. Never change what the project promised to fit the code.
- `## Key decisions`: `### D1: <root cause>` (file and line, the data that goes wrong and where it comes from); `### D2: <fix>` with the alternatives considered, the call sites the fix reaches and why each stays correct; `### Risks`, with each related defect as `[Related, not fixed: <what, where>] -> its own Change`. Neither D2 nor the scenario covers a related defect.
From an issue: save the fetched `C/issue.md` to `C/source/issue.md` word for word, then replace `issue.md` with the body (Write); the tracker sees it at the fix gate. From any other report: write the body to `C/source/proposal.md` and create the issue: `"${CLAUDE_PLUGIN_ROOT}/bin/bdk" tracker create --title "<the bug, one line>" --body-file .bdk/runs/<change>/source/proposal.md --run <change>` (it writes `issue.md` and `issue.json`). Run it without asking: the spec of a Change is its issue (ADR-0028), so the report the user handed you is the consent to file it, as an intent is for `/bdk:propose`. When it fails, quote the error and stop with `Status: blocked`. With `tracker.kind` other than `github`, create it as `tracker.instructions` say.
Then, unless too large, write `C/plan/parts/01.md`:
```markdown
---
id: "01"
depends-on: []
files:
- bin/tally.js
- test/tally.test.js
---
# Part 01: Fix of fix-total-crash
## Goal
`tally total` prints the sum after amounts were added.
## Acceptance scenarios
- Scenario: Total after an add
## Tasks
1. Store the parsed amount in `add` instead of the text it was given
- File: bin/tally.js, test/tally.test.js
- Interface: none
- Verified by: Scenario: Total after an add; a test in test/tally.test.js that runs `tally add 5` then `tally total` in a scratch directory and expects `Total: 5.00`, exit 0
```
Each task changes one thing; the first task's `Verified by:` names the test that reproduces the bug with the reproduction's exact input, so the implementer sees it red before the fix. `files` lists every file the tasks touch, tests included. The only acceptance scenario is the reproduction scenario, and no task only pins behaviour that already works (a scenario that passes today): the implementer must see every acceptance test red, and such a test cannot fail, so it would block the fix. A related defect gets no scenario and no task either, even when its test would fail today: it is named in `issue.md` and `diagnosis.md`, not fixed here.
Run `"${CLAUDE_PLUGIN_ROOT}/bin/bdk" plan check .bdk/runs/<change>/plan/parts --issue .bdk/runs/<change>/issue.md`: exit 1 lists problems, fix them and run it again; exit 3 is an environment problem, pass it on and stop.
Done when `issue.md` holds the three sections, the issue exists on the tracker, and, unless too large, its part passes `bdk plan check`.
## 6. Record the diagnosis
Run `git status --porcelain`. It must list nothing: remove anything the reproduction left in the repository, or name it when you cannot. `R/scratch/` stays: it is under the ignored `.bdk/runs/`.
Write `R/diagnosis.md`:
```markdown
Status: ready
Change: fix-total-crash
Reproduction: .bdk/runs/fix-total-crash/debug/reproduction.md
Root cause: bin/tally.js:15 `add` pushes the text argument, so `total` sums strings and calls toFixed on a string
Issue: #12
Scenario: Total after an add
Part: .bdk/runs/fix-total-crash/plan/parts/01.md
Next: /bdk:debug fix-total-crash
```
After `Root cause:`, write one line `Related: <where (file:line, or the data)> <what goes wrong>; <why this fix leaves it>` per related defect you found in step 3, none when there is none; `Issue:` is the issue's number; `Scenario:` names only the reproduction scenario. The first line is `Status: ready`, `too-large` (no `Part:` line; `Next: /bdk:design <change>`), `not-reproduced` (only `Reproduction:` and `Next:` with what would help reproduce it) or `blocked` (`Reason:` instead of `Root cause:`).
Done when `R/diagnosis.md` exists and its first line is the status.
## 7. Reply
Reply in a few lines: the status line; whether and how the bug reproduced; the root cause; each related defect as not fixed, with its own Change as the way to fix it; the Change and its part, or what is missing; and the next step from `diagnosis.md`. Never say the bug is fixed: nothing is fixed until `/bdk:execute` builds the part.