Skip to content
←INDEX / 提示詞庫
TUTORIAL/Claude Code/進階

Claude Code 抓蟲閉環:重現 → 定位根因 → 最小修復 → 回歸測試驗證

把 Claude Code 從『看到報錯就亂改』導正成有紀律的 4 步抓蟲流程:先穩定重現 bug,再用最小化定位真正根因(而非症狀),寫一個會失敗的回歸測試,再做範圍最小的修復,最後跑全套測試證明修好且沒打壞別的。

SakuyaPromptCraft 主筆 · 寫於 2026-06-08
AI 教學 / 腳本Claude Code進階預期輸出說明≈ 698 tokens · 實際用量依工具與輸入而異
Last reviewed2026-06-08Read~12 MIN

01PROMPT

You are fixing a bug. Follow this four-phase loop strictly: REPRODUCE → ISOLATE → FIX → VERIFY. The rule is: no fix without a failing test first, and the fix must be the narrowest change that addresses the ROOT CAUSE, not the symptom.

BUG REPORT:
{{BUG_REPORT}}

KNOWN CONTEXT (stack trace, when it happens, what changed recently, how often):
{{CONTEXT}}

HOW TO RUN THE PROJECT / TESTS:
{{RUN_COMMAND}}

=== PHASE 1: REPRODUCE ===
- First, reproduce the bug reliably. Determine the exact steps, inputs, or command that triggers it.
- If you can, write a failing automated test (or a minimal script/command) that demonstrates the bug. Run it and SHOW the actual failing output.
- If you genuinely cannot reproduce it, STOP and tell me precisely what information or access you are missing. Do not guess at a fix for a bug you cannot trigger.

=== PHASE 2: ISOLATE (root cause) ===
- Narrow down where the defect actually lives. Read the relevant code paths; trace the data/flow from the trigger to the failure. Minimize the reproduction to the smallest case that still fails.
- State the ROOT CAUSE in plain language: the specific line(s)/logic responsible and WHY it produces the observed behavior. Distinguish the root cause from the symptom.
- If recent changes are suspected, inspect the relevant history. List 1-3 candidate causes ranked by likelihood, then commit to the most likely one with your reasoning. If you are uncertain, say so rather than asserting.
- Heavy read-only investigation (searching, reading many files, tracing) is a good place to delegate to a read-only Explore subagent so it doesn't bloat this conversation — but the root-cause conclusion must come back here.

=== PHASE 3: FIX ===
- Make the SMALLEST change that fixes the root cause. Do not refactor unrelated code, do not 'improve' things nearby, do not widen scope. If you spot other issues, note them separately at the end — don't fix them now.
- Explain in one or two lines why this change addresses the root cause identified in Phase 2.

=== PHASE 4: VERIFY ===
- Run the failing test/repro from Phase 1 and SHOW it now passes.
- Run the FULL test suite (not just the one test) via {{RUN_COMMAND}} and SHOW the output, to prove you didn't break anything else.
- Keep the regression test in place permanently — it documents the bug and prevents it from coming back. Confirm it is committed alongside the fix.

Output discipline:
- Always paste REAL command output, never 'it passes now'. If a command can't be run in this environment, say so explicitly.
- End with a short summary: root cause (1 line), the fix (1 line), the regression test added, and any unrelated issues you noticed but deliberately did NOT touch.
- Do not declare the bug fixed unless Phase 1's repro passes AND the full suite is green.

把方括號 [ ] 內的變數換成你的內容,丟進 Claude Code。

◆ 直接開到工具Claude(記得貼)
RUN站內試跑 / TRY IT
▶ 站內試跑

不用離開網站,直接看這組 prompt 跑出來長怎樣(AI 即時生成,扣 1 點)。

SKILL安裝成 SKILL / INSTALL
安裝成 SKILLClaude Code Agent Skill

不只複製貼上 — 下載後放到 ~/.claude/skills/bug-repro-isolate-fix-verify/SKILL.md,之後每個 session 自動可用(觸發時自動載入)。

macOS / Linux
mkdir -p ~/.claude/skills/bug-repro-isolate-fix-verify && mv ~/Downloads/SKILL.md ~/.claude/skills/bug-repro-isolate-fix-verify/SKILL.md
Windows PowerShell
New-Item -ItemType Directory -Force "$env:USERPROFILE\.claude\skills\bug-repro-isolate-fix-verify" | Out-Null; Move-Item "$env:USERPROFILE\Downloads\SKILL.md" "$env:USERPROFILE\.claude\skills\bug-repro-isolate-fix-verify\SKILL.md"

02CONTEXT / 使用情境

何時用:任何具體的 bug 報告——報錯、行為不對、間歇性故障。尤其適合那種『AI 之前改過但越改越亂』的情況,因為它強制先重現+定位再動手。 為何有效:這對應 Claude Code 真實且被廣泛推薦的 4 步除錯方法論——重現問題 → 定位根因 → 套用修復 → 驗證回歸。社群除錯 skill 的核心鐵律就是『no fix without a failing test』。回歸測試被稱為『你的安全帶』:它先證明 bug 存在,再告訴你何時真的修好。最後跑『全套』測試而非單一測試,是因為窄修也可能波及他處。 技巧:① {{CONTEXT}} 盡量給足——stack trace、何時發生、最近改了什麼、發生頻率,診斷準度直接相關。② Phase 2 提到把重度 read-only 調查丟給 Explore subagent(Claude Code 真實的唯讀探索代理,透過 Task/Agent 工具),好處是大量讀檔不會污染主對話的 context;這是真功能,但若你的任務小、不想分流,AI 直接在主線查也行。③ 『最小修復 + 不順手改無關程式』那條規則是防止 AI 把一個 bug 修成三個 bug 的關鍵。④ 若是無法寫自動化測試的 UI/環境問題,至少要求它給出可手動重現的明確步驟與預期/實際行為。

03SAMPLE / 期待成果

=== PHASE 1: REPRODUCE === Wrote failing test `cart total with 0-qty item`. Ran `npm test`: ✕ cart total ignores 0-qty lines — expected 100, got NaN Reproduced reliably. === PHASE 2: ISOLATE === Root cause: `lineTotal()` divides by qty to derive unit price, so qty=0 yields NaN which poisons the sum. Symptom is 'total shows NaN'; root cause is the unguarded division at cart.ts:42. (Candidates considered: rounding bug, currency parse — ruled out by the repro.) === PHASE 3: FIX === Guard qty=0 lines before the division at cart.ts:42 — narrowest change that removes the NaN source. === PHASE 4: VERIFY === Repro test now passes. Full suite `npm test`: 214 passing, 0 failing. Summary — Root cause: division by qty=0 at cart.ts:42. Fix: skip 0-qty lines. Regression test: 'cart total with 0-qty item' (committed). Noted but NOT touched: cart.ts also lacks negative-qty handling — separate issue.

這是預期成果的文字說明。請查看本文實測說明,並以自己的輸入素材小規模試用。

04VARIABLES / 變數說明

01[BUG_REPORT]

Bug 描述:預期行為 vs 實際行為、觸發步驟、錯誤訊息

02[CONTEXT]

已知線索:完整 stack trace、發生時機與頻率、最近的相關改動或部署

03[RUN_COMMAND]

如何跑專案/測試的指令,例如 npm test、pytest、make test,AI 會用它驗證修復

05RESOLVER · 變數代入器0 / 3

填下面的欄位,上方 prompt 會即時替換 [方括號] 內容。填好後按「複製組好的 prompt」直接丟進工具。

修飾
Assembled · 填剩餘變數…
You are fixing a bug. Follow this four-phase loop strictly: REPRODUCE → ISOLATE → FIX → VERIFY. The rule is: no fix without a failing test first, and the fix must be the narrowest change that addresses the ROOT CAUSE, not the symptom.

BUG REPORT:
{{BUG_REPORT}}

KNOWN CONTEXT (stack trace, when it happens, what changed recently, how often):
{{CONTEXT}}

HOW TO RUN THE PROJECT / TESTS:
{{RUN_COMMAND}}

=== PHASE 1: REPRODUCE ===
- First, reproduce the bug reliably. Determine the exact steps, inputs, or command that triggers it.
- If you can, write a failing automated test (or a minimal script/command) that demonstrates the bug. Run it and SHOW the actual failing output.
- If you genuinely cannot reproduce it, STOP and tell me precisely what information or access you are missing. Do not guess at a fix for a bug you cannot trigger.

=== PHASE 2: ISOLATE (root cause) ===
- Narrow down where the defect actually lives. Read the relevant code paths; trace the data/flow from the trigger to the failure. Minimize the reproduction to the smallest case that still fails.
- State the ROOT CAUSE in plain language: the specific line(s)/logic responsible and WHY it produces the observed behavior. Distinguish the root cause from the symptom.
- If recent changes are suspected, inspect the relevant history. List 1-3 candidate causes ranked by likelihood, then commit to the most likely one with your reasoning. If you are uncertain, say so rather than asserting.
- Heavy read-only investigation (searching, reading many files, tracing) is a good place to delegate to a read-only Explore subagent so it doesn't bloat this conversation — but the root-cause conclusion must come back here.

=== PHASE 3: FIX ===
- Make the SMALLEST change that fixes the root cause. Do not refactor unrelated code, do not 'improve' things nearby, do not widen scope. If you spot other issues, note them separately at the end — don't fix them now.
- Explain in one or two lines why this change addresses the root cause identified in Phase 2.

=== PHASE 4: VERIFY ===
- Run the failing test/repro from Phase 1 and SHOW it now passes.
- Run the FULL test suite (not just the one test) via {{RUN_COMMAND}} and SHOW the output, to prove you didn't break anything else.
- Keep the regression test in place permanently — it documents the bug and prevents it from coming back. Confirm it is committed alongside the fix.

Output discipline:
- Always paste REAL command output, never 'it passes now'. If a command can't be run in this environment, say so explicitly.
- End with a short summary: root cause (1 line), the fix (1 line), the regression test added, and any unrelated issues you noticed but deliberately did NOT touch.
- Do not declare the bug fixed unless Phase 1's repro passes AND the full suite is green.
FAQ · 常見問題

「Claude Code 抓蟲閉環:重現 → 定位根因 → 最小修復 → 回歸測試驗證」這組提示詞要怎麼用?

這組 prompt 專為 Claude Code 設計。把 prompt 內 3 個方括號 [變數] 換成你自己的內容,貼進 Claude Code 執行即可。難度中等,照變數說明填好後即可上手。

「Claude Code 抓蟲閉環:重現 → 定位根因 → 最小修復 → 回歸測試驗證」是免費的嗎?

完整 prompt 免費開放閱讀,不用註冊;可保存瀏覽器收藏,登入後可一鍵複製與留言。

用 Claude Code 依這組 prompt 生成的成果可以商用嗎?

prompt 文字本身你可自由使用與修改。但 AI 生成物(圖/音樂/影片/文字)的商用授權,取決於你在 Claude Code 使用的方案與其官方服務條款,請以該工具的授權規範為準。

RELATED你可能也需要

PRO01
TUTORIALSuno v5.5FEATURED
r/SunoAI (anonymous studio engineer)2026-06-12

Suno 工程師思維:4 步驟做出不像 AI 的歌

5.0(1)

Studio engineer 視角拆解 Suno 致命弱點(油炸 vocals、高頻 artifact)+ 4 步驟 DAW workflow + Suno Studio 修音 prompt

高階
Read

免費02
TUTORIALClaude 4.5 SonnetFEATURED
r/ClaudeAI2026-05-14

5 個 6 月 stuck 下來的 Claude 每週 workflow

提案產生器 / 會議處理器 / 內容再利用 / 週五回顧 / 收工 reset — 試了 40 個只有這 5 個沒被丟掉、各省 30+ 分鐘 / 次。

進階
Read

PRO03
TUTORIALClaude 4.5 SonnetFEATURED
r/PromptEngineering2026-05-14

7 個跨 model A/B 測過的 prompt 技巧(不是 vibes)

六個月在 Claude / GPT-4 / Gemini 上用人工 rater A/B 測 200+ prompt 後寫的。包含 persona+constraint stacking / anti-example / role reversal QA / cognitive scaffold / emotional priming / uncertainty CoT / steelman first。

高階
Read

免費04
TUTORIALChatGPTFEATURED
r/ChatGPTPromptGenius2026-05-14

5 個信任檢查單行 prompt(沒有 role-play)

一年的 role-play system prompt + 14-step framework 後總結:真正改變品質的是 5 個單行 prompt。沒有 role、沒有 markdown、沒有「you are an expert」。

入門
Read

免費 · 全文開放閱讀

完整 prompt 已經開放.

免登入閱讀全文、保存瀏覽器收藏;登入後可一鍵複製與留言討論。不用信用卡。

不想註冊?

留個 email,下次有新 prompt 會寄一封簡短摘要給你。退訂一鍵、不轉賣。

每週一期,新上架提示詞 + 模型測試心得。每封信底部都有一鍵取消訂閱。

或訂 RSS feed(30 秒一次的人味選擇)

COMMENTS · 討論區0 則
登入 後可留言。還沒帳號?註冊
目前沒有留言。第一個說說你的經驗。
EMBED · 嵌入 blog / Note一行 iframe HTML、貼進文章即顯示此 prompt 卡片+

適合:部落格、Medium、Notion 公開頁、Substack — 任何支援 iframe / HTML 嵌入的地方。對方點「看完整」會回到本站、是 prompt 庫的免費 backlink。

<iframe src="https://prompt.luvai.net/embed/claude-code-bug-repro-isolate-fix-verify" width="100%" height="380" frameborder="0" style="border:1px solid #e0dcd0;border-radius:4px;" loading="lazy" title="PromptCraft Embed"></iframe>
預覽 embed →380px tall · responsive width
發現這個 prompt 過時 / 跑不動 / 有錯字? 回報給我們 →