Skip to content
Mastering Claude

Home / Everyday moves

Everyday moves9 minApplication

Debugging and fixing a bug

A precise reproduction command and a complete stack trace steer the diagnosis towards the real cause of a bug, and the fix is only declared closed once a regression test reproducing the faulty case has been run and its output read.

Pasting only the last line of an error message to Claude Code leaves the bug's real cause out of view. The documented workflow for fixing a bug effectively calls for a more complete gesture: give the command that reproduces the problem and the complete stack trace, not just its last call shown on screen.

Reproduce before diagnosing

Three elements make the difference between a fix that touches the symptom and a fix that touches the cause. The exact command that triggers the bug, the entire stack trace from the entry point to the error, and a note on whether it is intermittent or constant. A bug that only appears once in ten calls does not have the same cause as a bug that fails on every call, and this distinction steers the whole diagnosis that follows.

The following example fabricates its own data to stay valid for any reader, without touching any real file of a project. A function that shares a total across a number of parts fails when that number is zero.

function partager(total, nombreDeParts) {
  return total / nombreDeParts; // aucune garde sur nombreDeParts
}

console.log(partager(90, 3));  // 30, cas normal
console.log(partager(90, 0));  // Infinity, le bug réel se cache ici

The stack trace here would point to the exact call to partager(90, 0), the reproduction command would be this isolated call, and the nature of the bug would be constant: zero parts always produces the same invalid result, never an intermittent error.

The fix does not close on the first green

Once the cause is identified, the fix is limited to the code responsible, without touching what already worked. The final gesture consists of requiring a regression test that reproduces exactly the faulty case observed, then reading its output before considering the bug closed.

function partager(total, nombreDeParts) {
  if (nombreDeParts === 0) throw new Error("nombre de parts invalide");
  return total / nombreDeParts;
}

try {
  partager(90, 0);
} catch (erreur) {
  console.log("test de régression : ", erreur.message);
}

This requirement directly echoes writing the test before the implementation: in both cases, confidence comes from an output that was run and read, not from rereading the fixed code.

Figure 1

From reported bug to proven fix

01
Reproduce
The exact command that triggers the bug is isolated, with the complete stack trace from the entry point.
02
Diagnose
The real cause is sought in the code pointed to by the trace, noting whether the bug is intermittent or constant.
03
Fix
Only the code identified as responsible is modified, without touching the rest of the file.
04
Test the regression
A test reproducing exactly the faulty case observed is written and run.
05
Confirm the green
The regression test's output is read before considering the bug closed.
The sequence shows that the fix is the last step only in appearance: the proof that the bug is resolved comes from the test run afterwards, not from the fix itself.
Calibrate it yourself

A developer pastes to Claude Code the error message displayed by the application. Claude proposes a fix three minutes later.

Write in one sentence what this situation establishes, and in one sentence what it does not establish.

What to remember
  • A precise reproduction command and a complete stack trace steer the diagnosis towards the real cause, the last line of an error alone is not enough.
  • Specifying whether a bug is intermittent or constant changes the nature of the cause being sought, the two categories do not share the same origins.
  • A fix is limited to the code actually responsible for the bug, without touching what already worked before the intervention.
  • A bug is only declared closed once a regression test reproducing the faulty case has been run and its output read.
Do this now

Reproduce a real bug from your project in an isolated file that depends on no data from the repository, paste to Claude Code the reproduction command and the complete trace, then require a regression test before accepting the fix.

Check the source

Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.