Claude 可以通過電腦使用工具與電腦環境互動,該工具提供截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
Claude 可以通過電腦使用工具與電腦環境互動,該工具提供截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
電腦使用是一項測試版功能,使 Claude 能夠與桌面環境互動。此工具提供:
雖然電腦使用可以與 bash 和文字編輯器等其他工具結合使用,以實現更全面的自動化工作流程,但電腦使用特別指的是電腦使用工具查看和控制桌面環境的能力。
Claude 可以通過電腦使用工具與電腦環境互動,該工具提供截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
電腦使用是一項測試版功能,使 Claude 能夠與桌面環境互動。此工具提供:
雖然電腦使用可以與 bash 和文字編輯器等其他工具結合使用,以實現更全面的自動化工作流程,但電腦使用特別指的是電腦使用工具查看和控制桌面環境的能力。
電腦使用適用於以下 Claude 模型:
| 模型 | 工具版本 | 測試版標誌 |
|---|---|---|
| Claude Opus 4.5 | computer_20251124 | computer-use-2025-11-24 |
| Claude 4 模型 | computer_20250124 | computer-use-2025-01-24 |
| Claude Sonnet 3.7(已棄用) | computer_20250124 | computer-use-2025-01-24 |
Claude Opus 4.5 引入了 computer_20251124 工具版本,具有新功能,包括用於詳細螢幕區域檢查的縮放操作。Claude 4 模型使用針對新架構優化的更新工具版本。Claude Sonnet 3.7(已棄用)引入了其他功能,包括思考功能,以便更深入了解模型的推理過程。
舊工具版本不保證與較新模型向後相容。始終使用與您的模型版本相對應的工具版本。
Claude 可以通過電腦使用工具與電腦環境互動,該工具提供截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
電腦使用是一項測試版功能,使 Claude 能夠與桌面環境互動。此工具提供:
雖然電腦使用可以與 bash 和文字編輯器等其他工具結合使用,以實現更全面的自動化工作流程,但電腦使用特別指的是電腦使用工具查看和控制桌面環境的能力。
電腦使用適用於以下 Claude 模型:
| 模型 | 工具版本 | 測試版標誌 |
|---|---|---|
| Claude Opus 4.5 | computer_20251124 | computer-use-2025-11-24 |
| Claude 4 模型 | computer_20250124 | computer-use-2025-01-24 |
| Claude Sonnet 3.7(已棄用) | computer_20250124 | computer-use-2025-01-24 |
Claude Opus 4.5 引入了 computer_20251124 工具版本,具有新功能,包括用於詳細螢幕區域檢查的縮放操作。Claude 4 模型使用針對新架構優化的更新工具版本。Claude Sonnet 3.7(已棄用)引入了其他功能,包括思考功能,以便更深入了解模型的推理過程。
舊工具版本不保證與較新模型向後相容。始終使用與您的模型版本相對應的工具版本。
電腦使用是一項測試版功能,具有不同於標準 API 功能的獨特風險。與網際網路互動時,這些風險會增加。為了最小化風險,請考慮採取以下預防措施:
在某些情況下,Claude 會遵循內容中找到的命令,即使這與使用者的指示相衝突。例如,網頁上或包含在影像中的 Claude 指示可能會覆蓋指示或導致 Claude 犯錯。我們建議採取預防措施將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
我們已訓練模型抵抗這些提示注入,並添加了額外的防禦層。如果您使用我們的電腦使用工具,我們將自動在您的提示上執行分類器,以標記潛在的提示注入實例。當這些分類器在螢幕截圖中識別潛在的提示注入時,它們將自動引導模型在繼續下一個操作之前要求使用者確認。我們認識到這種額外的保護不適合每個使用案例(例如,沒有人在迴圈中的使用案例),因此如果您想選擇退出並關閉它,請 聯絡我們。
我們仍然建議採取預防措施將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
最後,請在您自己的產品中啟用電腦使用之前,告知最終使用者相關風險並獲得他們的同意。
使用我們的電腦使用參考實現快速入門,其中包括網頁介面、Docker 容器、範例工具實現和代理迴圈。
**注意:**該實現已更新,包括 Claude 4 模型和 Claude Sonnet 3.7 的新工具。請務必拉取最新版本的儲存庫以存取這些新功能。
請使用 此表單 提供 有關模型回應品質、API 本身或文件品質的反饋 - 我們迫不及待地想聽到您的意見!
Claude 可以通過電腦使用工具與電腦環境互動,該工具提供截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
電腦使用是一項測試版功能,使 Claude 能夠與桌面環境互動。此工具提供:
雖然電腦使用可以與 bash 和文字編輯器等其他工具結合使用,以實現更全面的自動化工作流程,但電腦使用特別指的是電腦使用工具查看和控制桌面環境的能力。
電腦使用適用於以下 Claude 模型:
| 模型 | 工具版本 | 測試版標誌 |
|---|---|---|
| Claude Opus 4.5 | computer_20251124 | computer-use-2025-11-24 |
| Claude 4 模型 | computer_20250124 | computer-use-2025-01-24 |
| Claude Sonnet 3.7(已棄用) | computer_20250124 | computer-use-2025-01-24 |
Claude Opus 4.5 引入了 computer_20251124 工具版本,具有新功能,包括用於詳細螢幕區域檢查的縮放操作。Claude 4 模型使用針對新架構優化的更新工具版本。Claude Sonnet 3.7(已棄用)引入了其他功能,包括思考功能,以便更深入了解模型的推理過程。
舊工具版本不保證與較新模型向後相容。始終使用與您的模型版本相對應的工具版本。
電腦使用是一項測試版功能,具有不同於標準 API 功能的獨特風險。與網際網路互動時,這些風險會增加。為了最小化風險,請考慮採取以下預防措施:
在某些情況下,Claude 會遵循內容中找到的命令,即使這與使用者的指示相衝突。例如,網頁上或包含在影像中的 Claude 指示可能會覆蓋指示或導致 Claude 犯錯。我們建議採取預防措施將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
我們已訓練模型抵抗這些提示注入,並添加了額外的防禦層。如果您使用我們的電腦使用工具,我們將自動在您的提示上執行分類器,以標記潛在的提示注入實例。當這些分類器在螢幕截圖中識別潛在的提示注入時,它們將自動引導模型在繼續下一個操作之前要求使用者確認。我們認識到這種額外的保護不適合每個使用案例(例如,沒有人在迴圈中的使用案例),因此如果您想選擇退出並關閉它,請 聯絡我們。
我們仍然建議採取預防措施將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
最後,請在您自己的產品中啟用電腦使用之前,告知最終使用者相關風險並獲得他們的同意。
使用我們的電腦使用參考實現快速入門,其中包括網頁介面、Docker 容器、範例工具實現和代理迴圈。
**注意:**該實現已更新,包括 Claude 4 模型和 Claude Sonnet 3.7 的新工具。請務必拉取最新版本的儲存庫以存取這些新功能。
請使用 此表單 提供 有關模型回應品質、API 本身或文件品質的反饋 - 我們迫不及待地想聽到您的意見!
以下是如何開始使用電腦使用的方法:
import anthropic
client = anthropic.Anthropic()
response = client.beta.messages.create(
model="claude-sonnet-4-5", # 或其他相容模型
max_tokens=1024,
tools=[
{
"type": "computer_20250124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768,
"display_number": 1,
},
{
"type": "text_editor_20250728",
"name": "str_replace_based_edit_tool"
},
{
"type": "bash_20250124",
"name": "bash"
}
],
messages=[{"role": "user", "content": "Save a picture of a cat to my desktop."}],
betas=["computer-use-2025-01-24"]
)
print(response)測試版標頭僅對電腦使用工具是必需的。
上面的範例顯示了所有三個工具一起使用,這需要測試版標頭,因為它包括電腦使用工具。
Claude 可以通過電腦使用工具與電腦環境互動,該工具提供截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
電腦使用是一項測試版功能,使 Claude 能夠與桌面環境互動。此工具提供:
雖然電腦使用可以與 bash 和文字編輯器等其他工具結合使用,以實現更全面的自動化工作流程,但電腦使用特別指的是電腦使用工具查看和控制桌面環境的能力。
電腦使用適用於以下 Claude 模型:
| 模型 | 工具版本 | 測試版標誌 |
|---|---|---|
| Claude Opus 4.5 | computer_20251124 | computer-use-2025-11-24 |
| Claude 4 模型 | computer_20250124 | computer-use-2025-01-24 |
| Claude Sonnet 3.7(已棄用) | computer_20250124 | computer-use-2025-01-24 |
Claude Opus 4.5 引入了 computer_20251124 工具版本,具有新功能,包括用於詳細螢幕區域檢查的縮放操作。Claude 4 模型使用針對新架構優化的更新工具版本。Claude Sonnet 3.7(已棄用)引入了其他功能,包括思考功能,以便更深入了解模型的推理過程。
舊工具版本不保證與較新模型向後相容。始終使用與您的模型版本相對應的工具版本。
電腦使用是一項測試版功能,具有不同於標準 API 功能的獨特風險。與網際網路互動時,這些風險會增加。為了最小化風險,請考慮採取以下預防措施:
在某些情況下,Claude 會遵循內容中找到的命令,即使這與使用者的指示相衝突。例如,網頁上或包含在影像中的 Claude 指示可能會覆蓋指示或導致 Claude 犯錯。我們建議採取預防措施將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
我們已訓練模型抵抗這些提示注入,並添加了額外的防禦層。如果您使用我們的電腦使用工具,我們將自動在您的提示上執行分類器,以標記潛在的提示注入實例。當這些分類器在螢幕截圖中識別潛在的提示注入時,它們將自動引導模型在繼續下一個操作之前要求使用者確認。我們認識到這種額外的保護不適合每個使用案例(例如,沒有人在迴圈中的使用案例),因此如果您想選擇退出並關閉它,請 聯絡我們。
我們仍然建議採取預防措施將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
最後,請在您自己的產品中啟用電腦使用之前,告知最終使用者相關風險並獲得他們的同意。
使用我們的電腦使用參考實現快速入門,其中包括網頁介面、Docker 容器、範例工具實現和代理迴圈。
**注意:**該實現已更新,包括 Claude 4 模型和 Claude Sonnet 3.7 的新工具。請務必拉取最新版本的儲存庫以存取這些新功能。
請使用 此表單 提供 有關模型回應品質、API 本身或文件品質的反饋 - 我們迫不及待地想聽到您的意見!
1. 為 Claude 提供電腦使用工具和使用者提示
2. Claude 決定使用電腦使用工具
stop_reason 為 tool_use,表示 Claude 的意圖。3. 提取工具輸入、在電腦上評估工具並返回結果
tool_result 內容區塊的新 user 訊息繼續對話。4. Claude 繼續呼叫電腦使用工具,直到完成任務
tool_use stop_reason 回應,您應該返回步驟 3。我們將步驟 3 和 4 在沒有使用者輸入的情況下重複稱為「代理迴圈」- 即 Claude 以工具使用請求回應,您的應用程式以評估該請求的結果回應 Claude。
Claude 可以通過電腦使用工具與電腦環境互動,該工具提供螢幕截圖功能以及滑鼠/鍵盤控制,用於自主桌面互動。
電腦使用是一項測試版功能,使 Claude 能夠與桌面環境互動。此工具提供:
雖然電腦使用可以透過 bash 和文字編輯器等其他工具進行增強,以實現更全面的自動化工作流程,但電腦使用特別指的是電腦使用工具查看和控制桌面環境的能力。
電腦使用適用於以下 Claude 模型:
| 模型 | 工具版本 | 測試版標誌 |
|---|---|---|
| Claude Opus 4.5 | computer_20251124 | computer-use-2025-11-24 |
| Claude 4 模型 | computer_20250124 | computer-use-2025-01-24 |
| Claude Sonnet 3.7(已棄用) | computer_20250124 | computer-use-2025-01-24 |
Claude Opus 4.5 引入了 computer_20251124 工具版本,具有新功能,包括用於詳細螢幕區域檢查的縮放操作。Claude 4 模型使用為新架構優化的更新工具版本。Claude Sonnet 3.7(已棄用)引入了其他功能,包括思考功能,以便更深入了解模型的推理過程。
舊工具版本不保證與較新模型向後相容。始終使用與您的模型版本相對應的工具版本。
電腦使用是一項測試版功能,具有不同於標準 API 功能的獨特風險。與網際網路互動時,這些風險會增加。為了最小化風險,請考慮採取以下預防措施:
在某些情況下,Claude 會遵循內容中發現的命令,即使這與使用者的指示相衝突。例如,網頁或影像中包含的 Claude 指示可能會覆蓋指示或導致 Claude 出錯。我們建議採取預防措施,將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
我們已訓練模型以抵抗這些提示注入,並添加了額外的防禦層。如果您使用我們的電腦使用工具,我們將自動在您的提示上執行分類器,以標記潛在的提示注入實例。當這些分類器在螢幕截圖中識別出潛在的提示注入時,它們會自動引導模型在繼續下一個操作之前要求使用者確認。我們認識到這種額外的保護不適合每個使用案例(例如,沒有人在迴圈中的使用案例),因此如果您想選擇退出並將其關閉,請 聯絡我們。
我們仍然建議採取預防措施,將 Claude 與敏感資料和操作隔離,以避免與提示注入相關的風險。
最後,請在您自己的產品中啟用電腦使用之前,向終端使用者告知相關風險並獲得他們的同意。
使用我們的電腦使用參考實現快速入門,其中包括網頁介面、Docker 容器、範例工具實現和代理迴圈。
**注意:**該實現已更新,包括 Claude 4 模型和 Claude Sonnet 3.7 的新工具。請確保拉取最新版本的儲存庫以存取這些新功能。
請使用 此表單 提供有關模型回應品質、API 本身或文件品質的回饋 - 我們迫不及待地想聽到您的意見!
以下是如何開始使用電腦使用的方法:
import anthropic
client = anthropic.Anthropic()
response = client.beta.messages.create(
model="claude-sonnet-4-5", # or another compatible model
max_tokens=1024,
tools=[
{
"type": "computer_20250124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768,
"display_number": 1,
},
{
"type": "text_editor_20250728",
"name": "str_replace_based_edit_tool"
},
{
"type": "bash_20250124",
"name": "bash"
}
],
messages=[{"role": "user", "content": "Save a picture of a cat to my desktop."}],
betas=["computer-use-2025-01-24"]
)
print(response)只有電腦使用工具需要測試版標頭。
上面的範例顯示了所有三個工具一起使用,這需要測試版標頭,因為它包括電腦使用工具。
1. 為 Claude 提供電腦使用工具和使用者提示
2. Claude 決定使用電腦使用工具
stop_reason 為 tool_use,表示 Claude 的意圖。3. 提取工具輸入、在電腦上評估工具並返回結果
tool_result 內容區塊的新 user 訊息繼續對話。4. Claude 繼續呼叫電腦使用工具,直到完成任務
tool_use stop_reason 回應,您應該返回步驟 3。我們將步驟 3 和 4 在沒有使用者輸入的情況下重複稱為「代理迴圈」- 即 Claude 以工具使用請求回應,您的應用程式以評估該請求的結果回應 Claude。
電腦使用需要一個沙箱計算環境,Claude 可以在其中安全地與應用程式和網頁互動。此環境包括:
虛擬顯示:虛擬 X11 顯示伺服器(使用 Xvfb),呈現 Claude 將透過螢幕截圖看到的桌面介面,並使用滑鼠/鍵盤操作進行控制。
桌面環境:在 Linux 上執行的輕量級 UI,具有視窗管理器(Mutter)和面板(Tint2),為 Claude 提供一致的圖形介面以進行互動。
應用程式:預先安裝的 Linux 應用程式,如 Firefox、LibreOffice、文字編輯器和檔案管理器,Claude 可以使用它們來完成任務。
工具實現:整合程式碼,將 Claude 的抽象工具請求(如「移動滑鼠」或「擷取螢幕截圖」)轉換為虛擬環境中的實際操作。
代理迴圈:處理 Claude 和環境之間通訊的程式,將 Claude 的操作傳送到環境,並將結果(螢幕截圖、命令輸出)返回給 Claude。
當您使用電腦使用時,Claude 不會直接連接到此環境。相反,您的應用程式:
為了安全和隔離,參考實現在 Docker 容器內執行所有這些操作,具有適當的連接埠對應,用於檢視和與環境互動。
我們已建立了 參考實現,其中包含快速開始使用電腦使用所需的一切:
電腦使用的核心是「代理迴圈」- 一個循環,其中 Claude 請求工具操作,您的應用程式執行它們,並將結果返回給 Claude。以下是一個簡化的範例:
async def sampling_loop(
*,
model: str,
messages: list[dict],
api_key: str,
max_tokens: int = 4096,
tool_version: str,
thinking_budget: int | None = None,
max_iterations: int = 10, # Add iteration limit to prevent infinite loops
):
"""
A simple agent loop for Claude computer use interactions.
This function handles the back-and-forth between:
1. Sending user messages to Claude
2. Claude requesting to use tools
3. Your app executing those tools
4. Sending tool results back to Claude
"""
# Set up tools and API parameters
client = Anthropic(api_key=api_key)
beta_flag = "computer-use-2025-01-24" if "20250124" in tool_version else "computer-use-2024-10-22"
# Configure tools - you should already have these initialized elsewhere
tools = [
{"type": f"computer_{tool_version}", "name": "computer", "display_width_px": 1024, "display_height_px": 768},
{"type": f"text_editor_{tool_version}", "name": "str_replace_editor"},
{"type": f"bash_{tool_version}", "name": "bash"}
]
# Main agent loop (with iteration limit to prevent runaway API costs)
iterations = 0
while True and iterations < max_iterations:
iterations += 1
# Set up optional thinking parameter (for Claude Sonnet 3.7)
thinking = None
if thinking_budget:
thinking = {"type": "enabled", "budget_tokens": thinking_budget}
# Call the Claude API
response = client.beta.messages.create(
model=model,
max_tokens=max_tokens,
messages=messages,
tools=tools,
betas=[beta_flag],
thinking=thinking
)
# Add Claude's response to the conversation history
response_content = response.content
messages.append({"role": "assistant", "content": response_content})
# Check if Claude used any tools
tool_results = []
for block in response_content:
if block.type == "tool_use":
# In a real app, you would execute the tool here
# For example: result = run_tool(block.name, block.input)
result = {"result": "Tool executed successfully"}
# Format the result for Claude
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": result
})
# If no tools were used, Claude is done - return the final messages
if not tool_results:
return messages
# Add tool results to messages for the next iteration with Claude
messages.append({"role": "user", "content": tool_results})迴圈會繼續,直到 Claude 回應時不請求任何工具(任務完成)或達到最大迭代限制。此保障措施可防止可能導致意外 API 成本的潛在無限迴圈。
使用電腦使用工具時,您必須為您的模型版本包括適當的測試版標誌:
我們建議在閱讀本文件的其餘部分之前先試用參考實現。
以下是一些有關如何獲得最佳品質輸出的提示:
After each step, take a screenshot and carefully evaluate if you have achieved the right outcome. Explicitly show your thinking: "I have evaluated step X..." If not correct, try again. Only when you confirm a step was executed correctly should you move on to the next one.<robot_credentials>)提供使用者名稱和密碼。在需要登入的應用程式中使用電腦使用會增加由於提示注入而導致不良結果的風險。在向模型提供登入認證之前,請查看我們的 提示注入緩解指南。如果您反覆遇到一組明確的問題,或提前知道 Claude 需要完成的任務,請使用系統提示為 Claude 提供明確的提示或指示,說明如何成功完成任務。
當透過 Claude API 請求 Anthropic 定義的工具之一時,會生成電腦使用特定的系統提示。它類似於 工具使用系統提示,但以以下內容開始:
You have access to a set of functions you can use to answer the user's question. This includes access to a sandboxed computing environment. You do NOT currently have the ability to inspect files or interact with external resources, except by invoking the below functions.
與常規工具使用一樣,使用者提供的 system_prompt 欄位仍然受到尊重,並用於構造組合系統提示。
我們已建立了一個參考實現,其中包含了快速開始使用電腦使用所需的一切:
電腦使用的核心是「代理迴圈」- 一個循環過程,其中 Claude 請求工具操作,您的應用程式執行這些操作,並將結果返回給 Claude。以下是一個簡化的示例:
async def sampling_loop(
*,
model: str,
messages: list[dict],
api_key: str,
max_tokens: int = 4096,
tool_version: str,
thinking_budget: int | None = None,
max_iterations: int = 10, # Add iteration limit to prevent infinite loops
):
"""
A simple agent loop for Claude computer use interactions.
This function handles the back-and-forth between:
1. Sending user messages to Claude
2. Claude requesting to use tools
3. Your app executing those tools
4. Sending tool results back to Claude
"""
# Set up tools and API parameters
client = Anthropic(api_key=api_key)
beta_flag = "computer-use-2025-01-24" if "20250124" in tool_version else "computer-use-2024-10-22"
# Configure tools - you should already have these initialized elsewhere
tools = [
{"type": f"computer_{tool_version}", "name": "computer", "display_width_px": 1024, "display_height_px": 768},
{"type": f"text_editor_{tool_version}", "name": "str_replace_editor"},
{"type": f"bash_{tool_version}", "name": "bash"}
]
# Main agent loop (with iteration limit to prevent runaway API costs)
iterations = 0
while True and iterations < max_iterations:
iterations += 1
# Set up optional thinking parameter (for Claude Sonnet 3.7)
thinking = None
if thinking_budget:
thinking = {"type": "enabled", "budget_tokens": thinking_budget}
# Call the Claude API
response = client.beta.messages.create(
model=model,
max_tokens=max_tokens,
messages=messages,
tools=tools,
betas=[beta_flag],
thinking=thinking
)
# Add Claude's response to the conversation history
response_content = response.content
messages.append({"role": "assistant", "content": response_content})
# Check if Claude used any tools
tool_results = []
for block in response_content:
if block.type == "tool_use":
# In a real app, you would execute the tool here
# For example: result = run_tool(block.name, block.input)
result = {"result": "Tool executed successfully"}
# Format the result for Claude
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": result
})
# If no tools were used, Claude is done - return the final messages
if not tool_results:
return messages
# Add tool results to messages for the next iteration with Claude
messages.append({"role": "user", "content": tool_results})迴圈會持續進行,直到 Claude 在不請求任何工具的情況下做出回應(任務完成)或達到最大迭代限制。此保護措施可防止可能導致意外 API 成本的無限迴圈。
使用電腦使用工具時,您必須為您的模型版本包含適當的測試版標誌:
我們建議在閱讀本文檔的其餘部分之前先嘗試參考實現。
以下是一些關於如何獲得最佳品質輸出的提示:
After each step, take a screenshot and carefully evaluate if you have achieved the right outcome. Explicitly show your thinking: "I have evaluated step X..." If not correct, try again. Only when you confirm a step was executed correctly should you move on to the next one.<robot_credentials>)為其提供使用者名稱和密碼。在需要登入的應用程式中使用電腦使用會增加由於提示注入而導致不良結果的風險。在向模型提供登入認證之前,請查看我們的關於緩解提示注入的指南。如果您反覆遇到一組明確的問題,或提前知道 Claude 需要完成的任務,請使用系統提示為 Claude 提供明確的提示或說明,說明如何成功完成任務。
當通過 Claude API 請求 Anthropic 定義的工具之一時,會生成一個電腦使用特定的系統提示。它類似於工具使用系統提示,但開頭為:
You have access to a set of functions you can use to answer the user's question. This includes access to a sandboxed computing environment. You do NOT currently have the ability to inspect files or interact with external resources, except by invoking the below functions.
與常規工具使用一樣,使用者提供的 system_prompt 欄位仍然被尊重並用於構建組合系統提示。
電腦使用工具支援這些操作:
基本操作(所有版本)
[x, y] 處點擊增強操作(computer_20250124)
在 Claude 4 模型和 Claude Sonnet 3.7 中可用:
增強操作(computer_20251124)
在 Claude Opus 4.5 中可用:
computer_20250124 中的所有操作enable_zoom: true。採用 region 參數,其座標為 [x1, y1, x2, y2],定義要檢查的區域的左上角和右下角。| 參數 | 必需 | 描述 |
|---|---|---|
type | 是 | 工具版本(computer_20251124、computer_20250124 或 computer_20241022) |
name | 是 | 必須為 "computer" |
display_width_px | 是 | 顯示寬度(像素) |
display_height_px | 是 | 顯示高度(像素) |
display_number | 否 | X11 環境的顯示編號 |
enable_zoom | 否 | 啟用縮放操作(僅限 computer_20251124)。設定為 true 以允許 Claude 縮放到特定螢幕區域。預設值:false |
將顯示解析度保持在 1280x800 (WXGA) 或以下以獲得最佳性能。較高的解析度可能會因為圖像調整大小而導致準確性問題。
重要:電腦使用工具必須由您的應用程式明確執行 - Claude 無法直接執行它。您負責根據 Claude 的請求實現螢幕截圖捕獲、滑鼠移動、鍵盤輸入和其他操作。
| 參數 | 必需 | 描述 |
|---|---|---|
type | 是 | 工具版本(computer_20251124、computer_20250124 或 computer_20241022) |
name | 是 | 必須為 "computer" |
display_width_px | 是 | 顯示寬度(像素) |
display_height_px | 是 | 顯示高度(像素) |
display_number | 否 | X11 環境的顯示編號 |
enable_zoom | 否 | 啟用縮放操作(僅限 computer_20251124)。設定為 true 以允許 Claude 縮放到特定螢幕區域。預設值:false |
將顯示解析度保持在 1280x800 (WXGA) 或以下以獲得最佳性能。較高的解析度可能會因為圖像調整大小而導致準確性問題。
重要:電腦使用工具必須由您的應用程式明確執行 - Claude 無法直接執行它。您負責根據 Claude 的請求實現螢幕截圖捕獲、滑鼠移動、鍵盤輸入和其他操作。
Claude Sonnet 3.7 引入了一項新的「思考」功能,允許您在模型處理複雜任務時查看其推理過程。此功能可幫助您了解 Claude 如何處理問題,對於除錯或教育目的特別有價值。
要啟用思考,請將 thinking 參數新增到您的 API 請求中:
"thinking": {
"type": "enabled",
"budget_tokens": 1024
}budget_tokens 參數指定 Claude 可以用於思考的令牌數。這從您的整體 max_tokens 預算中扣除。
啟用思考後,Claude 將返回其推理過程作為回應的一部分,這可以幫助您:
以下是思考輸出可能看起來的示例:
[Thinking]
I need to save a picture of a cat to the desktop. Let me break this down into steps:
1. First, I'll take a screenshot to see what's on the desktop
2. Then I'll look for a web browser to search for cat images
3. After finding a suitable image, I'll need to save it to the desktop
Let me start by taking a screenshot to see what's available...| 參數 | 必需 | 描述 |
|---|---|---|
type | 是 | 工具版本(computer_20251124、computer_20250124 或 computer_20241022) |
name | 是 | 必須為 "computer" |
display_width_px | 是 | 顯示寬度(像素) |
display_height_px | 是 | 顯示高度(像素) |
display_number | 否 | X11 環境的顯示編號 |
enable_zoom | 否 | 啟用縮放操作(僅限 computer_20251124)。設定為 true 以允許 Claude 縮放到特定螢幕區域。預設值:false |
將顯示解析度保持在 1280x800 (WXGA) 或以下以獲得最佳性能。較高的解析度可能會因為圖像調整大小而導致準確性問題。
重要:電腦使用工具必須由您的應用程式明確執行 - Claude 無法直接執行它。您負責根據 Claude 的請求實現螢幕截圖捕獲、滑鼠移動、鍵盤輸入和其他操作。
電腦使用工具可以與其他工具結合,以建立更強大的自動化工作流程。當您需要以下功能時,這特別有用:
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: computer-use-2025-01-24" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 2000,
"tools": [
{
"type": "computer_20250124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768,
"display_number": 1
},
{
"type": "text_editor_20250728",
"name": "str_replace_based_edit_tool"
},
{
"type": "bash_20250124",
"name": "bash"
},
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature, either 'celsius' or 'fahrenheit'"
}
},
"required": ["location"]
}
}
],
"messages": [
{
"role": "user",
"content": "Find flights from San Francisco to a place with warmer weather."
}
],
"thinking": {
"type": "enabled",
"budget_tokens": 1024
}
}'| 參數 | 必需 | 描述 |
|---|---|---|
type | 是 | 工具版本(computer_20251124、computer_20250124 或 computer_20241022) |
name | 是 | 必須為「computer」 |
display_width_px | 是 | 顯示寬度(像素) |
display_height_px | 是 | 顯示高度(像素) |
display_number | 否 | X11 環境的顯示編號 |
enable_zoom | 否 | 啟用縮放操作(僅限 computer_20251124)。設定為 true 以允許 Claude 縮放到特定螢幕區域。預設值:false |
為了獲得最佳效能,請將顯示解析度保持在 1280x800 (WXGA) 或以下。較高的解析度可能會因為影像調整大小而導致準確度問題。
重要:電腦使用工具必須由您的應用程式明確執行 - Claude 無法直接執行它。您負責根據 Claude 的請求實現螢幕擷取、滑鼠移動、鍵盤輸入和其他操作。
Claude Sonnet 3.7 引入了新的「思考」能力,允許您在模型處理複雜任務時查看其推理過程。此功能可幫助您了解 Claude 如何處理問題,對於除錯或教育目的特別有價值。
要啟用思考,請在您的 API 請求中新增 thinking 參數:
"thinking": {
"type": "enabled",
"budget_tokens": 1024
}budget_tokens 參數指定 Claude 可用於思考的令牌數量。這將從您的整體 max_tokens 預算中扣除。
啟用思考後,Claude 將返回其推理過程作為回應的一部分,這可以幫助您:
以下是思考輸出可能看起來的示例:
[Thinking]
I need to save a picture of a cat to the desktop. Let me break this down into steps:
1. First, I'll take a screenshot to see what's on the desktop
2. Then I'll look for a web browser to search for cat images
3. After finding a suitable image, I'll need to save it to the desktop
Let me start by taking a screenshot to see what's available...電腦使用工具可以與其他工具結合,以建立更強大的自動化工作流程。當您需要以下操作時,這特別有用:
curl https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: computer-use-2025-01-24" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 2000,
"tools": [
{
"type": "computer_20250124",
"name": "computer",
"display_width_px": 1024,
"display_height_px": 768,
"display_number": 1
},
{
"type": "text_editor_20250728",
"name": "str_replace_based_edit_tool"
},
{
"type": "bash_20250124",
"name": "bash"
},
{
"name": "get_weather",
"description": "Get the current weather in a given location",
"input_schema": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit of temperature, either 'celsius' or 'fahrenheit'"
}
},
"required": ["location"]
}
}
],
"messages": [
{
"role": "user",
"content": "Find flights from San Francisco to a place with warmer weather."
}
],
"thinking": {
"type": "enabled",
"budget_tokens": 1024
}
}'參考實現旨在幫助您開始使用電腦使用。它包含了讓 Claude 使用電腦所需的所有元件。但是,您可以建立自己的電腦使用環境以滿足您的需求。您需要:
tool_use 結果的代理迴圈電腦使用工具實現為無模式工具。使用此工具時,您不需要像其他工具那樣提供輸入模式;模式內建於 Claude 的模型中,無法修改。
設定您的計算環境
建立虛擬顯示或連接到 Claude 將與之互動的現有顯示。這通常涉及設定 Xvfb(X 虛擬幀緩衝區)或類似技術。
實現操作處理程式
建立函數以處理 Claude 可能請求的每種操作類型:
def handle_computer_action(action_type, params):
if action_type == "screenshot":
return capture_screenshot()
elif action_type == "left_click":
x, y = params["coordinate"]
return click_at(x, y)
elif action_type == "type":
return type_text(params["text"])
# ... handle other actions處理 Claude 的工具呼叫
從 Claude 的回應中提取並執行工具呼叫:
for content in response.content:
if content.type == "tool_use":
action = content.input["action"]
result = handle_computer_action(action, content.input)
# Return result to Claude
tool_result = {
"type": "tool_result",
"tool_use_id": content.id,
"content": result
}實現代理迴圈
建立一個迴圈,直到 Claude 完成任務為止:
while True:
response = client.beta.messages.create(...)
# Check if Claude used any tools
tool_results = process_tool_calls(response)
if not tool_results:
# No more tool use, task complete
break
# Continue conversation with tool results
messages.append({"role": "user", "content": tool_results})實現電腦使用工具時,可能會發生各種錯誤。以下是處理方式:
電腦使用功能處於測試版。雖然 Claude 的功能是尖端的,但開發人員應該了解其限制:
left_mouse_down、left_mouse_up 和新的修飾鍵支援)改進了試算表互動的滑鼠點擊。透過使用這些細粒度控制和結合修飾鍵與點擊,儲存格選擇可以更可靠。始終仔細檢查和驗證 Claude 的電腦使用操作和日誌。不要在沒有人工監督的情況下使用 Claude 進行需要完美精度或敏感使用者資訊的任務。
電腦使用功能處於測試版。雖然 Claude 的功能是尖端的,但開發人員應該了解其限制:
left_mouse_down、left_mouse_up 和新的修飾鍵支援)改進了試算表互動的滑鼠點擊。透過使用這些細粒度控制和結合修飾鍵與點擊,儲存格選擇可以更可靠。始終仔細檢查和驗證 Claude 的電腦使用操作和日誌。不要在沒有人工監督的情況下使用 Claude 進行需要完美精度或敏感使用者資訊的任務。
Computer use follows the standard tool use pricing. When using the computer use tool:
System prompt overhead: The computer use beta adds 466-499 tokens to the system prompt
Computer use tool token usage:
| Model | Input tokens per tool definition |
|---|---|
| Claude 4.x models | 735 tokens |
| Claude Sonnet 3.7 (deprecated) | 735 tokens |
Additional token consumption:
If you're also using bash or text editor tools alongside computer use, those tools have their own token costs as documented in their respective pages.
電腦使用功能處於測試版。雖然 Claude 的功能是尖端的,但開發人員應該了解其限制:
left_mouse_down、left_mouse_up 和新的修飾鍵支援)改進了試算表互動的滑鼠點擊。透過使用這些細粒度控制和結合修飾鍵與點擊,儲存格選擇可以更可靠。始終仔細檢查和驗證 Claude 的電腦使用操作和日誌。不要在沒有人工監督的情況下使用 Claude 進行需要完美精度或敏感使用者資訊的任務。
Computer use follows the standard tool use pricing. When using the computer use tool:
System prompt overhead: The computer use beta adds 466-499 tokens to the system prompt
Computer use tool token usage:
| Model | Input tokens per tool definition |
|---|---|
| Claude 4.x models | 735 tokens |
| Claude Sonnet 3.7 (deprecated) | 735 tokens |
Additional token consumption:
If you're also using bash or text editor tools alongside computer use, those tools have their own token costs as documented in their respective pages.