Use early when debugging a medium or hard bug, especially when tests alone may not reveal the real runtime failure. Trigger this before extended TDD iteration when a bug involves runtime state, ordering, persistence, streaming, concurrency, UI/manual reproduction, external services, or when a red or newly passing test may not model the real issue. Skip only when the root cause is already directly proven by a stack trace or deterministic test that exercises the real runtime path.
64
75%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./.claude/skills/debugging-difficult-bugs/SKILL.mdUse this skill early for medium or hard bugs where normal TDD may give false confidence because the test does not fully capture the real bug.
Core idea: instrument the actual runtime path, reproduce the real issue, then inspect append-only JSONL logs before deciding on a fix.
Use this workflow near the start of debugging when any of these are true:
Do not keep iterating only on tests if you do not understand the runtime behavior.
Skip this workflow only when the root cause is already directly proven by a stack trace or by a deterministic failing test that exercises the real runtime path. If you are tempted to make a second speculative fix, use this workflow.
State the uncertainty
Add temporary unconditional instrumentation
.jsonl file in the current working directory.Reproduce the real issue
.jsonl file to send or ask them to tell you when reproduction is complete so you can inspect it.Analyze the log before fixing
Clean up instrumentation
.jsonl files, and any other temporary artifacts.Keep or improve tests
Use append-only JSONL in cwd so it works across CLIs, dev servers, tests, and manual reproduction.
import { appendFileSync } from 'node:fs';
import { join } from 'node:path';
function debugBug(event: string, data: Record<string, unknown> = {}) {
appendFileSync(
join(process.cwd(), 'debug-difficult-bug.jsonl'),
`${JSON.stringify({
ts: new Date().toISOString(),
event,
...data,
})}\n`,
);
}Call it at every meaningful branch or state transition:
debugBug('workflow.start', { runId, stepId, inputKeys: Object.keys(input ?? {}) });
debugBug('workflow.beforeStep', {
runId,
stepId,
status: step.status,
hasResumeData: Boolean(resumeData),
});
try {
const result = await executeStep();
debugBug('workflow.afterStep', { runId, stepId, resultShape: Object.keys(result ?? {}) });
return result;
} catch (error) {
debugBug('workflow.stepError', {
runId,
stepId,
errorName: error instanceof Error ? error.name : typeof error,
errorMessage: error instanceof Error ? error.message : String(error),
});
throw error;
}Prefer compact, structured data over huge dumps.
Log:
Avoid logging:
Treat debug logs as potentially sensitive. Do not ask the user to paste them into public issues, PRs, or shared channels unless they have reviewed/redacted them first.
If sensitive data might appear, log redacted summaries:
debugBug('request.received', {
hasAuthHeader: Boolean(headers.authorization),
bodyKeys: Object.keys(body ?? {}),
messageCount: body?.messages?.length,
});When the user needs to reproduce manually, say exactly this shape:
I added temporary unconditional JSONL instrumentation. Please reproduce the issue once, then send me or point me at:
<cwd>/debug-difficult-bug.jsonl
After I inspect that log, I’ll remove the instrumentation and make the actual fix.If multiple processes have different working directories, either:
process.cwd(), process role, and pid at startup, ordebug-server-flow.jsonl, debug-worker-flow.jsonl, and debug-client-flow.jsonl.Before writing the fix, answer:
A difficult bug is not done until:
3b78ed9
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.