# 策展 · X (Twitter) 🔥

> 📖 本站完整內容索引（documentation index）：[llms.txt](/llms.txt)

> 作者：rody (@0x_rody) · 平台：X (Twitter) · 日期：2026-06-06

> 原始來源：https://x.com/0x_rody/status/2063295395434831922

## 中文摘要

# 如何讓 Claude Code 在不知道答案時停止胡說八道（內含精確設定）

Claude Code 每天都在對你撒謊。憑空捏造的函式、虛假的 import，明明什麼都沒跑卻說「測試通過」。解決方案是一套 4 層架構的設定，讓它撒謊的代價變得很高。

Claude 告訴你 Bug 修好了。兩小時後，你發現它呼叫的函式根本不存在。

大多數開發者學會了檢查一切，並把錯怪在模型身上。但真正的解決方案是在謊言離開你的電腦之前就將其攔截。

以下是完整的誠實設定指南 👇

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1780786706301-iaHKJJj2kW0AA8Ybijpg.jpg)

## 為什麼 Claude 一開始就會胡說八道

Claude 本質上是一個文字預測器。當它不知道某件事時，它會預測出看起來正確的文字。捏造的函式名稱看起來就像真的，自信滿滿說出的廢話，讀起來跟自信滿滿說出的真理沒兩樣。

你無法分辨兩者的區別，直到兩小時後你的程式碼崩潰，且需要再花一小時來除錯。

解決方案不是換一個更聰明的模型，而是讓 Claude 的輸出能夠即時被驗證，並讓「我不知道」比「瞎猜」更具成本效益。

以下是 4 個層級。它們加在一起，能將捏造內容的機率降至幾乎為零。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1780786705763-iaHKJJxOMXgAAQ4VGjpg.jpg)

## 第 1 層：CLAUDE.md 誠實規則

第一層是 CLAUDE.md 中的一組規則，明確告訴 Claude 何時該承認不確定性以及該如何承認。將此內容放入你的專案根目錄：

```markdown
## Honesty rules (read every turn)

Before claiming a function, class, or import exists, verify it by reading
the file or running a grep. Never fabricate symbols.

If you cannot verify something, say "I haven't verified this" explicitly.
Do not write code that depends on the unverified claim.

If a task asks you to use a library you've never seen referenced in this
project, ask before adding it.

If a task involved tests or builds, do not claim success unless you
actually ran the test or build command in this session.

Never invent error messages, API responses, or stack traces. If you
didn't see them, say so.

When you genuinely don't know, the correct answer is "I don't know" or
"I need to check first." Both are better than a confident guess.
```

這些規則看起來很顯而易見。

但其實不然，因為 Claude 預設被優化為「看起來很有幫助」，除非你明確給予許可，否則「我不知道」聽起來會顯得沒用。

最後一行是最重要的一點。這是「我不知道」的許可證，而大多數人從未授予過它。

## 第 2 層：寫入前的驗證模式

第二層強制 Claude 在寫入程式碼前進行驗證。將此內容加入 CLAUDE.md 的誠實規則下方：

```markdown
## Verification protocol

Before writing or editing code that uses a symbol (function, class, type,
constant), do one of:

1. Read the file where it's defined and confirm the signature
2. Run `grep -r "symbolName" .` or use the Glob tool to find it
3. Check package.json, requirements.txt, Cargo.toml, or equivalent for
   the dependency

If you skip verification, prefix the code with a comment:
`// UNVERIFIED: I have not confirmed this symbol exists`

Plan-then-execute mode is preferred for any task touching more than one
file. Use Shift+Tab to enter plan mode before starting.
```

這會讓 Claude 每次對話多消耗幾次工具呼叫，但能幫你省下原本花在除錯虛假函式呼叫上的數小時時間。

## 第 3 層：即時捕捉謊言的 Hook

第三層是 settings.json 中的 Hook，會在 Claude 每次寫入檔案時執行型別檢查器或 Linter。如果 Claude 捏造了一個 import，檢查器會立即失敗，Claude 必須在宣稱任務完成前修復它。

```json
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Write(*.ts|*.tsx)|Edit(*.ts|*.tsx)",
        "hooks": [
          { "type": "command", "command": "npx tsc --noEmit --pretty false 2>&1 | head -20" }
        ]
      },
      {
        "matcher": "Write(*.py)|Edit(*.py)",
        "hooks": [
          { "type": "command", "command": "ruff check --quiet $file && pyright $file 2>&1 | head -20" }
        ]
      },
      {
        "matcher": "Write(*.rs)|Edit(*.rs)",
        "hooks": [
          { "type": "command", "command": "cargo check --message-format=short 2>&1 | head -20" }
        ]
      }
    ]
  }
}
```

Hook 的輸出會作為 context 回傳給 Claude。如果 tsc 說「Cannot find module 'foo'」，Claude 會立即看到並修復捏造的 import。沒有任何捏造的程式碼能逃過 PostToolUse 的檢查。

對於涉及測試的任務，請加入一個 Stop hook，在 Claude 宣告任務完成前執行測試套件：

```json
"Stop": [
  {
    "hooks": [
      { "type": "command", "command": "npm test 2>&1 | tail -30" }
    ]
  }
]
```

現在 Claude 無法在沒有實際執行測試的情況下說「完成，測試通過」。Hook 會幫你執行它們。

結果會回傳給 Claude。如果測試失敗，Claude 必須修復它們或承認測試未通過。

## 第 4 層：事實查核 Agent

第四層是一個子 Agent，其唯一工作是在 Claude 的主張發布前進行審查。

將此內容放入 .claude/agents/fact-checker.md：

```yaml
---
name: fact-checker
description: Use this agent after Claude has made claims about what code does, what tests passed, or what a library supports. Invoke before any commit, before any user-facing summary, and after any task that involved new dependencies.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You verify claims, you do not write code.

When invoked, do this:

1. Identify every factual claim in the recent conversation. Examples:
   "the function X does Y", "the tests pass", "library Z supports W",
   "this import is correct".

2. For each claim, verify it independently:
   - Code claims: read the actual file and confirm
   - Test claims: run the tests yourself
   - Library claims: check the actual package or its docs
   - Import claims: confirm the package is in the dependency manifest

3. Produce a report:
   - VERIFIED: claim, evidence (file:line or command output)
   - WRONG: claim, what's actually true
   - UNVERIFIABLE: claim, why you couldn't check it

Never accept "trust me" claims. Never make claims of your own. If you
can't verify, the correct output is UNVERIFIABLE.
```

在提交程式碼或與團隊分享結果前呼叫此 Agent。它能捕捉到前 3 層漏掉的謊言。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1780786706079-iaHKJKjNqXYAAc9Gtpng.png)

## 「我不知道」的許可證

Claude 被訓練成要樂於助人，而承認無知感覺起來並不「樂於助人」。所以它會猜測，而且猜測看起來還挺像那麼回事。

解決方案是授予它「不知道」的許可。CLAUDE.md 完成了一半，你的反應則是另一半。用耐心回報「我還沒驗證過這一點」，你就能在每次對話中獲得誠實的 Claude；用挫折感懲罰它，Claude 就會回到瞎猜的老路。

這不是一種設定，而是一種習慣。這是整個架構中最被低估的修復方式。

## 如何判斷它是否真的有效

在你的日常對話中觀察這三個跡象：

Claude 在加入依賴項之前會先詢問。「我應該加入 X 還是使用標準函式庫？」而不是默默執行 npm install。

Claude 在談論現有程式碼時會引用 file:line。「src/auth/middleware.ts:47 中的 validateToken 執行了 Y」而不是「validateToken 函式執行了 Y」。

tsc 和你的 Linter 不再尖叫。Hook 會即時捕捉到罕見的捏造內容，Claude 會自動修正，所以當你檢查時，謊言已經消失了。

一兩天後沒看到這些跡象？代表有一層沒載入。通常是 CLAUDE.md 位置錯誤或命名錯誤。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1780786705787-iaHKJLk6rWMAAWMkAjpg.jpg)

## 導致 Claude 繼續撒謊的常見錯誤

CLAUDE.md 太長了。Claude 只讀了前半部分，後面就草草瀏覽。請將誠實規則放在前 50 行。

Hook 靜默記錄。如果輸出沒有回到標準輸出 (stdout)，Claude 就不知道它撒謊了。確保 Hook 的輸出會回到對話中。

你跳過了規劃模式 (Plan mode)。那是 Claude 在寫入前暴露錯誤假設的地方。跳過它，你就錯過了捕捉謊言成本最低的時刻。

你沒有呼叫事實查核 Agent。子 Agent 只有在你實際呼叫時才有用。將 @fact-checker 納入你的提交流程中。

你對「我不知道」的反應很差。只要懲罰一次誠實，Claude 就會回到瞎猜。如果沒有這一點，其他 3 層設定也無法發揮作用。

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1780786706305-iaHKJLuYZXEAArPaJpng.png)

## 5 分鐘誠實稽核

1 分鐘：將 CLAUDE.md 誠實規則和驗證協定複製到你的專案根目錄。

1 分鐘：將 Hook 區塊複製到 ~/.claude/settings.json 或 .claude/settings.json。

2 分鐘：使用上述模板建立 .claude/agents/fact-checker.md。

1 分鐘：執行一個你通常會再次檢查的任務。觀察 tsc 輸出是否回傳給 Claude。確認 Claude 是否明確說出「已驗證」或「我尚未驗證這一點」。

完成。捏造內容的頻率會從「每隔一次對話」降至「罕見且能立即被捕捉」。模型並沒有變聰明，是你的設定變聰明了。

感謝閱讀！

![](https://pub-75d4fe1e4e80421b9ecb1245a7ae0d1a.r2.dev/curated/1780786705911-iaHKJNXAfWQAA3uIkjpg.jpg)

## 標籤

Claude Code, CLI, Skills, 教學資源, Anthropic, Claude
