Claude Code 抓蟲閉環:重現 → 定位根因 → 最小修復 → 回歸測試驗證
把 Claude Code 從『看到報錯就亂改』導正成有紀律的 4 步抓蟲流程:先穩定重現 bug,再用最小化定位真正根因(而非症狀),寫一個會失敗的回歸測試,再做範圍最小的修復,最後跑全套測試證明修好且沒打壞別的。
AI 修 bug 最危險的地方:它常修『症狀』而非『根因』,或順手改一堆無關程式,把問題從這裡推到那裡。
這個提示詞鎖死它的抓蟲節奏——先穩定重現、再定位根因、寫一個會失敗的回歸測試、做最小修復、最後全套測試驗證安全帶。
[ Log in to see the full prompt ]Sign up free to see the full prompt, copy it, save it, and join the discussion. Free content unlocks on login; Pro content is a separate subscription.
何時用:任何具體的 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/環境問題,至少要求它給出可手動重現的明確步驟與預期/實際行為。
=== 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.
Suno Engineer's Mindset: 4 Steps to a Song That Doesn't Sound Like AI
A studio engineer's breakdown of Suno's fatal weaknesses (fried vocals, high-frequency artifacts), plus a 4-step DAW workflow and a Suno Studio cleanup prompt.
5 Claude Weekly Workflows That Stuck After 6 Months
Proposal generator / meeting processor / content repurposer / Friday review / shutdown reset — out of 40 I tried, only these 5 survived, each saving 30+ minutes per run.