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

Codex bug 修復閉環:先重現再修,附可重跑的驗證

強制 Codex 走「先寫出能重現 bug 的失敗測試 → 找根因 → 最小修改 → 同一測試由紅轉綠 → 跑完整測試確認沒回歸」的閉環,杜絕『改了但沒驗證』與『順手亂改一堆』。

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

01PROMPT

Fix this bug using a strict reproduce-first, verify-after loop. Do not skip steps. Do not claim it's fixed without showing a passing test run.

## The bug
{{BUG_DESCRIPTION}}

Expected behavior: {{EXPECTED}}
Actual behavior: {{ACTUAL}}
How to trigger (if known): {{REPRO_STEPS}}

## Loop you MUST follow

**1. Reproduce FIRST (red).** Before changing any production code, write or identify a test that fails *because of this bug*. Run it and paste the real failing output. If you genuinely cannot write an automated test (e.g. it needs a live external service), say so explicitly and instead give the exact manual command + observed wrong output that demonstrates the bug. A bug you can't reproduce is not yet understood — keep investigating until you can.

**2. Find the root cause.** Trace from the failing symptom back to the line(s) responsible. State the root cause in 1-2 sentences: *what* is wrong and *why* it produces the observed behavior. Do not pattern-match a fix onto the symptom — explain the mechanism. If there are multiple plausible causes, name them and say how you ruled the others out.

**3. Apply the MINIMAL fix.** Change only what's needed to fix the root cause. No drive-by refactors, no reformatting unrelated lines, no renaming. If you spot adjacent issues, list them at the end as 'noticed but not changed' — do not fold them into this fix.

**4. Verify (green).** Re-run the SAME test from step 1 and paste the now-passing output. Then run the broader suite (`{{TEST_COMMAND}}`) and paste the result to prove no regression. If the suite was already partially failing before your change, note which failures are pre-existing and unrelated.

**5. Report.** Summarize: root cause, the one-line essence of the fix, files touched, and the verification command anyone can re-run.

## Hard rules
- Steps 1 and 4 MUST include actual command output, not a description of what you expect to happen. 'Should pass now' is not acceptable — run it.
- If after a reasonable effort you cannot reproduce, STOP and report what you tried and what info you need, rather than guessing at a fix.
- Keep the diff small and reviewable. The test added in step 1 stays in the codebase as a regression guard.
- Respect existing project conventions (read AGENTS.md / CLAUDE.md if present for the right test command and style).

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

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

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

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

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

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

02CONTEXT / 使用情境

何時用:任何『有人回報的 bug』或你自己撞到的錯。為何有效:AI 修 bug 最大的兩個病是『沒重現就猜著改』和『說改好了卻沒跑』。這個 prompt 用 TDD 的紅→綠把它鎖死:步驟 1 先要一個失敗測試(重現=理解),步驟 4 要同一測試轉綠+全套不回歸,且兩步都強制貼真實輸出。技巧:在 Codex CLI 用 `codex exec` 讓它自動跑測試迭代(workspace-write 沙箱下它能反覆 run test 直到綠);{{TEST_COMMAND}} 填你的專案指令(npm test / pytest / go test ./...)。重現不出來時它會停下問你、而不是亂改——這正是你要的。

03SAMPLE / 期待成果

1. Reproduce (red): $ pytest tests/test_dates.py::test_month_rollover -q FAILED — assert parse('2026-01-31' + 1mo) == '2026-02-28', got ValueError: day is out of range 2. Root cause: add_months() 直接把 month+1 後沿用原 day(31),2 月無 31 日故 datetime 拋錯。應 clamp 到當月最後一天。 3. Fix: src/dates.py add_months() 加 day = min(day, last_day_of(year, month)) 4. Verify (green): $ pytest tests/test_dates.py::test_month_rollover -q 1 passed $ pytest -q 214 passed, 0 failed Report: 根因=月份進位未夾日;修 1 檔 1 函式;回歸測試已留存於 test_month_rollover。

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

04VARIABLES / 變數說明

01[BUG_DESCRIPTION]

bug 的描述(症狀、出現在哪個功能/頁面)

02[EXPECTED]

預期的正確行為

03[ACTUAL]

實際發生的錯誤行為(含錯誤訊息/stack trace 若有)

04[REPRO_STEPS]

已知的重現步驟;不知道就填「未知」讓它自己找

05[TEST_COMMAND]

跑完整測試套件的指令,如 npm test、pytest -q、go test ./...

05RESOLVER · 變數代入器0 / 5

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

修飾
Assembled · 填剩餘變數…
Fix this bug using a strict reproduce-first, verify-after loop. Do not skip steps. Do not claim it's fixed without showing a passing test run.

## The bug
{{BUG_DESCRIPTION}}

Expected behavior: {{EXPECTED}}
Actual behavior: {{ACTUAL}}
How to trigger (if known): {{REPRO_STEPS}}

## Loop you MUST follow

**1. Reproduce FIRST (red).** Before changing any production code, write or identify a test that fails *because of this bug*. Run it and paste the real failing output. If you genuinely cannot write an automated test (e.g. it needs a live external service), say so explicitly and instead give the exact manual command + observed wrong output that demonstrates the bug. A bug you can't reproduce is not yet understood — keep investigating until you can.

**2. Find the root cause.** Trace from the failing symptom back to the line(s) responsible. State the root cause in 1-2 sentences: *what* is wrong and *why* it produces the observed behavior. Do not pattern-match a fix onto the symptom — explain the mechanism. If there are multiple plausible causes, name them and say how you ruled the others out.

**3. Apply the MINIMAL fix.** Change only what's needed to fix the root cause. No drive-by refactors, no reformatting unrelated lines, no renaming. If you spot adjacent issues, list them at the end as 'noticed but not changed' — do not fold them into this fix.

**4. Verify (green).** Re-run the SAME test from step 1 and paste the now-passing output. Then run the broader suite (`{{TEST_COMMAND}}`) and paste the result to prove no regression. If the suite was already partially failing before your change, note which failures are pre-existing and unrelated.

**5. Report.** Summarize: root cause, the one-line essence of the fix, files touched, and the verification command anyone can re-run.

## Hard rules
- Steps 1 and 4 MUST include actual command output, not a description of what you expect to happen. 'Should pass now' is not acceptable — run it.
- If after a reasonable effort you cannot reproduce, STOP and report what you tried and what info you need, rather than guessing at a fix.
- Keep the diff small and reviewable. The test added in step 1 stays in the codebase as a regression guard.
- Respect existing project conventions (read AGENTS.md / CLAUDE.md if present for the right test command and style).
FAQ · 常見問題

「Codex bug 修復閉環:先重現再修,附可重跑的驗證」這組提示詞要怎麼用?

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

「Codex bug 修復閉環:先重現再修,附可重跑的驗證」是免費的嗎?

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

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

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

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/codex-bug-reproduce-fix-verify-loop" 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 過時 / 跑不動 / 有錯字? 回報給我們 →