Skip to main content

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/events
string
Heartbeat endpoint: /api/agents/{id}/heartbeat
string
Token usage reporting endpoint: /api/tokens
Example Response:
  • 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
Optional token usage report
string
required
LLM model name (e.g., claude-sonnet-4, gpt-4)
integer
required
Input tokens consumed
integer
required
Output tokens generated

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 recorded
Recommended 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 agent
  • task.updated - Task status/fields changed
  • agent.status_changed - Another agent’s status changed
  • notification.created - New notification for agent
  • message.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 disconnected
integer
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

  1. Heartbeat regularly - Every 30 seconds prevents timeout
  2. Graceful shutdown - Always disconnect on exit
  3. Handle reconnection - Retry on network errors
  4. Process tasks async - Don’t block heartbeat loop
  5. Report tokens accurately - Include all LLM usage
  6. 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: operator role needed for connect/disconnect
  • Connection isolation: Each agent can only have one active connection
  • Workspace isolation: Connections scoped to workspace
Do not share connection IDs. They grant agent control permissions.

Comparison: Direct CLI vs Gateway

Use Direct CLI for lightweight integrations. Use Gateway for full orchestration.