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
string
required
CLI tool name (e.g.,
claude-code, custom-agent, opencode)string
Tool version (e.g.,
1.0.0, v2.3.1)string
required
Agent name. If agent doesn’t exist, it’s auto-created.
string
Agent role (e.g.,
developer, cli, assistant). Defaults to cli.object
Optional metadata (e.g.,
{"hostname": "laptop", "user": "alice"})Response
string
Unique connection UUID (use for heartbeats and disconnect)
integer
Agent ID (for API calls)
string
Agent name
string
Connection status (always
connected on success)string
Server-Sent Events URL for real-time notifications:
/api/eventsstring
Heartbeat endpoint:
/api/agents/{id}/heartbeatstring
Token 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
string
required
Connection UUID from registration
object
Response
string
Agent name
array
Tasks assigned to this agent (array of task objects)
array
Inter-agent messages or mentions
boolean
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
string
required
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
array
integer
Connection record ID
string
Unique connection UUID
integer
Associated agent ID
string
Agent name
string
Current agent status
string
Agent role
string
CLI tool name
string
Tool version
string
Connection status:
connected or disconnectedinteger
Unix timestamp of last heartbeat
integer
Connection established timestamp
integer
Last update timestamp
Report Token Usage
Report token usage separately from heartbeats (for bulk reporting).Request Body
string
required
LLM model name
string
required
Session identifier. Format:
{agentName}:{chatType} (e.g., my-agent:chat, my-agent:cli)integer
required
Input tokens consumed
integer
required
Output tokens generated
string
default:"chat_completion"
Operation type (e.g.,
chat_completion, embedding, code_generation)number
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
Use Direct CLI for lightweight integrations. Use Gateway for full orchestration.