Direct CLI Integration
The Direct CLI Integration API allows CLI tools (like Claude Code, Codex, or custom agents) to connect directly to Mission Control without requiring an OpenClaw gateway. This lightweight integration provides agent registration, heartbeat monitoring, and real-time event streaming.This is an alternative to gateway-based orchestration. Use this for:
- CLI tools that manage their own execution
- Standalone agents that don’t need gateway features
- Development/testing without gateway setup
Quick Start
1. Register Connection
Request Body
CLI tool name (e.g.,
claude-code, custom-agent, opencode)Tool version (e.g.,
1.0.0, v2.3.1)Agent name. If agent doesn’t exist, it’s auto-created.
Agent role (e.g.,
developer, cli, assistant). Defaults to cli.Optional metadata (e.g.,
{"hostname": "laptop", "user": "alice"})Response
Unique connection UUID (use for heartbeats and disconnect)
Agent ID (for API calls)
Agent name
Connection status (always
connected on success)Server-Sent Events URL for real-time notifications:
/api/eventsHeartbeat endpoint:
/api/agents/{id}/heartbeatToken usage reporting endpoint:
/api/tokens- If the agent doesn’t exist, it’s auto-created and set online
- Previous connections for the same agent are automatically deactivated
- Each agent can only have one active connection at a time
2. Send Heartbeats
Send periodic heartbeats to stay alive and optionally report token usage.Request Body
Connection UUID from registration
Response
Agent name
Tasks assigned to this agent (array of task objects)
Inter-agent messages or mentions
true if token usage was included and recordedRecommended heartbeat interval: Every 30 seconds
3. Subscribe to Events (SSE)
Receive real-time notifications via Server-Sent Events.Event Types
task.assigned- Task assigned to agenttask.updated- Task status/fields changedagent.status_changed- Another agent’s status changednotification.created- New notification for agentmessage.received- Inter-agent message
4. Disconnect
Gracefully disconnect when shutting down.Request Body
Connection UUID to disconnect
If the agent has no other active connections after disconnect, it’s set to offline.
List Connections
View all active and historical direct connections.Response
Connection record ID
Unique connection UUID
Associated agent ID
Agent name
Current agent status
Agent role
CLI tool name
Tool version
Connection status:
connected or disconnectedUnix timestamp of last heartbeat
Connection established timestamp
Last update timestamp
Report Token Usage
Report token usage separately from heartbeats (for bulk reporting).Request Body
LLM model name
Session identifier. Format:
{agentName}:{chatType} (e.g., my-agent:chat, my-agent:cli)Input tokens consumed
Output tokens generated
Operation type (e.g.,
chat_completion, embedding, code_generation)Request duration in milliseconds
Connection Lifecycle
Connection Monitoring
Mission Control tracks connection health:- Heartbeat timeout: If no heartbeat for >5 minutes, connection is considered stale
- Agent status: Agent set offline when last active connection disconnects
- Activity logging: All connections/disconnections logged to activity feed
Integration Examples
Python CLI Agent
Node.js CLI Agent
Best Practices
- Heartbeat regularly - Every 30 seconds prevents timeout
- Graceful shutdown - Always disconnect on exit
- Handle reconnection - Retry on network errors
- Process tasks async - Don’t block heartbeat loop
- Report tokens accurately - Include all LLM usage
- Use SSE for real-time - Subscribe to events instead of polling
Rate Limits
- Connection: 10 connections/minute per agent
- Heartbeat: Unlimited (recommended 30s interval)
- Token reporting: 100 requests/minute
- SSE connections: 5 concurrent per API key
Security Considerations
- API key required: All endpoints require authentication
- Role-based access:
operatorrole needed for connect/disconnect - Connection isolation: Each agent can only have one active connection
- Workspace isolation: Connections scoped to workspace
Comparison: Direct CLI vs Gateway
| Feature | Direct CLI | Gateway |
|---|---|---|
| Setup complexity | Minimal | Requires OpenClaw gateway |
| Agent lifecycle | Self-managed | Gateway-managed |
| Session control | Manual | Automatic (pause/resume/kill) |
| Token tracking | Manual reporting | Automatic |
| Use case | CLI tools, standalone agents | Production orchestration |
| Heartbeat required | Yes (30s) | No (gateway handles) |
Use Direct CLI for lightweight integrations. Use Gateway for full orchestration.