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 |
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
list-workspaces
List all open workspaces.
cmux list-workspaces
cmux list-workspaces --json{"command": "list-workspaces"}new-workspace
Create a new workspace.
cmux new-workspace{"command": "new-workspace"}select-workspace
Switch to a specific workspace.
cmux select-workspace --workspace <id>{"command": "select-workspace", "id": "<id>"}current-workspace
Get the currently active workspace.
cmux current-workspace
cmux current-workspace --json{"command": "current-workspace"}close-workspace
Close a workspace.
cmux close-workspace --workspace <id>{"command": "close-workspace", "id": "<id>"}Split commands
new-split
Create a new split pane. Directions: left, right, up, down.
cmux new-split right
cmux new-split down{"command": "new-split", "direction": "right"}list-surfaces
List all surfaces in the current workspace.
cmux list-surfaces
cmux list-surfaces --json{"command": "list-surfaces"}focus-surface
Focus a specific surface.
cmux focus-surface --surface <id>{"command": "focus-surface", "id": "<id>"}Input commands
send
Send text input to the focused terminal.
cmux send "echo hello"
cmux send "ls -la\n"{"command": "send", "text": "echo hello\n"}send-key
Send a key press. Keys: enter, tab, escape, backspace, delete, up, down, left, right.
cmux send-key enter{"command": "send-key", "key": "enter"}send-surface
Send text to a specific surface.
cmux send-surface --surface <id> "command"{"command": "send-surface", "id": "<id>", "text": "command"}send-key-surface
Send a key press to a specific surface.
cmux send-key-surface --surface <id> enter{"command": "send-key-surface", "id": "<id>", "key": "enter"}Notification commands
notify
Send a notification.
cmux notify --title "Title" --body "Body"
cmux notify --title "T" --subtitle "S" --body "B"{"command": "notify", "title": "Title",
"subtitle": "S", "body": "Body"}list-notifications
List all notifications.
cmux list-notifications
cmux list-notifications --json{"command": "list-notifications"}clear-notifications
Clear all notifications.
cmux clear-notifications{"command": "clear-notifications"}Utility commands
ping
Check if cmux is running and responsive.
cmux ping{"command": "ping"}
// Response: {"success": true, "pong": true}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 |
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