import type { Metadata } from "next"; import { CodeBlock } from "../../components/code-block"; import { Callout } from "../../components/callout"; export const metadata: Metadata = { title: "API Reference", description: "cmux CLI and Unix socket API reference. Workspace management, split panes, input control, notifications, sidebar metadata (status, progress, logs), environment variables, and detection methods.", }; function Cmd({ name, desc, cli, socket, }: { name: string; desc: string; cli: string; socket: string; }) { return (

{name}

{desc}

{cli} {socket}
); } export default function ApiPage() { return ( <>

API Reference

cmux provides both a CLI tool and a Unix socket for programmatic control. Every command is available through both interfaces.

Socket

Build Path
Release /tmp/cmux.sock
Debug /tmp/cmux-debug.sock
Tagged debug build /tmp/cmux-debug-<tag>.sock

Override with the CMUX_SOCKET_PATH environment variable. Send one newline-terminated JSON request per call:

{`{"id":"req-1","method":"workspace.list","params":{}} // Response: {"id":"req-1","ok":true,"result":{"workspaces":[...]}}`} JSON socket requests must use method and{" "} params. Legacy v1 JSON payloads such as{" "} {`{"command":"..."}`} are not supported.

Access modes

Mode Description How to enable
Off Socket disabled Settings UI or CMUX_SOCKET_MODE=off
cmux processes only Only processes spawned inside cmux terminals can connect. Default mode in Settings UI
allowAll Allow any local process to connect (no ancestry check). Environment override only: CMUX_SOCKET_MODE=allowAll
On shared machines, use Off or{" "} cmux processes only.

CLI options

Flag Description
--socket PATH Custom socket path
--json Output in JSON format
--window ID Target a specific window
--workspace ID Target a specific workspace
--surface ID Target a specific surface
--id-format refs|uuids|both Control identifier format in JSON output

Workspace commands

`} socket={`{"id":"ws-select","method":"workspace.select","params":{"workspace_id":""}}`} /> `} socket={`{"id":"ws-close","method":"workspace.close","params":{"workspace_id":""}}`} />

Split commands

`} socket={`{"id":"surface-focus","method":"surface.focus","params":{"surface_id":""}}`} />

Input commands

"command"`} socket={`{"id":"send-surface","method":"surface.send_text","params":{"surface_id":"","text":"command"}}`} /> enter`} socket={`{"id":"send-key-surface","method":"surface.send_key","params":{"surface_id":"","key":"enter"}}`} />

Notification commands

Sidebar metadata commands

Set status pills, progress bars, and log entries in the sidebar for any workspace. Useful for build scripts, CI integrations, and AI coding agents that want to surface state at a glance.

`} /> `} /> `} /> `} /> `} /> -- Compilation failed`} /> `} /> `} /> `} />

Utility commands

Environment variables

Variable Description
CMUX_SOCKET_PATH Override the socket path used by CLI and integrations
CMUX_SOCKET_ENABLE Force-enable/disable socket (1/0,{" "} true/false, on/ off)
CMUX_SOCKET_MODE Override access mode (cmuxOnly,{" "} allowAll, off). Also accepts{" "} cmux-only/cmux_only and{" "} allow-all/allow_all
CMUX_WORKSPACE_ID Auto-set: current workspace ID
CMUX_SURFACE_ID Auto-set: current surface ID
TERM_PROGRAM Set to ghostty
TERM Set to xterm-ghostty
Legacy CMUX_SOCKET_MODE values full and{" "} notifications are still accepted for compatibility.

Detecting cmux

{`# Prefer explicit socket path if set SOCK="\${CMUX_SOCKET_PATH:-/tmp/cmux.sock}" [ -S "$SOCK" ] && echo "Socket available" # Check for the CLI command -v cmux &>/dev/null && echo "cmux available" # In cmux-managed terminals these are auto-set [ -n "\${CMUX_WORKSPACE_ID:-}" ] && [ -n "\${CMUX_SURFACE_ID:-}" ] && echo "Inside cmux surface" # Distinguish from regular Ghostty [ "$TERM_PROGRAM" = "ghostty" ] && [ -n "\${CMUX_WORKSPACE_ID:-}" ] && echo "In cmux"`}

Examples

Python client

{`import json import os import socket SOCKET_PATH = os.environ.get("CMUX_SOCKET_PATH", "/tmp/cmux.sock") def rpc(method, params=None, req_id=1): payload = {"id": req_id, "method": method, "params": params or {}} with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: sock.connect(SOCKET_PATH) sock.sendall(json.dumps(payload).encode("utf-8") + b"\\n") return json.loads(sock.recv(65536).decode("utf-8")) # List workspaces print(rpc("workspace.list", req_id="ws")) # Send notification print(rpc( "notification.create", {"title": "Hello", "body": "From Python!"}, req_id="notify" ))`}

Shell script

{`#!/bin/bash SOCK="\${CMUX_SOCKET_PATH:-/tmp/cmux.sock}" cmux_cmd() { printf "%s\\n" "$1" | nc -U "$SOCK" } cmux_cmd '{"id":"ws","method":"workspace.list","params":{}}' cmux_cmd '{"id":"notify","method":"notification.create","params":{"title":"Done","body":"Task complete"}}'`}

Build script with notification

{`#!/bin/bash npm run build if [ $? -eq 0 ]; then cmux notify --title "✓ Build Success" --body "Ready to deploy" else cmux notify --title "✗ Build Failed" --body "Check the logs" fi`} ); }