• 訊息
  • 託管代理
  • 管理
Search...
⌘K
使用案例
概覽工單路由客戶支援代理內容審核法律摘要
提示工程
概覽提示最佳實務Claude Fable 5 提示技巧Claude Opus 4.8 提示技巧Console 提示工具
測試與評估
定義成功並建構評估在 Console 中使用評估工具降低延遲
強化防護措施
減少幻覺提高輸出一致性緩解越獄減少提示洩漏
參考
詞彙表
Log in
提示最佳實務
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
最佳實務/提示工程

提示最佳實踐

針對 Claude 最新模型的提示工程技術完整指南,涵蓋清晰度、範例、XML 結構化、思考以及代理系統。

這是使用 Claude 最新模型進行提示工程的參考資料,包括 Claude Fable 5、Claude Mythos 5、Claude Opus 4.8、Claude Opus 4.7、Claude Opus 4.6、Claude Sonnet 4.6 和 Claude Haiku 4.5。本頁面分為三個部分:

  • 模型特定指引優先:說明 Claude Fable 5 和 Claude Opus 4.8 在行為上的差異以及需要調整的內容。
  • 適用於所有目前模型的技術其次:一般原則、輸出與格式化、工具使用、思考以及代理系統。
  • 遷移考量最後,適用於從早期世代遷移的提示。

如需模型功能概述,請參閱模型概述。如需 Claude Fable 5 的功能與 API 變更,請參閱 Claude Fable 5 與 Claude Mythos 5 介紹。如需 Claude Opus 4.8 新功能的詳細資訊,請參閱 Claude Opus 4.8 新功能。如需遷移指引,請參閱遷移指南。

Claude Fable 5

Claude Fable 5 和 Claude Mythos 5 的提示指引有專屬頁面:Claude Fable 5 提示指南。該頁面涵蓋與 Claude Opus 4.8 的行為差異,以及值得進行的提示和框架調整,包括努力程度、指令遵循、長期執行進度聲明、記憶系統,以及 reasoning_extraction 拒絕類別。

Claude Opus 4.8 提示指南

Claude Opus 4.8 的提示指引有專屬頁面:Claude Opus 4.8 提示指南。該頁面涵蓋回應長度、努力程度與思考深度校準、工具使用觸發、字面指令遵循、子代理控制,以及設計與前端預設值。

一般原則

本節及後續各節中的技術適用於所有目前的 Claude 模型,包括 Claude Fable 5 和 Claude Mythos 5。

清晰且直接

Claude 對清晰、明確的指令反應良好。具體說明您期望的輸出有助於提升結果。如果您希望獲得「超出預期」的表現,請明確提出要求,而不是依賴模型從模糊的提示中推斷。

請將 Claude 想像成一位聰明但新進的員工,對您的規範和工作流程缺乏背景知識。您越精確地說明您想要什麼,結果就越好。

**黃金法則:**將您的提示展示給對該任務背景了解有限的同事,並請他們依照提示執行。如果他們會感到困惑,Claude 也會。

  • 具體說明期望的輸出格式和限制條件。
  • 當步驟的順序或完整性很重要時,使用編號清單或項目符號將指令以連續步驟的方式提供。

加入背景脈絡以提升表現

提供指令背後的背景脈絡或動機,例如向 Claude 解釋為什麼這種行為很重要,可以幫助 Claude 更好地理解您的目標並提供更有針對性的回應。

Claude 足夠聰明,能夠從解釋中進行概括推理。

有效使用範例

範例是引導 Claude 輸出格式、語氣和結構最可靠的方法之一。幾個精心設計的範例(稱為「few-shot」或「multishot」提示,即少樣本或多樣本提示)可以大幅提升準確性和一致性。

新增範例時,請確保它們:

  • **相關:**緊密反映您的實際使用情境。
  • **多樣:**涵蓋邊緣案例並有足夠的變化,避免 Claude 學到非預期的模式。
  • **結構化:**將範例包裹在 <example> 標籤中(多個範例則使用 <examples> 標籤),以便 Claude 能區分範例與指令。
包含 3–5 個範例以獲得最佳結果。您也可以請 Claude 評估您的範例的相關性和多樣性,或根據您的初始範例集產生額外的範例。

使用 XML 標籤結構化提示

XML 標籤可幫助 Claude 明確地解析複雜的提示,特別是當您的提示混合了指令、背景脈絡、範例和變數輸入時。將每種類型的內容包裹在各自的標籤中(例如 <instructions>、<context>、<input>)可減少誤解。

最佳實踐:

  • 在您的提示中使用一致且具描述性的標籤名稱。
  • 當內容具有自然的層級結構時使用巢狀標籤(文件放在 <documents> 內,每個文件放在 <document index="n"> 內)。

為 Claude 設定角色

在系統提示中設定角色可以針對您的使用情境聚焦 Claude 的行為和語氣。即使只是一句話也能產生差異:

Python
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=1024,
    system="You are a helpful coding assistant specializing in Python.",
    messages=[
        {"role": "user", "content": "How do I sort a list of dictionaries by key?"}
    ],
)
print(message.content)

長上下文提示

處理大型文件或資料豐富的輸入(20k+ token)時,請仔細結構化您的提示以獲得最佳結果:

  • **將長篇資料放在頂部:**將您的長文件和輸入放在提示的頂部附近,位於您的查詢、指令和範例之上。這可以顯著提升所有模型的表現。

    在測試中,將查詢放在末尾可以將回應品質提升高達 30%,特別是在處理複雜的多文件輸入時。
  • **使用 XML 標籤結構化文件內容和中繼資料:**使用多個文件時,將每個文件包裹在 <document> 標籤中,並使用 <document_content> 和 <source>(以及其他中繼資料)子標籤以提高清晰度。

模型自我認知

如果您希望 Claude 在您的應用程式中正確識別自己或使用特定的 API 字串:

Sample prompt for model identity
The assistant is Claude, created by Anthropic. The current model is Claude Opus 4.8.

對於需要指定模型字串的 LLM 驅動應用程式:

Sample prompt for model string
When an LLM is needed, please default to Claude Opus 4.8 unless the user requests
otherwise. The exact model string for Claude Opus 4.8 is claude-opus-4-8.

輸出與格式化

溝通風格與詳細程度

與先前的模型相比,Claude 的最新模型具有更簡潔自然的溝通風格:

  • **更直接且務實:**提供基於事實的進度報告,而非自我誇耀的更新
  • **更具對話性:**稍微更流暢且口語化,較不機械化
  • **較不冗長:**除非另有提示,否則可能會為了效率而略過詳細摘要

這表示 Claude 可能會在工具呼叫後略過口頭摘要,直接跳到下一個動作。如果您希望更清楚地看到其推理過程:

Sample prompt
After completing a task that involves tool use, provide a quick summary of the work you've done.

控制回應的格式

有幾種特別有效的方法可以引導輸出格式:

  1. 告訴 Claude 該做什麼,而不是不該做什麼

    • 不要使用:「不要在回應中使用 markdown」
    • 改用:「您的回應應由流暢的散文段落組成。」
  2. 使用 XML 格式指示符

    • 嘗試:「將回應的散文部分寫在 <smoothly_flowing_prose_paragraphs> 標籤中。」
  3. 讓您的提示風格與期望的輸出相符

    您提示中使用的格式風格可能會影響 Claude 的回應風格。如果您在輸出格式的可控性方面仍遇到問題,請嘗試讓您的提示風格盡可能與期望的輸出風格相符。例如,從提示中移除 markdown 可以減少輸出中的 markdown 數量。

  4. 針對特定格式偏好使用詳細的提示

    如需更精確地控制 markdown 和格式的使用,請提供明確的指引:

Sample prompt to minimize markdown
<avoid_excessive_markdown_and_bullet_points>
When writing reports, documents, technical explanations, analyses, or any long-form
content, write in clear, flowing prose using complete paragraphs and sentences. Use
standard paragraph breaks for organization and reserve markdown primarily for `inline
code`, code blocks (```...```), and simple headings (###, and ###). Avoid using **bold**
and *italics*.

DO NOT use ordered lists (1. ...) or unordered lists (*) unless : a) you're presenting
truly discrete items where a list format is the best option, or b) the user explicitly
requests a list or ranking

Instead of listing items with bullets or numbers, incorporate them naturally into
sentences. This guidance applies especially to technical writing. Using prose instead of
excessive formatting will improve user satisfaction. NEVER output a series of overly
short bullet points.

Your goal is readable, flowing text that guides the reader naturally through ideas
rather than fragmenting information into isolated points.
</avoid_excessive_markdown_and_bullet_points>

LaTeX 輸出

Claude 的最新模型預設使用 LaTeX 來表示數學運算式、方程式和技術說明。如果您偏好純文字,請在提示中加入以下指令:

Sample prompt
Format your response in plain text only. Do not use LaTeX, MathJax, or any markup
notation such as \( \), $, or \frac{}{}. Write all math expressions using standard text
characters (e.g., "/" for division, "*" for multiplication, and "^" for exponents).

文件建立

Claude 的最新模型擅長建立簡報、動畫和視覺文件,具有令人印象深刻的創意風格和強大的指令遵循能力。在大多數情況下,模型在第一次嘗試時就能產生精緻、可用的輸出。

為了在文件建立方面獲得最佳結果:

Sample prompt
Create a professional presentation on [topic]. Include thoughtful design elements,
visual hierarchy, and engaging animations where appropriate.

從預填回應遷移

從 Claude 4.6 模型和 Claude Mythos Preview 開始,不再支援在最後一個助理回合上使用預填回應。向這些模型發送帶有預填助理訊息的請求會回傳 400 錯誤。模型的智慧和指令遵循能力已經進步到大多數預填使用情境不再需要它。較早的模型仍支援預填,且在對話中其他位置加入助理訊息不受影響。

以下是常見的預填情境以及如何從中遷移:

工具使用

工具使用方式

Claude 的最新模型經過訓練以精確遵循指令,並受益於明確指示使用特定工具。如果您說「您能建議一些變更嗎」,Claude 有時會提供建議而不是實作它們,即使進行變更可能才是您的本意。

若要讓 Claude 採取行動,請更加明確:

若要讓 Claude 預設更主動地採取行動,您可以將以下內容加入系統提示:

Sample prompt for proactive action
<default_to_action>
By default, implement changes rather than only suggesting them. If the user's intent is
unclear, infer the most useful likely action and proceed, using tools to discover any
missing details instead of guessing. Try to infer the user's intent about whether a tool
call (e.g., file edit or read) is intended or not, and act accordingly.
</default_to_action>

另一方面,如果您希望模型預設更加謹慎,較不傾向直接跳入實作,且僅在被要求時才採取行動,您可以使用如下的提示來引導此行為:

Sample prompt for conservative action
<do_not_act_before_instructions>
Do not jump into implementation or change files unless clearly instructed to make
changes. When the user's intent is ambiguous, default to providing information, doing
research, and providing recommendations rather than taking action. Only proceed with
edits, modifications, or implementations when the user explicitly requests them.
</do_not_act_before_instructions>

Claude Opus 4.5 和 Claude Opus 4.6 對系統提示的反應也比先前的模型更敏感。如果您的提示是為了減少工具或技能的觸發不足而設計的,這些模型現在可能會過度觸發。解決方法是減弱任何激進的措辭。在您可能曾說「關鍵:您必須在...時使用此工具」的地方,您可以使用更正常的提示,如「在...時使用此工具」。

最佳化平行工具呼叫

Claude 的最新模型擅長平行工具執行。這些模型會:

  • 在研究期間執行多個推測性搜尋
  • 一次讀取多個檔案以更快建立上下文
  • 平行執行 bash 命令(這甚至可能成為系統效能的瓶頸)

此行為很容易引導。雖然模型在沒有提示的情況下平行工具呼叫的成功率很高,但您可以將其提升至約 100% 或調整積極程度:

Sample prompt for maximum parallel efficiency
<use_parallel_tool_calls>
If you intend to call multiple tools and there are no dependencies between the tool
calls, make all of the independent tool calls in parallel. Prioritize calling tools
simultaneously whenever the actions can be done in parallel rather than sequentially.
For example, when reading 3 files, run 3 tool calls in parallel to read all 3 files into
context at the same time. Maximize use of parallel tool calls where possible to increase
speed and efficiency. However, if some tool calls depend on previous calls to inform
dependent values like the parameters, do NOT call these tools in parallel and instead
call them sequentially. Never use placeholders or guess missing parameters in tool
calls.
</use_parallel_tool_calls>
Sample prompt to reduce parallel execution
Execute operations sequentially with brief pauses between each step to ensure stability.

思考與推理

過度思考與過度徹底

Claude Opus 4.6 比先前的模型進行更多的前期探索,特別是在較高的 effort 設定下。這種初始工作通常有助於最佳化最終結果,但模型可能會在未被提示的情況下收集大量上下文或追蹤多條研究線索。如果您的提示先前鼓勵模型更加徹底,您應該針對 Claude Opus 4.6 調整該指引:

  • **以更有針對性的指令取代一概而論的預設值。**不要使用「預設使用 [工具]」,而是加入如「當 [工具] 能增進您對問題的理解時使用它」的指引。
  • **移除過度提示。**在先前模型中觸發不足的工具現在可能會適當觸發。像「如有疑問,請使用 [工具]」這樣的指令會導致過度觸發。
  • **使用 effort 作為後備方案。**如果 Claude 仍然過於積極,請使用較低的 effort 設定。

在某些情況下,Claude Opus 4.6 可能會進行大量思考,這可能會增加思考 token 並減慢回應速度。如果此行為不符合需求,您可以加入明確的指令來限制其推理,或者您可以降低 effort 設定以減少整體思考和 token 使用量。

Sample prompt
When you're deciding how to approach a problem, choose an approach and commit to it.
Avoid revisiting decisions unless you encounter new information that directly
contradicts your reasoning. If you're weighing two approaches, pick one and see it
through. You can always course-correct later if the chosen approach fails.

如果您需要對思考成本設定硬性上限,帶有 budget_tokens 上限的擴展思考在 Opus 4.6 和 Sonnet 4.6 上仍然可用,但已被棄用。建議優先降低 effort 設定,或搭配自適應思考使用 max_tokens 作為硬性限制。

善用思考與交錯思考功能

Claude 的最新模型提供思考功能,對於涉及工具使用後反思或複雜多步驟推理的任務特別有幫助。您可以引導其初始或交錯思考以獲得更好的結果。

Claude Opus 4.6 和 Claude Sonnet 4.6 使用自適應思考(thinking: {type: "adaptive"}),Claude 會動態決定何時思考以及思考多少。Claude 根據兩個因素校準其思考:effort 參數和查詢複雜度。較高的 effort 會引發更多思考,更複雜的查詢也是如此。對於不需要思考的較簡單查詢,模型會直接回應。在內部評估中,自適應思考可靠地帶來比擴展思考更好的表現。請考慮轉換至自適應思考以獲得最智慧的回應。

對於需要代理行為的工作負載,例如多步驟工具使用、複雜的程式編寫任務和長期代理迴圈,請使用自適應思考。較舊的模型使用帶有 budget_tokens 的手動思考模式。

您可以引導 Claude 的思考行為:

Example prompt
After receiving tool results, carefully reflect on their quality and determine optimal
next steps before proceeding. Use your thinking to plan and iterate based on this new
information, and then take the best next action.

自適應思考的觸發行為可透過提示調整。如果您發現模型思考的頻率超出您的預期(這可能發生在大型或複雜的系統提示中),請加入指引來引導它:

Sample prompt
Extended thinking adds latency and should only be used when it will meaningfully improve
answer quality - typically for problems that require multi-step reasoning. When in
doubt, respond directly.

如果您正在從帶有 budget_tokens 的擴展思考遷移,請替換您的思考設定並將預算控制移至 effort:

之前(擴展思考,較舊的模型):

Python
client.messages.create(
    model="claude-sonnet-4-5-20250929",
    max_tokens=64000,
    thinking={"type": "enabled", "budget_tokens": 32000},
    messages=[{"role": "user", "content": "..."}],
)

之後(自適應思考):

Python
client.messages.create(
    model="claude-opus-4-8",
    max_tokens=64000,
    thinking={"type": "adaptive"},
    output_config={"effort": "high"},  # or "max", "xhigh", "medium", "low"
    messages=[{"role": "user", "content": "..."}],
)

如果您未使用擴展思考,則無需變更。當您省略 thinking 參數時,思考預設為關閉。

  • **優先使用一般指令而非規定性步驟。**像「徹底思考」這樣的提示通常比手寫的逐步計畫產生更好的推理。Claude 的推理經常超越人類所能規定的內容。
  • **多樣本範例可與思考搭配使用。**在您的少樣本範例中使用 <thinking> 標籤來向 Claude 展示推理模式。它會將該風格概括應用到自己的擴展思考區塊中。
  • **手動 CoT 作為後備方案。**當思考關閉時,您仍然可以透過要求 Claude 逐步思考問題來鼓勵逐步推理。使用結構化標籤如 <thinking> 和 <answer> 來清楚地將推理與最終輸出分開。
  • **要求 Claude 自我檢查。**附加類似「在您完成之前,請根據 [測試標準] 驗證您的答案」的內容。這能可靠地捕捉錯誤,特別是對於程式編寫和數學。
當擴展思考被停用時,Claude Opus 4.5 對「think」一詞及其變體特別敏感。在這些情況下,請考慮使用「consider」、「evaluate」或「reason through」等替代詞。

如需思考功能的更多資訊,請參閱擴展思考和自適應思考。

代理系統

長期推理與狀態追蹤

Claude 的最新模型擅長長期推理任務,具有卓越的狀態追蹤能力。Claude 透過專注於漸進式進展來在延長的工作階段中保持方向,一次穩定地推進少數幾件事,而不是試圖一次完成所有事情。這種能力特別在多個上下文視窗或任務迭代中顯現,Claude 可以處理複雜任務、儲存狀態,並在新的上下文視窗中繼續。

上下文感知與多視窗工作流程

Claude 4.6 和 Claude 4.5 模型具有上下文感知功能,使模型能夠在整個對話中追蹤其剩餘的上下文視窗(即「token 預算」)。這使 Claude 能夠透過了解其可用的工作空間來更有效地執行任務和管理上下文。

管理上下文限制:

如果您在會壓縮上下文或允許將上下文儲存到外部檔案的代理框架中使用 Claude(如在 Claude Code 中),請考慮將此資訊加入您的提示中,以便 Claude 能相應地行動。否則,Claude 有時可能會在接近上下文限制時自然地嘗試收尾工作。以下是一個範例提示:

Sample prompt
Your context window will be automatically compacted as it approaches its limit, allowing
you to continue working indefinitely from where you left off. Therefore, do not stop
tasks early due to token budget concerns. As you approach your token budget limit, save
your current progress and state to memory before the context window refreshes. Always be
as persistent and autonomous as possible and complete tasks fully, even if the end of
your budget is approaching. Never artificially stop any task early regardless of the
context remaining.

記憶工具與上下文感知自然搭配,可實現無縫的上下文轉換。

多上下文視窗工作流程

對於跨越多個上下文視窗的任務:

  1. **在第一個上下文視窗使用不同的提示:**使用第一個上下文視窗來建立框架(編寫測試、建立設定腳本),然後使用後續的上下文視窗來迭代待辦清單。

  2. **讓模型以結構化格式編寫測試:**要求 Claude 在開始工作前建立測試,並以結構化格式(例如 tests.json)追蹤它們。這會帶來更好的長期迭代能力。提醒 Claude 測試的重要性:「移除或編輯測試是不可接受的,因為這可能導致功能缺失或有錯誤。」

  3. **設定便利工具:**鼓勵 Claude 建立設定腳本(例如 init.sh)以順利啟動伺服器、執行測試套件和程式碼檢查工具。這可避免從新的上下文視窗繼續時重複工作。

  4. **重新開始與壓縮的取捨:**當上下文視窗被清除時,請考慮從全新的上下文視窗開始,而不是使用壓縮。Claude 的最新模型在從本機檔案系統發現狀態方面極為有效。在某些情況下,您可能希望利用這一點而非壓縮。請明確規定它應該如何開始:

    • 「呼叫 pwd;您只能讀取和寫入此目錄中的檔案。」
    • 「檢視 progress.txt、tests.json 和 git 日誌。」
    • 「在繼續實作新功能之前,手動執行一次基本的整合測試。」
  5. **提供驗證工具:**隨著自主任務的長度增加,Claude 需要在沒有持續人類回饋的情況下驗證正確性。像 Playwright MCP 伺服器或用於測試 UI 的電腦使用功能等工具會很有幫助。

Sample prompt
This is a very long task, so it may be beneficial to plan out your work clearly. It's
encouraged to spend your entire output context working on the task - just make sure you
don't run out of context with significant uncommitted work. Continue working
systematically until you have completed this task.

狀態管理最佳實踐

  • **對狀態資料使用結構化格式:**追蹤結構化資訊(如測試結果或任務狀態)時,使用 JSON 或其他結構化格式來幫助 Claude 理解結構描述需求
  • **對進度筆記使用非結構化文字:**自由格式的進度筆記適合追蹤一般進度和上下文
  • **使用 git 進行狀態追蹤:**Git 提供已完成工作的日誌和可還原的檢查點。Claude 的最新模型在使用 git 跨多個工作階段追蹤狀態方面表現特別出色。
  • **強調漸進式進展:**明確要求 Claude 追蹤其進度並專注於漸進式工作

平衡自主性與安全性

在沒有指引的情況下,Claude Opus 4.6 可能會採取難以還原或影響共用系統的行動,例如刪除檔案、強制推送或發布到外部服務。如果您希望 Claude Opus 4.6 在採取潛在風險行動之前先確認,請在提示中加入指引:

Sample prompt
Consider the reversibility and potential impact of your actions. You are encouraged to
take local, reversible actions like editing files or running tests, but for actions that
are hard to reverse, affect shared systems, or could be destructive, ask the user before
proceeding.

Examples of actions that warrant confirmation:
- Destructive operations: deleting files or branches, dropping database tables, rm -rf
- Hard to reverse operations: git push --force, git reset --hard, amending published commits
- Operations visible to others: pushing code, commenting on PRs/issues, sending
messages, modifying shared infrastructure

When encountering obstacles, do not use destructive actions as a shortcut. For example,
don't bypass safety checks (e.g. --no-verify) or discard unfamiliar files that may be
in-progress work.

研究與資訊收集

Claude 的最新模型展現出卓越的代理搜尋能力,可以有效地從多個來源尋找和綜合資訊。為了獲得最佳的研究結果:

  1. **提供明確的成功標準:**定義什麼構成對您研究問題的成功答案

  2. **鼓勵來源驗證:**要求 Claude 跨多個來源驗證資訊

  3. 對於複雜的研究任務,使用結構化方法:

Sample prompt for complex research
Search for this information in a structured way. As you gather data, develop several
competing hypotheses. Track your confidence levels in your progress notes to improve
calibration. Regularly self-critique your approach and plan. Update a hypothesis tree or
research notes file to persist information and provide transparency. Break down this
complex research task systematically.

這種結構化方法讓 Claude 能夠尋找和綜合幾乎任何資訊,並迭代地批判其發現,無論語料庫的大小如何。

子代理協調

Claude 的最新模型展現出顯著改進的原生子代理協調能力。這些模型可以識別何時任務會受益於將工作委派給專門的子代理,並主動這樣做而無需明確指示。

若要利用此行為:

  1. **確保子代理工具定義完善:**在工具定義中提供並描述子代理工具
  2. **讓 Claude 自然地協調:**Claude 會在沒有明確指示的情況下適當地委派
  3. **注意過度使用:**Claude Opus 4.6 對子代理有強烈的偏好,可能會在更簡單、直接的方法就足夠的情況下產生子代理。例如,模型可能會為程式碼探索產生子代理,而直接的 grep 呼叫更快且足夠。

如果您看到過度的子代理使用,請加入關於何時應該和不應該使用子代理的明確指引:

Sample prompt for subagent usage
Use subagents when tasks can run in parallel, require isolated context, or involve
independent workstreams that don't need to share state. For simple tasks, sequential
operations, single-file edits, or tasks where you need to maintain context across steps,
work directly rather than delegating.

串連複雜提示

透過自適應思考和子代理協調,Claude 在內部處理大多數多步驟推理。明確的提示串連(將任務分解為連續的 API 呼叫)在您需要檢查中間輸出或強制執行特定管線結構時仍然有用。

最常見的串連模式是**自我修正:**產生草稿 → 讓 Claude 根據標準審查它 → 讓 Claude 根據審查進行改進。每個步驟都是單獨的 API 呼叫,因此您可以在任何時點記錄、評估或分支。

減少代理程式編寫中的檔案建立

Claude 的最新模型有時可能會為了測試和迭代目的而建立新檔案,特別是在處理程式碼時。這種方法讓 Claude 能夠在儲存最終輸出之前使用檔案(特別是 python 腳本)作為「臨時草稿區」。使用臨時檔案可以改善結果,特別是對於代理程式編寫使用情境。

如果您希望盡量減少新檔案的建立,您可以指示 Claude 自行清理:

Sample prompt
If you create any temporary new files, scripts, or helper files for iteration, clean up
these files by removing them at the end of the task.

過度積極

Claude Opus 4.5 和 Claude Opus 4.6 有過度工程化的傾向,會建立額外的檔案、加入不必要的抽象層,或建立未被要求的彈性。如果您看到這種不希望的行為,請加入具體的指引以保持解決方案的精簡。

例如:

Sample prompt to minimize overengineering
Avoid over-engineering. Only make changes that are directly requested or clearly
necessary. Keep solutions simple and focused:

- Scope: Don't add features, refactor code, or make "improvements" beyond what was
asked. A bug fix doesn't need surrounding code cleaned up. A simple feature doesn't need
extra configurability.

- Documentation: Don't add docstrings, comments, or type annotations to code you didn't
change. Only add comments where the logic isn't self-evident.

- Defensive coding: Don't add error handling, fallbacks, or validation for scenarios
that can't happen. Trust internal code and framework guarantees. Only validate at system
boundaries (user input, external APIs).

- Abstractions: Don't create helpers, utilities, or abstractions for one-time
operations. Don't design for hypothetical future requirements. The right amount of
complexity is the minimum needed for the current task.

避免專注於通過測試和硬編碼

Claude 有時可能過於專注於讓測試通過,而犧牲了更通用的解決方案,或者可能使用變通方法,如用輔助腳本進行複雜的重構,而不是直接使用標準工具。為了防止這種行為並確保穩健、可概括的解決方案:

Sample prompt
Please write a high-quality, general-purpose solution using the standard tools
available. Do not create helper scripts or workarounds to accomplish the task more
efficiently. Implement a solution that works correctly for all valid inputs, not just
the test cases. Do not hard-code values or create solutions that only work for specific
test inputs. Instead, implement the actual logic that solves the problem generally.

Focus on understanding the problem requirements and implementing the correct algorithm.
Tests are there to verify correctness, not to define the solution. Provide a principled
implementation that follows best practices and software design principles.

If the task is unreasonable or infeasible, or if any of the tests are incorrect, please
inform me rather than working around them. The solution should be robust, maintainable,
and extendable.

在代理程式編寫中盡量減少幻覺

Claude 的最新模型較不容易產生幻覺,並根據程式碼提供更準確、有根據、智慧的答案。若要進一步鼓勵此行為並盡量減少幻覺:

Sample prompt
<investigate_before_answering>
Never speculate about code you have not opened. If the user references a specific file,
you MUST read the file before answering. Make sure to investigate and read relevant
files BEFORE answering questions about the codebase. Never make any claims about code
before investigating unless you are certain of the correct answer - give grounded and
hallucination-free answers.
</investigate_before_answering>

特定功能提示

改進的視覺能力

與先前的 Claude 模型相比,Claude Opus 4.5 和 Claude Opus 4.6 具有改進的視覺能力。它們在影像處理和資料擷取任務上表現更好,特別是當上下文中存在多個影像時。這些改進也延伸到電腦使用,模型可以更可靠地解讀螢幕截圖和 UI 元素。您也可以透過將影片分解為影格來使用這些模型分析影片。

一種已被證明能進一步提升表現的有效技術是為 Claude 提供裁切工具或技能。測試顯示,當 Claude 能夠「放大」影像的相關區域時,影像評估會有一致的提升。Anthropic 已建立了裁切工具的 cookbook。

前端設計

Claude Opus 4.5 和 Claude Opus 4.6 擅長建立複雜的真實世界網頁應用程式,具有強大的前端設計能力。然而,在沒有指引的情況下,模型可能會預設使用通用模式,產生使用者所稱的「AI 劣質品」美學。若要建立獨特、有創意、令人驚喜和愉悅的前端:

如需改進前端設計的詳細指南,請參閱關於透過技能改進前端設計的部落格文章。

以下是您可以用來鼓勵更好前端設計的系統提示片段:

Sample prompt for frontend aesthetics
<frontend_aesthetics>
You tend to converge toward generic, "on distribution" outputs. In frontend design, this
creates what users call the "AI slop" aesthetic. Avoid this: make creative, distinctive
frontends that surprise and delight.

Focus on:
- Typography: Choose fonts that are beautiful, unique, and interesting. Avoid generic
fonts like Arial and Inter; opt instead for distinctive choices that elevate the
frontend's aesthetics.
- Color & Theme: Commit to a cohesive aesthetic. Use CSS variables for consistency.
Dominant colors with sharp accents outperform timid, evenly-distributed palettes. Draw
from IDE themes and cultural aesthetics for inspiration.
- Motion: Use animations for effects and micro-interactions. Prioritize CSS-only
solutions for HTML. Use Motion library for React when available. Focus on high-impact
moments: one well-orchestrated page load with staggered reveals (animation-delay)
creates more delight than scattered micro-interactions.
- Backgrounds: Create atmosphere and depth rather than defaulting to solid colors. Layer
CSS gradients, use geometric patterns, or add contextual effects that match the overall
aesthetic.

Avoid generic AI-generated aesthetics:
- Overused font families (Inter, Roboto, Arial, system fonts)
- Clichéd color schemes (particularly purple gradients on white backgrounds)
- Predictable layouts and component patterns
- Cookie-cutter design that lacks context-specific character

Interpret creatively and make unexpected choices that feel genuinely designed for the
context. Vary between light and dark themes, different fonts, different aesthetics. You
still tend to converge on common choices (Space Grotesk, for example) across
generations. Avoid this: it is critical that you think outside the box!
</frontend_aesthetics>

您也可以參考完整的技能定義。

遷移考量

從早期世代遷移到 Claude 4.6 模型時:

  1. **具體說明期望的行為:**考慮準確描述您希望在輸出中看到的內容。

  2. **使用修飾語來框架您的指令:**加入鼓勵 Claude 提高輸出品質和細節的修飾語可以幫助更好地塑造 Claude 的表現。例如,不要使用「建立一個分析儀表板」,而是使用「建立一個分析儀表板。盡可能包含相關的功能和互動。超越基本功能,建立一個功能完整的實作。」

  3. **明確要求特定功能:**需要動畫和互動元素時應明確要求。

  4. **更新思考設定:**Claude 4.6 模型使用自適應思考(thinking: {type: "adaptive"}),而非帶有 budget_tokens 的手動思考。使用 effort 參數來控制思考深度。

  5. **從預填回應遷移:**從 Claude 4.6 模型開始,不再支援在最後一個助理回合上使用預填回應。請參閱從預填回應遷移以取得替代方案的詳細指引。

  6. **調整反懶惰提示:**如果您的提示先前鼓勵模型更加徹底或更積極地使用工具,請減弱該指引。Claude 4.6 模型明顯更加主動,可能會對先前模型所需的指令過度觸發。

如需詳細的遷移步驟,請參閱遷移指南。

從 Claude Sonnet 4.5 遷移到 Claude Sonnet 4.6

請參閱遷移指南中的從 Sonnet 4.5 遷移,其中涵蓋 effort 預設值變更以及兩種擴展思考遷移路徑。

Was this page helpful?

  • Claude Fable 5
  • Claude Opus 4.8 提示指南
  • 一般原則
  • 清晰且直接
  • 加入背景脈絡以提升表現
  • 有效使用範例
  • 使用 XML 標籤結構化提示
  • 為 Claude 設定角色
  • 長上下文提示
  • 模型自我認知
  • 輸出與格式化
  • 溝通風格與詳細程度
  • 控制回應的格式
  • LaTeX 輸出
  • 文件建立
  • 從預填回應遷移
  • 工具使用
  • 工具使用方式
  • 最佳化平行工具呼叫
  • 思考與推理
  • 過度思考與過度徹底
  • 善用思考與交錯思考功能
  • 代理系統
  • 長期推理與狀態追蹤
  • 平衡自主性與安全性
  • 研究與資訊收集
  • 子代理協調
  • 串連複雜提示
  • 減少代理程式編寫中的檔案建立
  • 過度積極
  • 避免專注於通過測試和硬編碼
  • 在代理程式編寫中盡量減少幻覺
  • 特定功能提示
  • 改進的視覺能力
  • 前端設計
  • 遷移考量
  • 從 Claude Sonnet 4.5 遷移到 Claude Sonnet 4.6
  • **以引用為基礎建立回應:**對於長文件任務,請 Claude 先引用文件的相關部分,然後再執行其任務。這有助於 Claude 排除文件其餘內容的干擾。

  • **鼓勵完整使用上下文:**提示 Claude 在繼續之前有效率地完成元件: