Clawdbot Gateway
The Clawdbot Gateway is the always-on service that manages messaging connections, agent runtime, and the control plane for your AI assistant.
Clawdbot Gateway Overview
The Clawdbot Gateway is the always-on process that owns messaging connections (WhatsApp via Baileys, Telegram via grammY, Discord, Slack, and more) and the control/event plane. It's the core service that keeps your Clawdbot AI assistant running 24/7.
What is the Gateway?
The Gateway is a single long-lived daemon that:
- Maintains all messaging provider connections
- Exposes a typed WebSocket API for requests, responses, and server-push events
- Validates inbound frames against JSON Schema
- Emits events like
agent,chat,presence,health,heartbeat,cron
Key principle: One Gateway per host; it is the only place that opens messaging sessions (like WhatsApp).
Quick Start
Start the Gateway
clawdbot gateway --port 18789For full debug/trace logs:
clawdbot gateway --port 18789 --verboseIf the port is busy, terminate listeners then start:
clawdbot gateway --forceDevelopment Mode
For development with auto-reload on TypeScript changes:
pnpm gateway:watchGateway Architecture
Components
| Component | Description |
|---|---|
| Gateway (daemon) | Maintains provider connections, exposes WS API |
| Clients | macOS app, CLI, web UI connect via WebSocket |
| Nodes | macOS/iOS/Android/headless devices with role: node |
| WebChat | Static UI using Gateway WS API |
| Canvas Host | Serves agent-editable HTML (default port 18793) |
Connection Flow
Client Gateway
| |
|---- req:connect -------->|
|<------ res (ok) ---------|
| |
|<------ event:presence ---|
|<------ event:tick -------|
| |
|------- req:agent ------->|
|<------ res:agent --------|
|<------ event:agent ------|Gateway Configuration
Basic Configuration
Config file location: ~/.clawdbot/clawdbot.json
{
"gateway": {
"port": 18789,
"auth": {
"token": "your-secret-token"
},
"reload": {
"mode": "hybrid"
}
}
}Port Configuration
Port precedence:
--portCLI flagCLAWDBOT_GATEWAY_PORTenvironment variablegateway.portin config- Default: 18789
Authentication
Gateway auth is required by default. Set via:
gateway.auth.tokenin configCLAWDBOT_GATEWAY_TOKENenvironment variablegateway.auth.passwordfor password-based auth
Clients must send connect.params.auth.token or connect.params.auth.password.
Hot Reload
Config hot reload watches ~/.clawdbot/clawdbot.json:
| Mode | Description |
|---|---|
hybrid (default) | Hot-apply safe changes, restart on critical |
off | Disable hot reload |
Gateway Services
HTTP Endpoints
The Gateway serves multiple HTTP endpoints on the same port:
| Endpoint | Description |
|---|---|
/v1/chat/completions | OpenAI Chat Completions compatible |
/v1/responses | OpenResponses API |
/tools/invoke | Tools invocation |
| Control UI | Web-based dashboard |
Canvas Host
Starts by default on port 18793, serving:
http://<gateway-host>:18793/__clawdbot__/canvas/From ~/.clawdbot/workspace/canvas. Disable with:
canvasHost.enabled: falseCLAWDBOT_SKIP_CANVAS_HOST=1
Dashboard
Access the Control UI at:
http://127.0.0.1:18789/Or run:
clawdbot dashboardRemote Access
SSH Tunnel (Recommended)
ssh -N -L 18789:127.0.0.1:18789 user@hostClients then connect to ws://127.0.0.1:18789 through the tunnel.
Tailscale/VPN
Preferred for production remote access. The same handshake + auth token apply.
Gateway Management
Service Commands
# Check status
clawdbot gateway status
# Health check
clawdbot health
# Security audit
clawdbot security audit --deep
# Stop gateway
clawdbot gateway stopSupervision
macOS: Uses LaunchAgent (bot.molt.<profile>)
Linux: Uses systemd user service (clawdbot-gateway-<profile>.service)
Windows: Uses Windows Service (Clawdbot Gateway (<profile>))
Multiple Gateways
Usually unnecessary—one Gateway can serve multiple channels and agents. Use multiple Gateways only for:
- Redundancy
- Strict isolation (e.g., rescue bot)
Requirements:
- Isolate state + config
- Use unique ports
Wire Protocol
Transport
- WebSocket with text frames containing JSON payloads
- First frame must be
connect
Message Types
Requests:
{"type": "req", "id": "...", "method": "...", "params": {...}}Responses:
{"type": "res", "id": "...", "ok": true, "payload": {...}}Events:
{"type": "event", "event": "...", "payload": {...}, "seq": 1}Idempotency
Idempotency keys are required for side-effecting methods (send, agent) to safely retry.
Troubleshooting
Gateway Won't Start
- Check if port is in use:
lsof -i :18789 - Review logs:
cat /tmp/clawdbot/gateway.log - Use
--forceto terminate existing listeners
Connection Issues
- Verify auth token matches
- Check network connectivity
- Review WebSocket handshake logs with
--verbose
Channel Problems
- Check channel status:
clawdbot channels status - Re-authenticate channels:
clawdbot channels login - Review channel-specific logs
Best Practices
- Use Auth Tokens: Always configure
gateway.auth.tokenfor security - Monitor Health: Regularly check
clawdbot health - Use Supervision: Let launchd/systemd manage restarts
- Backup Config: Keep backups of
~/.clawdbot/clawdbot.json - Review Logs: Check logs regularly for issues
Next Steps
- Clawdbot Setup Guide - Complete installation guide
- Clawdbot WhatsApp Integration - Connect to WhatsApp
- Clawdbot Telegram Integration - Connect to Telegram