### Install Dependencies and Run Example Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Installs necessary Python packages and Playwright browsers, sets the API key, and runs a sample command to open TextEdit and type 'hello world'. This task will control your mouse and keyboard. ```bash python -m pip install -r requirements.txt && python -m playwright install chromium echo "ANTHROPIC_API_KEY=" > .env python -m computer_use "open TextEdit and type hello world" ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/README.md Clone the quickstart repository and navigate into the browser-use-demo directory. ```bash git clone https://github.com/anthropics/claude-quickstarts.git cd claude-quickstarts/browser-use-demo ``` -------------------------------- ### Run Generated Application Setup Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/README.md Execute the setup script generated by the autonomous agent to prepare the application environment. ```bash cd generations/my_project # Run the setup script created by the agent ./init.sh ``` -------------------------------- ### Setup and Run Docker Container Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/README.md Execute the setup script, build the Docker image, and run the container. Mounts the local repository for development and exposes necessary ports. Ensure your ANTHROPIC_API_KEY is set. ```bash ./setup.sh # configure venv, install development dependencies, and install pre-commit hooks docker build . -t computer-use-demo:local # manually build the docker image (optional) export ANTHROPIC_API_KEY=%your_api_key% docker run \ -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ -v $(pwd)/computer_use_demo:/home/computeruse/computer_use_demo/ `# mount local python module for development` \ -v $HOME/.anthropic:/home/computeruse/.anthropic \ -p 5900:5900 \ -p 8501:8501 \ -p 6080:6080 \ -p 8080:8080 \ -it computer-use-demo:local # can also use ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest ``` -------------------------------- ### Setup and Run Computer-Use Demo Source: https://github.com/anthropics/claude-quickstarts/blob/main/CLAUDE.md Commands to initialize the environment, build the Docker image, and execute the container for the computer-use demo. ```bash ./setup.sh ``` ```bash docker build . -t computer-use-demo:local ``` ```bash docker run -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY -v $(pwd)/computer_use_demo:/home/computeruse/computer_use_demo/ -v $HOME/.anthropic:/home/computeruse/.anthropic -p 5900:5900 -p 8501:8501 -p 6080:6080 -p 8080:8080 -it computer-use-demo:local ``` -------------------------------- ### Run the development server Source: https://github.com/anthropics/claude-quickstarts/blob/main/financial-data-analyst/README.md Start the local development environment to preview the application. ```bash npm run dev ``` -------------------------------- ### Install dependencies Source: https://github.com/anthropics/claude-quickstarts/blob/main/financial-data-analyst/README.md Install the required Node.js packages for the project. ```bash npm install ``` -------------------------------- ### Run Localization Demo Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Starts the localization demo server using uvicorn, enabling hot-reloading for development. ```bash python -m uvicorn dev_ui.localization_demo.server:app --reload --port 8001 ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/tests/README.md Install the necessary packages to run the test suite. ```bash # Install test dependencies pip install -r test-requirements.txt # Or install with extras pip install -e ".[test]" ``` -------------------------------- ### Install Headless Chromium with uv Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Install the headless Chromium browser using uv for potentially faster installation. This command synchronizes packages and then installs playwright. ```bash uv sync uv run playwright install chromium ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/README.md Copy the example environment file and add your Anthropic API key. ```bash cp .env.example .env # Edit .env file and add your ANTHROPIC_API_KEY ``` -------------------------------- ### Initial Project Orientation Commands Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/prompts/coding_prompt.md Use these bash commands to understand the project structure, requirements, and history before starting development. ```bash pwd ls -la cat app_spec.txt cat feature_list.json | head -50 cat claude-progress.txt git log --oneline -20 cat feature_list.json | grep '"passes": false' | wc -l ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/CONTRIBUTING.md Installs pre-commit hooks to automate checks before commits. ```bash pre-commit install ``` -------------------------------- ### Run Docker Compose Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/README.md Start the browser automation demo using Docker Compose. Use --watch for development with auto-sync. ```bash # For production use: docker-compose up --build # For development with file watching (auto-sync changes): docker-compose up --build --watch ``` -------------------------------- ### Create and Run an Agent with Local and MCP Tools Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/README.md Instantiate an agent with a name, system prompt, local tools, and optionally configure MCP servers for extended capabilities. This example shows how to integrate the `ThinkTool` and set up standard input/output communication with an MCP server. ```python from agents.agent import Agent from agents.tools.think import ThinkTool # Create an agent with both local tools and MCP server tools agent = Agent( name="MyAgent", system="You are a helpful assistant.", tools=[ThinkTool()], # Local tools mcp_servers=[ { "type": "stdio", "command": "python", "args": ["-m", "mcp_server"], }, ] ) # Run the agent response = agent.run("What should I consider when buying a new laptop?") ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/CONTRIBUTING.md Installs necessary packages for development using pip. ```bash pip install -r dev-requirements.txt ``` -------------------------------- ### Run Tool Panel Server Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Starts the tool panel server for manual tool execution. Open the provided URL in your browser to access the tool panel. ```bash python -m uvicorn dev_ui.tool_panel.server:app --reload # open http://127.0.0.1:8000 ``` -------------------------------- ### Install Claude Code and SDK Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/README.md Install the latest versions of Claude Code CLI and the Claude Agent SDK using npm and pip. ```bash # Install Claude Code CLI (latest version required) npm install -g @anthropic-ai/claude-code # Install Python dependencies pip install -r requirements.txt ``` -------------------------------- ### Install Headless Chromium Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Download the necessary headless Chromium browser for the browser tool. This is a one-time installation and requires approximately 150 MB. ```bash python -m playwright install chromium ``` -------------------------------- ### Browser Tool Setup Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/README.md Initializes the BrowserTool and defines its parameters, including name, description, and input schema. This is a foundational step for integrating browser automation capabilities. ```python browser_tool = BrowserTool() def to_params(self): return { "name": "browser", "description": BROWSER_TOOL_DESCRIPTION, "input_schema": BROWSER_TOOL_INPUT_SCHEMA, } ``` -------------------------------- ### Set Up Python Virtual Environment Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Creates and activates a Python virtual environment using a version of Python 3.11 or newer, then upgrades pip and installs project dependencies. ```bash # Replace `python3.13` with whatever 3.11+ interpreter you installed. python3.13 -m venv .venv source .venv/bin/activate python -m pip install --upgrade pip python -m pip install -r requirements.txt ``` -------------------------------- ### Manage Customer Support Agent Project Source: https://github.com/anthropics/claude-quickstarts/blob/main/CLAUDE.md Commands for installing dependencies, running the development server with various UI configurations, and building the project. ```bash npm install ``` ```bash npm run dev ``` ```bash npm run dev:left ``` ```bash npm run dev:right ``` ```bash npm run dev:chat ``` ```bash npm run lint ``` ```bash npm run build ``` -------------------------------- ### Verify Installations Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/README.md Verify that Claude Code CLI and the Claude Code SDK are installed correctly. ```bash claude --version # Should be latest version pip show claude-code-sdk # Check SDK is installed ``` -------------------------------- ### Manually Run Generated Application Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/README.md Manually install dependencies and run the generated application, typically for Node.js projects. ```bash cd generations/my_project # Or manually (typical for Node.js apps): npm install npm run dev ``` -------------------------------- ### Configure Computer Use with Environment Variables Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Demonstrates how to override configuration settings using environment variables for a specific command. This example disables browser tools and increases JPEG quality. ```bash # one-off: turn off browser tools and bump JPEG quality CU_ENABLE_BROWSER_USE_TOOLS=false CU_JPEG_QUALITY=85 \ python -m computer_use "open Notes and type hello" ``` -------------------------------- ### Set API Key Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Copies the example environment file and instructs to edit it, or alternatively, set the ANTHROPIC_API_KEY environment variable directly. ```bash cp .env.example .env # then edit .env # or: export ANTHROPIC_API_KEY=... ``` -------------------------------- ### Run Docker Container with Claude API Key Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/README.md This command starts the Docker container and sets the Anthropic API key. It maps several ports for accessing the demo app and VNC. ```bash export ANTHROPIC_API_KEY=%your_api_key% docker run \ -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ -v $HOME/.anthropic:/home/computeruse/.anthropic \ -p 5900:5900 \ -p 8501:8501 \ -p 6080:6080 \ -p 8080:8080 \ -it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest ``` -------------------------------- ### Initialize Project Environment Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/prompts/coding_prompt.md Execute the init.sh script if it exists to set up the development environment. Ensure it has execute permissions first. ```bash chmod +x init.sh ./init.sh ``` -------------------------------- ### Initialize Agent with Server Tools Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Initializes an agent named 'Server Tools Agent' with system instructions and a set of tools including web search, code execution, and a think tool. Configure the model with a specific name, max tokens, and temperature. ```python server_agent = Agent( name="Server Tools Agent", system=""" You are a helpful assistant with access to: 1. Web search for finding current information 2. Code execution for running Python code 3. Think tool for complex reasoning Use these tools effectively to answer questions that require current data or calculations. """, tools=[think_tool, web_search_tool, code_execution_tool], config=ModelConfig( model="claude-sonnet-4-20250514", max_tokens=4096, temperature=0.7 ), verbose=True ) ``` -------------------------------- ### Use TOML Configuration File Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Illustrates how to use a TOML configuration file by pointing the CU_CONFIG environment variable to it. This allows for persistent configuration overrides. ```bash # or keep a config.toml and point at it from .env # .env: # CU_CONFIG=config.toml # config.toml: # enable_advisor_tool = true # image_prune_strategy = "none" # extra_models = ["some-beta-model"] ``` -------------------------------- ### Initialize agent with combined tools Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Initializes the agent with a system prompt defining its capabilities and available tools. It includes standard tools and MCP servers for web search and calculation. ```python # Create agent config system_prompt = """ You are a helpful assistant with access to: 1. Web search (brave_web_search, brave_local_search) 2. Mathematical calculator (calculate) 3. A tool to think and reason (think) Always use the most appropriate tool for each task. """ # Initialize agent with standard tools and MCP servers agent = Agent( name="Multi-Tool Agent", system=system_prompt, tools=[think_tool], mcp_servers=[brave_search_server, calculator_server], config=ModelConfig( model="claude-3-7-sonnet-20250219", max_tokens=4096, temperature=1.0 ), verbose=True ) ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/CONTRIBUTING.md Sets up a Python virtual environment for development. Use 'source' on Unix-based systems and '.' on Windows. ```bash python -m venv .venv source .venv/bin/activate # On Unix # or .venv\Scripts\activate # On Windows ``` -------------------------------- ### Create Anthropic Server Tools Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Demonstrates the creation of Anthropic's native server tools for web search and code execution. Configure tool usage limits and block specific domains. ```python # Create Anthropic server tools web_search_tool = WebSearchServerTool( name="web_search", max_uses=5, # Limit to 5 searches per request blocked_domains=["example.com"] # Example of blocking specific domains ) code_execution_tool = CodeExecutionServerTool() ``` -------------------------------- ### Run Docker with Custom Screen Size Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/README.md Configures the demo application's screen resolution by setting WIDTH and HEIGHT environment variables. This is useful for testing different display sizes or adhering to recommended resolution limits. ```bash docker run \ -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \ -v $HOME/.anthropic:/home/computeruse/.anthropic \ -p 5900:5900 \ -p 8501:8501 \ -p 6080:6080 \ -p 8080:8080 \ -e WIDTH=1920 \ -e HEIGHT=1080 \ -it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest ``` -------------------------------- ### Display macOS Permission Prompt Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/dev_ui/tool_panel/static/index.html Conditionally displays a message and a dismiss button if required macOS permissions (screen recording or accessibility) are missing. The message guides the user on how to grant permissions. ```javascript p => { if (p.screen_recording && p.accessibility) return; const el = document.getElementById('preflight'); const missing = []; if (!p.screen_recording) missing.push('Screen Recording'); if (!p.accessibility) missing.push('Accessibility'); el.textContent = 'Missing macOS permissions: ' + missing.join(', ') + '. Grant them in System Settings > Privacy & Security, then restart this server.'; const btn = document.createElement('button'); btn.className = 'btn'; btn.textContent = 'dismiss'; btn.onclick = () => { el.style.display = 'none'; }; el.appendChild(btn); el.style.display = 'block'; } ``` -------------------------------- ### Configure tools and MCP servers Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Sets up a standard Python tool (ThinkTool) and configures MCP servers for a calculator and Brave Search. The calculator uses a local Python script, while Brave Search requires an API key and uses npx to run the server. ```python # Standard Python tool think_tool = ThinkTool() # Python MCP server calculator_server_path = os.path.abspath(os.path.join(os.getcwd(), "tools/calculator_mcp.py")) calculator_server = { "type": "stdio", "command": "python", "args": [calculator_server_path] } print(f"Calculator server configured: {'Yes' if calculator_server else 'No'}") # Brave MCP server written in TypeScript brave_api_key = os.environ.get("BRAVE_API_KEY_BASE_DATA", "") print(f"Brave API key available: {'Yes' if brave_api_key else 'No'}") brave_search_server = { "type": "stdio", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-brave-search"], "env": { "BRAVE_API_KEY": brave_api_key, "PATH": f"{os.path.dirname('npx')}:" + os.environ.get("PATH", "") } } print(f"Brave search server configured: {'Yes' if brave_search_server else 'No'}") ``` -------------------------------- ### Run Tests Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Execute the test suite for the computer use best practices. ```bash python -m pytest ``` -------------------------------- ### Initialize UI and Fetch Model Data Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/dev_ui/localization_demo/static/index.html Fetches model metadata, populates dropdowns for models and thinking efforts, and sets up the default prompt and tool definitions. This code runs when the page loads. ```javascript const $ = id => document.getElementById(id); let effortSupport = new Set(); let defaultPrompt = ''; async function populate() { const r = await fetch('/meta').then(r => r.json()); effortSupport = new Set(r.effort_supported_models); defaultPrompt = r.default_prompt_template; for (const m of r.models) { const o = document.createElement('option'); o.value = o.textContent = m; if (m === r.default_model) o.selected = true; $('model').appendChild(o); } for (const t of r.thinking_efforts) { const o = document.createElement('option'); o.value = o.textContent = t; $('effort').appendChild(o); } $('prompt').value = defaultPrompt; $('tooldef').textContent = JSON.stringify(r.point_at_tool, null, 2); syncEffort(); } populate(); ``` -------------------------------- ### Clone the repository Source: https://github.com/anthropics/claude-quickstarts/blob/main/financial-data-analyst/README.md Download the project source code from the official repository. ```bash git clone https://github.com/anthropics/anthropic-quickstarts.git cd anthropic-quickstarts/financial-data-analyst ``` -------------------------------- ### NPM Scripts for App Configurations Source: https://github.com/anthropics/claude-quickstarts/blob/main/customer-support-agent/README.md Use these scripts to run or build the application with specific sidebar configurations. They set environment variables to tailor the application's layout for development or production. ```bash npm run dev: Runs the full app with both sidebars (default) ``` ```bash npm run build: Builds the full app with both sidebars (default) ``` ```bash npm run dev:full: Same as npm run dev ``` ```bash npm run dev:left: Runs the app with only the left sidebar ``` ```bash npm run dev:right: Runs the app with only the right sidebar ``` ```bash npm run dev:chat: Runs the app with just the chat area (no sidebars) ``` ```bash npm run build:full: Same as npm run build ``` ```bash npm run build:left: Builds the app with only the left sidebar ``` ```bash npm run build:right: Builds the app with only the right sidebar ``` ```bash npm run build:chat: Builds the app with just the chat area (no sidebars) ``` -------------------------------- ### Run Demo with Limited Iterations Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/README.md Run the autonomous coding agent demo with a maximum number of iterations for testing purposes. ```bash python autonomous_agent_demo.py --project-dir ./my_project --max-iterations 3 ``` -------------------------------- ### Manage Financial Data Analyst Project Source: https://github.com/anthropics/claude-quickstarts/blob/main/CLAUDE.md Standard lifecycle commands for the Financial Data Analyst project. ```bash npm install ``` ```bash npm run dev ``` ```bash npm run lint ``` ```bash npm run build ``` -------------------------------- ### Build and Run Docker with Vertex AI Authentication Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/README.md Builds the Docker image and runs it using Google Cloud credentials for Vertex AI. It authenticates using Application Default Credentials and requires specifying the Vertex AI region and project ID. ```bash docker build . -t computer-use-demo gcloud auth application-default login export VERTEX_REGION=%your_vertex_region% export VERTEX_PROJECT_ID=%your_vertex_project_id% docker run \ -e API_PROVIDER=vertex \ -e CLOUD_ML_REGION=$VERTEX_REGION \ -e ANTHROPIC_VERTEX_PROJECT_ID=$VERTEX_PROJECT_ID \ -v $HOME/.config/gcloud/application_default_credentials.json:/home/computeruse/.config/gcloud/application_default_credentials.json \ -p 5900:5900 \ -p 8501:8501 \ -p 6080:6080 \ -p 8080:8080 \ -it computer-use-demo ``` -------------------------------- ### Run the Agent Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Executes the computer-use agent to perform a task, such as opening TextEdit and typing a message. ```bash python -m computer_use "open TextEdit and type hello world" ``` -------------------------------- ### Test and Lint Computer-Use Demo Source: https://github.com/anthropics/claude-quickstarts/blob/main/CLAUDE.md Standard commands for maintaining code quality and running tests in the Python-based computer-use demo. ```bash ruff check . ``` ```bash ruff format . ``` ```bash pyright ``` ```bash pytest ``` ```bash pytest tests/path_to_test.py::test_name -v ``` -------------------------------- ### Configure environment variables Source: https://github.com/anthropics/claude-quickstarts/blob/main/financial-data-analyst/README.md Set up the API key required for Anthropic service integration. ```env ANTHROPIC_API_KEY=your_api_key_here ``` -------------------------------- ### Run Autonomous Agent Demo Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/README.md Execute the autonomous coding agent demo script. Specify a project directory for the generated application. ```bash python autonomous_agent_demo.py --project-dir ./my_project ``` -------------------------------- ### Browser Automation Tools Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/prompts/coding_prompt.md These are the available tools for UI testing. Use them to interact with the application like a human user and verify functionality and appearance. ```bash puppeteer_navigate - Start browser and go to URL puppeteer_screenshot - Capture screenshot puppeteer_click - Click elements puppeteer_fill - Fill form inputs puppeteer_evaluate - Execute JavaScript (use sparingly, only for debugging) ``` -------------------------------- ### Run Agent for Information Retrieval and Calculation Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Uses the initialized agent to search for the current population of Tokyo and then execute Python code to calculate its population density per square kilometer, given its area. ```python # Example 1: Use web search to find current information and code execution for analysis server_agent.run(""" Search for the current population of Tokyo, Japan. Then write and execute Python code to calculate how many people that would be per square kilometer, given that Tokyo's area is approximately 2,194 square kilometers. """) ``` -------------------------------- ### Run Docker with AWS Profile Authentication Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/README.md Use this command to run the demo container when you want to leverage your existing AWS profile configuration. Ensure your AWS credentials file is correctly set up. ```bash export AWS_PROFILE= docker run \ -e API_PROVIDER=bedrock \ -e AWS_PROFILE=$AWS_PROFILE \ -e AWS_REGION=us-west-2 \ -v $HOME/.aws:/home/computeruse/.aws \ -v $HOME/.anthropic:/home/computeruse/.anthropic \ -p 5900:5900 \ -p 8501:8501 \ -p 6080:6080 \ -p 8080:8080 \ -it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest ``` -------------------------------- ### JavaScript: Run Tool and Display Results Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/dev_ui/tool_panel/static/index.html Sends a POST request to the '/run' endpoint with tool and input data. Displays execution status, results, and any errors. Renders batch results or content blocks, including images. ```javascript async function run(tool, input, delay) { const out = document.getElementById('out'); let remaining = delay; const tick = () => { out.textContent = remaining > 0 ? `running in ${remaining.toFixed(1)}s ...` : 'running ...'; }; tick(); const cd = delay > 0 ? setInterval(() => { remaining = Math.max(0, remaining - 0.1); tick(); }, 100) : null; const r = await fetch('/run', { method: 'POST', headers: {'content-type': 'application/json'}, body: JSON.stringify({tool, input, delay}), }).then(r => r.json()); if (cd) clearInterval(cd); lastMeta = r.meta || null; const head = {ms: r.ms, error: r.error, meta: r.meta}; out.textContent = JSON.stringify(head, null, 2); const imgDiv = document.getElementById('img'); imgDiv.innerHTML = ''; const batch = (r.meta && r.meta.batch_results) || null; if (batch && Array.isArray(batch)) { const ol = document.createElement('ol'); ol.className = 'batch'; for (const step of batch) { const li = document.createElement('li'); if (step.error) li.className = 'err'; const stepText = renderBlocks(step.content || [], li); const pre = document.createElement('pre'); pre.textContent = (step.error ? 'error: ' + step.error + '\n' : '') + stepText; li.prepend(pre); ol.appendChild(li); } imgDiv.appendChild(ol); } else { const text = renderBlocks(r.content || [], imgDiv); if (text) out.textContent += '\n' + text; } } ``` -------------------------------- ### Pin Browser Viewport via Environment Variable Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Sets a specific browser viewport size using an environment variable. The string value is automatically coerced into a tuple. ```bash # pin a viewport via env var (string is coerced to a tuple) CU_BROWSER_VIEWPORT=1280x720 python -m computer_use "..." ``` -------------------------------- ### Run Docker with AWS Access Key Authentication Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/README.md Use this command to run the demo container with explicit AWS access key, secret key, and session token. This is an alternative to using an AWS profile. ```bash export AWS_ACCESS_KEY_ID=%your_aws_access_key% export AWS_SECRET_ACCESS_KEY=%your_aws_secret_access_key% export AWS_SESSION_TOKEN=%your_aws_session_token% docker run \ -e API_PROVIDER=bedrock \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ -e AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \ -e AWS_REGION=us-west-2 \ -v $HOME/.anthropic:/home/computeruse/.anthropic \ -p 5900:5900 \ -p 8501:8501 \ -p 6080:6080 \ -p 8080:8080 \ -it ghcr.io/anthropics/anthropic-quickstarts:computer-use-demo-latest ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/anthropics/claude-quickstarts/blob/main/customer-support-agent/README.md Define required API keys in a .env.local file. Note the 'B' prefix used for AWS variables. ```text ANTHROPIC_API_KEY=your_anthropic_api_key BAWS_ACCESS_KEY_ID=your_aws_access_key BAWS_SECRET_ACCESS_KEY=your_aws_secret_key ``` -------------------------------- ### Render Tool Cards from Fetch Data Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/dev_ui/tool_panel/static/index.html Fetches tool definitions from a '/tools' endpoint and dynamically renders interactive cards for each tool. Each card includes the tool's name, description, input fields, and a 'run' button with a delay setting. ```javascript fetch('/tools').then(r => r.json()).then(tools => { const root = document.getElementById('tools'); for (const t of tools) { const card = document.createElement('div'); card.className = 'card'; card.innerHTML = `

${t.name}

` + `
description

${t.description}

`; for (const [k, spec] of Object.entries(t.input_schema.properties || {})) card.appendChild(fieldFor(k, spec)); const row = document.createElement('div'); row.className = 'row'; const delay = document.createElement('input'); delay.type = 'number'; delay.value = '3'; delay.title = 'delay (s)'; const btn = document.createElement('button'); btn.className = 'btn'; btn.textContent = 'run'; btn.onclick = () => run(t.name, collect(card), parseFloat(delay.value) || 0); row.append('delay:', delay, btn); card.appendChild(row); root.appendChild(card); } }); ``` -------------------------------- ### Handle Image File Setting Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/dev_ui/localization_demo/static/index.html Sets the selected image file for preview and display. It creates a DataTransfer object to set the file and updates the image source and filename display. Also handles adding a 'has-file' class to the drop zone. ```javascript function setFile(file) { if (!file) return; const dt = new DataTransfer(); dt.items.add(file); $('image').files = dt.files; $('preview').src = URL.createObjectURL(file); $('filename').textContent = `${file.name} (${(file.size/1024).toFixed(0)} KB)`; $('drop').classList.add('has-file'); } $('image').addEventListener('change', e => setFile(e.target.files[0])); ``` -------------------------------- ### Test Directory Structure Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/tests/README.md Overview of the project's test file organization. ```text tests/ ├── conftest.py # Shared fixtures and mocks ├── test_message_renderer.py # MessageRenderer class tests (~300 test cases) ├── test_streamlit_helpers.py # Helper function tests (~150 test cases) └── test_integration.py # End-to-end integration tests (~50 test cases) ``` -------------------------------- ### Run Ruff for Linting and Formatting Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/CONTRIBUTING.md Commands to check code for linting errors and format the code using Ruff. ```bash ruff check . ruff format . ``` -------------------------------- ### Layout Styling for Computer Use Demo Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-demo/image/static_content/index.html Defines the CSS for a full-screen split layout with two side-by-side iframes. ```css body { margin: 0; padding: 0; overflow: hidden; } .container { display: flex; height: 100vh; width: 100vw; } .left { flex: 1; border: none; height: 100vh; } .right { flex: 2; border: none; height: 100vh; } ``` -------------------------------- ### Open Screen Recording Permissions Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Opens the macOS System Settings pane for Screen Recording permissions. This is required for the agent to take screenshots. ```bash open "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture" ``` -------------------------------- ### Run CI Test Pipeline Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/tests/README.md Commands for executing tests and generating coverage reports in a CI environment. ```bash # Install dependencies pip install -e ".[test]" # Run tests with coverage pytest tests/ --cov=browser_tools_api_demo --cov-report=xml --cov-report=term # Generate coverage badge coverage-badge -o coverage.svg ``` -------------------------------- ### View Trajectory with Streamlit Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Launches the trajectory viewer using Streamlit, which allows for inspecting past agent runs as chat transcripts with tool calls and results. ```bash python -m streamlit run dev_ui/trajectory_viewer/app.py ``` -------------------------------- ### Settings API Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/prompts/app_spec.txt Endpoints for managing user and application settings. ```APIDOC ## GET /api/settings ### Description Retrieves the current user settings. ### Method GET ### Endpoint /api/settings ## PUT /api/settings ### Description Updates the current user settings. ### Method PUT ### Endpoint /api/settings ## GET /api/settings/custom-instructions ### Description Retrieves custom instructions for the user. ### Method GET ### Endpoint /api/settings/custom-instructions ## PUT /api/settings/custom-instructions ### Description Updates custom instructions for the user. ### Method PUT ### Endpoint /api/settings/custom-instructions ``` -------------------------------- ### Commit Development Progress Source: https://github.com/anthropics/claude-quickstarts/blob/main/autonomous-coding/prompts/coding_prompt.md Create a descriptive git commit message detailing the implemented feature, verification steps, and changes made. Include specific details about the implementation and testing. ```bash git add . git commit -m "Implement [feature name] - verified end-to-end - Added [specific changes] - Tested with browser automation - Updated feature_list.json: marked test #X as passing - Screenshots in verification/ directory " ``` -------------------------------- ### Execute Test Suite Source: https://github.com/anthropics/claude-quickstarts/blob/main/browser-use-demo/tests/README.md Commands to run tests using pytest with various options for coverage and granularity. ```bash pytest tests/ ``` ```bash pytest tests/ --cov=browser_tools_api_demo --cov-report=html # Open htmlcov/index.html to view coverage report ``` ```bash pytest tests/test_message_renderer.py -v ``` ```bash pytest tests/test_message_renderer.py::TestMessageRenderer -v pytest tests/test_message_renderer.py::TestRenderMethod::test_render_string_message -v ``` ```bash # Run only integration tests pytest -m integration # Run tests excluding integration pytest -m "not integration" # Run async tests pytest -m asyncio ``` -------------------------------- ### Run Agent Query Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Use the agent.run() method to execute a natural language query. The agent will determine the necessary tools and steps to fulfill the request. ```python agent.run("What's the square root of the OKC population in 2022") ``` -------------------------------- ### Open Accessibility Permissions Source: https://github.com/anthropics/claude-quickstarts/blob/main/computer-use-best-practices/README.md Opens the macOS System Settings pane for Accessibility permissions. This is required for the agent to control the mouse and keyboard. ```bash open "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility" ``` -------------------------------- ### Import necessary libraries Source: https://github.com/anthropics/claude-quickstarts/blob/main/agents/agent_demo.ipynb Imports required libraries for agent functionality, including system path manipulation and specific tool modules. Applies nest_asyncio to handle nested asyncio loops. ```python import os import sys import nest_asyncio nest_asyncio.apply() parent_dir = os.path.dirname(os.getcwd()) sys.path.insert(0, parent_dir) from agents.agent import Agent, ModelConfig from agents.tools.think import ThinkTool from agents.tools.web_search import WebSearchServerTool from agents.tools.code_execution import CodeExecutionServerTool ```