Claudeはコンピュータ使用ツールを通じてコンピュータ環境と対話できます。このツールはスクリーンショット機能とマウス/キーボード制御を提供し、自律的なデスクトップ操作を可能にします。
コンピュータ使用は現在ベータ版であり、ベータヘッダーが必要です:
"computer-use-2025-11-24" - Claude Opus 4.6、Claude Opus 4.5用"computer-use-2025-01-24" - Claude Sonnet 4.5、Haiku 4.5、Opus 4.1、Sonnet 4、Opus 4、およびSonnet 3.7(非推奨)用この機能に関するフィードバックはフィードバックフォームからお寄せください。
コンピュータ使用は、Claudeがデスクトップ環境と対話できるようにするベータ機能です。このツールは以下を提供します:
コンピュータ使用はbashやテキストエディタなどの他のツールと組み合わせてより包括的な自動化ワークフローを構築できますが、コンピュータ使用は特にコンピュータ使用ツールのデスクトップ環境を表示・制御する機能を指します。
コンピュータ使用は以下のClaudeモデルで利用可能です:
| モデル | ツールバージョン | ベータフラグ |
|---|---|---|
| Claude Opus 4.6、Claude Opus 4.5 | computer_20251124 | computer-use-2025-11-24 |
| その他のサポートされているモデル | computer_20250124 | computer-use-2025-01-24 |
Claude Opus 4.6とClaude Opus 4.5は、詳細な画面領域の検査のためのズームアクションを含む新機能を備えたcomputer_20251124ツールバージョンを導入しています。その他のモデル(Sonnet 4.5、Haiku 4.5、Sonnet 4、Opus 4、Opus 4.1、およびSonnet 3.7)はcomputer_20250124ツールバージョンを使用します。
古いツールバージョンは、新しいモデルとの後方互換性が保証されていません。常にモデルバージョンに対応するツールバージョンを使用してください。
コンピュータ使用は、標準的なAPI機能とは異なる固有のリスクを持つベータ機能です。これらのリスクはインターネットとの対話時に高まります。
リスクを最小限に抑えるために、以下のような予防措置を検討してください:
状況によっては、Claudeはユーザーの指示と矛盾する場合でも、コンテンツ内に見つかったコマンドに従うことがあります。例えば、ウェブページ上や画像に含まれるClaudeへの指示が、指示を上書きしたり、Claudeにミスを引き起こさせたりする可能性があります。プロンプトインジェクションに関連するリスクを回避するために、Claudeを機密データやアクションから隔離する予防措置を講じることをお勧めします。
私たちはこれらのプロンプトインジェクションに抵抗するようモデルをトレーニングし、追加の防御層を設けています。コンピュータ使用ツールを使用する場合、プロンプトインジェクションの潜在的なインスタンスをフラグ付けするために、プロンプトに対して自動的に分類器を実行します。これらの分類器がスクリーンショット内の潜在的なプロンプトインジェクションを識別した場合、次のアクションに進む前にユーザーの確認を求めるようモデルを自動的に誘導します。この追加の保護がすべてのユースケースに理想的ではないことを認識しています(例えば、人間がループに入っていないユースケース)。オプトアウトして無効にしたい場合は、お問い合わせください。
プロンプトインジェクションに関連するリスクを回避するために、Claudeを機密データやアクションから隔離する予防措置を講じることを引き続きお勧めします。
最後に、ご自身の製品でコンピュータ使用を有効にする前に、エンドユーザーに関連するリスクを通知し、同意を得てください。
Webインターフェース、Dockerコンテナ、ツール実装例、エージェントループを含むコンピュータ使用リファレンス実装で素早く始めましょう。
注意: この実装はClaude 4モデルとClaude Sonnet 3.7の両方の新しいツールを含むように更新されています。これらの新機能にアクセスするために、リポジトリの最新バージョンをプルしてください。
モデルの応答品質、API自体、またはドキュメントの品質に関するフィードバックを提供するには、このフォームをご利用ください。皆様からのご意見をお待ちしております!
コンピュータ使用を始める方法は以下の通りです:
import anthropic
client = anthropic.Anthropic()
response = client.beta.messages.create(
model="claude-opus-4-6", # or another compatible model
max_tokens=1024,
tools=[
{
"type": "computer_20251124",
"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-11-24"]
)
print(response)ベータヘッダーはコンピュータ使用ツールにのみ必要です。
上記の例では3つのツールすべてを一緒に使用しており、コンピュータ使用ツールを含むためベータヘッダーが必要です。
Claudeにコンピュータ使用ツールとユーザープロンプトを提供する
Claudeがコンピュータ使用ツールの使用を決定する
tool_useのstop_reasonがあり、Claudeの意図を示します。ツール入力を抽出し、コンピュータ上でツールを評価し、結果を返す
tool_resultコンテンツブロックを含む新しいuserメッセージで会話を続けます。Claudeはタスクが完了するまでコンピュータ使用ツールを呼び出し続ける
tool_useのstop_reasonで応答し、ステップ3に戻る必要があります。ユーザー入力なしでステップ3と4を繰り返すことを「エージェントループ」と呼びます。つまり、Claudeがツール使用リクエストで応答し、アプリケーションがそのリクエストの評価結果をClaudeに返すことです。
コンピュータ使用には、Claudeがアプリケーションやウェブと安全に対話できるサンドボックス化されたコンピューティング環境が必要です。この環境には以下が含まれます:
仮想ディスプレイ:仮想X11ディスプレイサーバー(Xvfbを使用)。Claudeがスクリーンショットで確認し、マウス/キーボードアクションで制御するデスクトップインターフェースをレンダリングします。
デスクトップ環境:Linux上で動作するウィンドウマネージャー(Mutter)とパネル(Tint2)を備えた軽量UI。Claudeが対話するための一貫したグラフィカルインターフェースを提供します。
アプリケーション:Firefox、LibreOffice、テキストエディタ、ファイルマネージャーなど、Claudeがタスクを完了するために使用できるプリインストールされたLinuxアプリケーション。
ツール実装: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>のようなxmlタグ内にユーザー名とパスワードをプロンプトに提供してください。ログインが必要なアプリケーション内でコンピュータ使用を行うと、プロンプトインジェクションの結果として悪い結果が生じるリスクが高まります。モデルにログイン資格情報を提供する前に、プロンプトインジェクションの軽減に関するガイドを確認してください。明確な一連の問題に繰り返し遭遇する場合や、Claudeが完了する必要のあるタスクを事前に把握している場合は、システムプロンプトを使用して、タスクを正常に完了するための明示的なヒントや指示をClaudeに提供してください。
Anthropicが定義したツールの1つがClaude APIを介してリクエストされると、コンピュータ使用固有のシステムプロンプトが生成されます。これはツール使用システムプロンプトに似ていますが、以下で始まります:
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.6およびClaude Opus 4.5で利用可能:
computer_20250124のすべてのアクションenable_zoom: trueが必要。検査する領域の左上と右下の角を定義する座標[x1, y1, x2, y2]を持つregionパラメータを取ります。| パラメータ | 必須 | 説明 |
|---|---|---|
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 |
重要:コンピュータ使用ツールはアプリケーションによって明示的に実行される必要があります。Claudeは直接実行できません。スクリーンショットのキャプチャ、マウスの移動、キーボード入力、その他のアクションの実装は、Claudeのリクエストに基づいてあなたが責任を持ちます。
Claude Sonnet 3.7は、複雑なタスクに取り組む際のモデルの推論プロセスを確認できる新しい「thinking」機能を導入しました。この機能により、Claudeが問題にどのようにアプローチしているかを理解でき、デバッグや教育目的に特に価値があります。
thinkingを有効にするには、APIリクエストにthinkingパラメータを追加します:
"thinking": {
"type": "enabled",
"budget_tokens": 1024
}budget_tokensパラメータは、Claudeがthinkingに使用できるトークン数を指定します。これは全体のmax_tokensバジェットから差し引かれます。
thinkingが有効な場合、Claudeはレスポンスの一部として推論プロセスを返します。これにより以下が可能になります:
thinkingの出力がどのように見えるかの例を以下に示します:
[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-opus-4-6",
"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 Virtual Framebuffer)または同様の技術のセットアップが含まれます。
アクションハンドラーの実装
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 actionsClaudeのツール呼び出しの処理
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})コンピュータ使用ツールを実装する際、さまざまなエラーが発生する可能性があります。以下はそれらの処理方法です:
APIは画像を最長辺で最大1568ピクセル、合計で約115万ピクセルに制限します(詳細は画像のリサイズを参照)。例えば、1512x982の画面は約1330x864にダウンサンプリングされます。Claudeはこの小さい画像を分析し、そのスペースでの座標を返しますが、ツールは元の画面スペースでクリックを実行します。
座標変換を処理しないと、Claudeのクリック座標がターゲットを外す可能性があります。
これを修正するには、スクリーンショットを自分でリサイズし、Claudeの座標をスケールアップします:
import math
def get_scale_factor(width, height):
"""Calculate scale factor to meet API constraints."""
long_edge = max(width, height)
total_pixels = width * height
long_edge_scale = 1568 / long_edge
total_pixels_scale = math.sqrt(1_150_000 / total_pixels)
return min(1.0, long_edge_scale, total_pixels_scale)
# When capturing screenshot
scale = get_scale_factor(screen_width, screen_height)
scaled_width = int(screen_width * scale)
scaled_height = int(screen_height * scale)
# Resize image to scaled dimensions before sending to Claude
screenshot = capture_and_resize(scaled_width, scaled_height)
# When handling Claude's coordinates, scale them back up
def execute_click(x, y):
screen_x = x / scale
screen_y = y / scale
perform_click(screen_x, screen_y)コンピュータ使用機能はベータ版です。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.
Was this page helpful?