import type { Metadata } from "next"; import { CodeBlock } from "../../components/code-block"; import { Callout } from "../../components/callout"; export const metadata: Metadata = { title: "API Reference", description: "CLI and socket API reference for cmux", }; 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

Override with the CMUX_SOCKET_PATH environment variable. Commands are newline-terminated JSON:

{`{"command": "command-name", "arg1": "value1"} // Response: {"success": true, "data": {...}}`}

Access modes

Mode Description
Off Socket disabled
Notifications only Only notification commands allowed
Full control All commands enabled
On shared machines, use “Notifications only” mode to prevent other users from controlling your terminals.

CLI options

Flag Description
--socket PATH Custom socket path
--json Output in JSON format
--workspace ID Target a specific workspace
--surface ID Target a specific surface

Workspace commands

`} socket={`{"command": "select-workspace", "id": ""}`} /> `} socket={`{"command": "close-workspace", "id": ""}`} />

Split commands

`} socket={`{"command": "focus-surface", "id": ""}`} />

Input commands

"command"`} socket={`{"command": "send-surface", "id": "", "text": "command"}`} /> enter`} socket={`{"command": "send-key-surface", "id": "", "key": "enter"}`} />

Notification commands

Utility commands

Environment variables

Variable Description
CMUX_SOCKET_PATH Override the default socket path
CMUX_SOCKET_ENABLE Enable/disable socket (1/0)
CMUX_SOCKET_MODE Override access mode (full,{" "} notifications, off)
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
Environment variables override app settings. Use the socket check to distinguish cmux from regular Ghostty.

Detecting cmux

{`# Check for the socket [ -S /tmp/cmux.sock ] && echo "In cmux" # Check for the CLI command -v cmux &>/dev/null && echo "cmux available" # Distinguish from regular Ghostty [ "$TERM_PROGRAM" = "ghostty" ] && [ -S /tmp/cmux.sock ] && echo "In cmux"`}

Examples

Python client

{`import socket, json def send_command(cmd): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect('/tmp/cmux.sock') sock.send(json.dumps(cmd).encode() + b'\\n') response = sock.recv(4096).decode() sock.close() return json.loads(response) # List workspaces print(send_command({"command": "list-workspaces"})) # Send notification send_command({ "command": "notify", "title": "Hello", "body": "From Python!" })`}

Shell script

{`#!/bin/bash cmux_cmd() { echo "$1" | nc -U /tmp/cmux.sock } cmux_cmd '{"command": "list-workspaces"}' cmux_cmd '{"command": "notify", "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`} ); }