From spec-first
Systematically debugs by tracing root causes with predictions before test-first fixes. Use for errors, test failures, GitHub/Linear/Jira issues, stack traces.
npx claudepluginhub sunrain520/spec-firstThis skill uses the workspace's default tool permissions.
Find root causes, then fix them. This skill investigates bugs systematically — tracing the full causal chain before proposing a fix — and optionally implements the fix with test-first discipline.
Executes hypothesis-driven debugging workflow: triage and reproduce bugs, investigate with evidence, analyze root causes, fix and verify, then report. For 'fix this bug' or debug requests.
Fixes bugs via root cause diagnosis with debugger/gap-analyzer, requirements.md generation, /execute delegation, 3-retry circuit breaker, and QA.
Runs structured bug investigation: reproduce issue, trace root cause, test hypotheses, apply TDD fixes via sub-agent, escalate after failures. Use /cdebug when stuck on bugs.
Share bugs, ideas, or general feedback.
Find root causes, then fix them. This skill investigates bugs systematically — tracing the full causal chain before proposing a fix — and optionally implements the fix with test-first discipline.
<bug_description> #$ARGUMENTS </bug_description>
These principles govern every phase. They are repeated at decision points because they matter most when the pressure to skip them is highest.
| Phase | Name | Purpose |
|---|---|---|
| 0 | Triage | Parse input, fetch issue if referenced, proceed to investigation |
| 1 | Investigate | Reproduce the bug, trace the code path |
| 2 | Root Cause | Form hypotheses with predictions for uncertain links, test them, causal chain gate, smart escalation |
| 3 | Fix | Only if user chose to fix. Test-first fix with workspace safety checks |
| 4 | Handoff | Structured summary, then prompt the user for the next action |
All phases self-size — a simple bug flows through them in seconds, a complex bug spends more time in each naturally. No complexity classification, no phase skipping.
Parse the input and reach a clear problem statement.
If the input references an issue tracker, fetch it:
#123, org/repo#123, github.com URL): Parse the issue reference from <bug_description> and fetch with gh issue view <number> --json title,body,comments,labels. For URLs, pass the URL directly to gh.Read the full conversation — the original description AND every comment, with particular attention to the latest ones. Comments frequently contain updated reproduction steps, narrowed scope, prior failed attempts, additional stack traces, or a pivot to a different suspected root cause; treating the opening post as the whole picture often sends the investigation in the wrong direction. Extract reported symptoms, expected behavior, reproduction steps, and environment details from the combined thread. Then proceed to Phase 1.
Everything else (stack traces, test paths, error messages, descriptions of broken behavior): Proceed directly to Phase 1.
Questions:
Prior-attempt awareness: If the user indicates prior failed attempts ("I've been trying", "keeps failing", "stuck"), ask what they have already tried before investigating. This avoids repeating failed approaches and is one of the few cases where asking first is the right call.
Confirm the bug exists and understand its behavior. Run the test, trigger the error, follow reported reproduction steps — whatever matches the input.
agent-browser if installed. Otherwise use whatever works — MCP browser tools, direct URL testing, screenshot capture, etc.references/investigation-techniques.md for intermittent-bug techniques.Before deep code tracing, confirm the environment is what you think it is:
bun install, npm install, bundle install, etc.) — stale node_modules/vendor is a frequent false lead.tool-versions, .nvmrc, Gemfile, etc. against what's actually active)dist/, .next/, compiled binaries from an earlier branch)Read the relevant source files. Follow the execution path from entry point to where the error manifests. Trace backward through the call chain:
As you trace:
git log --oneline -10 -- [file]git bisect (see references/investigation-techniques.md)Reminder: investigate before fixing. Do not propose a fix until you can explain the full causal chain from trigger to symptom with no gaps.
Read references/anti-patterns.md before forming hypotheses.
Assumption audit (before hypothesis formation): List the concrete "this must be true" beliefs your understanding depends on — the framework behaves as expected here, this function returns what its name implies, the config loads before this runs, the caller passes a non-null value, the database is in the state the test implies. For each, mark verified (you read the code, checked state, or ran it) or assumed. Assumptions are the most common source of stuck debugging. Many "wrong hypotheses" are actually correct hypotheses tested against a wrong assumption.
Form hypotheses ranked by likelihood. For each, state:
When the causal chain is obvious and has no uncertain links (missing import, clear type error, explicit null dereference), the chain explanation itself is the gate — no prediction required. Predictions are a tool for testing uncertain links, not a ritual for every hypothesis.
Before forming a new hypothesis, review what has already been ruled out and why.
Causal chain gate: Do not proceed to Phase 3 until you can explain the full causal chain — from the original trigger through every step to the observed symptom — with no gaps. The user can explicitly authorize proceeding with the best-available hypothesis if investigation is stuck.
Reminder: if a prediction was wrong but the fix appears to work, you found a symptom. The real cause is still active.
Once the root cause is confirmed, present:
Then offer next steps.
Use the platform's blocking question tool (AskUserQuestion in Claude Code or request_user_input in Codex). In Claude Code, call ToolSearch with select:AskUserQuestion first if its schema isn't loaded — a pending schema load is not a reason to fall back. Fall back to numbered options in chat only when no blocking tool exists in the harness or the call errors (e.g., Codex edit modes). Never silently skip the question.
Options to offer:
/spec:brainstorm) — only when the root cause reveals a design problem (see below)Do not assume the user wants action right now. The test recommendations are part of the diagnosis regardless of which path is chosen.
When to suggest brainstorm: Only when investigation reveals the bug cannot be properly fixed within the current design — the design itself needs to change. Concrete signals observable during debugging:
Do not suggest brainstorm for bugs that are large but have a clear fix — size alone does not make something a design problem.
If 2-3 hypotheses are exhausted without confirmation, diagnose why:
| Pattern | Diagnosis | Next move |
|---|---|---|
| Hypotheses point to different subsystems | Architecture/design problem, not a localized bug | Present findings, suggest /spec:brainstorm |
| Evidence contradicts itself | Wrong mental model of the code | Step back, re-read the code path without assumptions |
| Works locally, fails in CI/prod | Environment problem | Focus on env differences, config, dependencies, timing |
| Fix works but prediction was wrong | Symptom fix, not root cause | The real cause is still active — keep investigating |
Parallel investigation option: When hypotheses are evidence-bottlenecked across clearly independent subsystems, dispatch read-only sub-agents in parallel, each with an explicit hypothesis and structured evidence-return format. No code edits by sub-agents, and skip this when hypotheses depend on each other's outcomes. If the platform does not support parallel sub-agent dispatch, run the same hypothesis probes sequentially in ranked-likelihood order instead — the parallelism is a latency optimization, not a correctness requirement.
Present the diagnosis to the user before proceeding.
Reminder: one change at a time. If you are changing multiple things, stop.
If the user chose "Diagnosis only" at the end of Phase 2, skip this phase and go straight to Phase 4 for the summary — the skill's job was the diagnosis. If they chose "Rethink the design", control has transferred to /spec:brainstorm and this skill ends.
Workspace and branch check: Before editing files:
git status). If the user has unstaged work in files that need modification, confirm before editing — do not overwrite in-progress changes.main, master, or the value of git rev-parse --abbrev-ref origin/HEAD with its origin/ prefix stripped (the raw output is origin/<name>, so an unstripped comparison will never match the local branch name). Default to creating one; derive a name from the bug and run git checkout -b <name>. On any other branch, proceed.Test-first:
3 failed fix attempts = smart escalation. Diagnose using the same table from Phase 2. If fixes keep failing, the root cause identification was likely wrong. Return to Phase 2.
Conditional defense-in-depth (trigger: grep for the root-cause pattern found it in 3+ other files, OR the bug would have been catastrophic if it reached production): Read references/defense-in-depth.md for the four-layer model (entry validation, invariant check, environment guard, diagnostic breadcrumb) and choose which layers apply. Skip when the root cause is a one-off error with no realistic recurrence path.
Conditional post-mortem (trigger: the bug was in production, OR the pattern appears in 3+ locations): Analyze how this was introduced and what allowed it to survive. Note any systemic gap or repeated pattern found; it informs Phase 4's decision on whether to offer learning capture.
Structured summary — always write this first:
## Debug Summary
**Problem**: [What was broken]
**Root Cause**: [Full causal chain, with file:line references]
**Recommended Tests**: [Tests to add/modify to prevent recurrence, with specific file and assertion guidance]
**Fix**: [What was changed — or "diagnosis only" if Phase 3 was skipped]
**Prevention**: [Test coverage added; defense-in-depth if applicable]
**Confidence**: [High/Medium/Low]
If Phase 3 was skipped (user chose "Diagnosis only" in Phase 2), stop after the summary — the user already told you they were taking it from here. Do not prompt.
If Phase 3 ran, the next move depends on whether this skill created the branch in Phase 3.
When Phase 3 created the branch, default to finishing the bugfix by committing and opening a PR.
AGENTS.md or CLAUDE.md for explicit preferences that conflict with automatic commit-and-PR, such as "always review before pushing", "open PRs as drafts", or "do not open PRs from skills". If any apply, honor them by switching to the pre-existing-branch menu below or skipping the PR step, whichever matches the instruction.git-commit-push-pr. When the entry came from an issue tracker, include the appropriate close syntax in the place that tracker parses, such as Fixes #N in GitHub PR descriptions or the relevant Jira/Linear close syntax. Surface the resulting PR URL.If this skill did not create the branch, prompt the user for the next action via the platform's blocking question tool (AskUserQuestion in Claude Code or request_user_input in Codex). In Claude Code, call ToolSearch with select:AskUserQuestion first if its schema isn't loaded — a pending schema load is not a reason to fall back. Fall back to numbered options in chat only when no blocking tool exists in the harness or the call errors (e.g., Codex edit modes). Never end the phase without collecting a response.
Options:
git-commit-push-pr) — default for most casesMost bugs are localized mechanical fixes where the only lesson is the bug itself. Compounding those clutters docs/solutions/ without adding value. Decide which path applies:
When offering, use the same blocking question tool described above. If the user accepts, run spec-compound, then commit the resulting learning doc to the same branch and push so the open PR picks up the new commit.