How It Works
Constclaw follows a two-layer architecture: a thin browser extension client and a local AI gateway. No data leaves your machine unless you explicitly configure a remote provider.
High-level overview
The extension captures text selections, sends them over WebSocket to your local OpenClaw gateway, and renders the AI response in Chrome's side panel. The gateway handles provider routing, authentication, and model orchestration.
┌─────────────────────────────────────────────────────────────┐
│ Chrome Browser │
│ │
│ ┌──────────────┐ chrome.runtime ┌────────────────┐ │
│ │ content.js │───────────────────▶│ background.js │ │
│ │ (selection) │ │ (service worker)│ │
│ └──────┬─────────┘ └────────┬───────┘ │
│ │ │ │
│ │ chrome.runtime.sendMessage │ │
│ ▼ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ sidepanel.js │ │
│ │ • Renders selected text │ │
│ │ • Mode selector (5 modes) │ │
│ │ • WebSocket client → gateway │ │
│ │ • Query history (chrome.storage.local) │ │
│ └─────────────────────┬───────────────────────────────┘ │
│ │ │
└─────────────────────────┼────────────────────────────────────┘
│ WebSocket (ws://127.0.0.1:18789)
▼
┌──────────────────────────┐
│ OpenClaw Gateway │
│ │
│ • Protocol handshake │
│ • Auth / token check │
│ • Provider routing │
│ • Rate limiting │
└────────────┬──────────────┘
│ HTTPS
▼
┌──────────────────────────┐
│ AI Model Provider │
│ │
│ Anthropic (Claude) │
│ OpenAI (GPT) │
│ Local (Ollama, etc.) │
└──────────────────────────┘
Extension components
Constclaw is a Manifest V3 Chrome extension with three main scripts:
content.js Content Script
Injected into every webpage. Listens for mouseup events,
detects text selection, and shows the floating "Ask Constclaw" button.
Sends the selected text to the side panel via chrome.runtime.sendMessage.
background.js Service Worker
Registers the context menu item ("Ask Constclaw"). Relays messages
between content scripts and the side panel. Manages side panel
lifecycle with chrome.sidePanel.open().
sidepanel.js Side Panel
The main UI controller. Manages the WebSocket connection to OpenClaw,
implements the gateway protocol, renders
AI responses, and stores query history in chrome.storage.local.
Data flow
Here's the step-by-step flow from text selection to AI response:
Prompt construction
Each analysis mode uses a purpose-built system prompt. The extension wraps the user's selected text with mode-specific instructions before sending it to the gateway:
Security model
The extension connects to 127.0.0.1 only. No external requests unless you configure a remote gateway.
Set OPENCLAW_GATEWAY_TOKEN to require authentication on the gateway connection.
Query history uses chrome.storage.local — never synced, never uploaded.
AI provider keys live in the OpenClaw config, not in the extension. The extension has no access to them.