เอกสาร API

cmux มีทั้งเครื่องมือ CLI และ Unix socket สำหรับการควบคุมแบบโปรแกรม ทุกคำสั่งพร้อมใช้งานผ่านทั้งสองอินเทอร์เฟซ

Socket

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

Override ด้วยตัวแปรสภาพแวดล้อม CMUX_SOCKET_PATH ส่ง JSON request ที่จบด้วย newline หนึ่งรายการต่อการเรียก:

{"id":"req-1","method":"workspace.list","params":{}}
// Response:
{"id":"req-1","ok":true,"result":{"workspaces":[...]}}
JSON socket request ต้องใช้ method และ params Legacy v1 JSON payload เช่น {"command":"..."} ไม่รองรับ

โหมดการเข้าถึง

โหมดคำอธิบายวิธีเปิดใช้งาน
Offปิด socketSettings UI หรือ CMUX_SOCKET_MODE=off
cmux processes onlyเฉพาะโปรเซสที่เกิดภายในเทอร์มินัล cmux เท่านั้นที่เชื่อมต่อได้โหมดเริ่มต้นใน Settings UI
allowAllอนุญาตให้โปรเซสในเครื่องใดก็ได้เชื่อมต่อ (ไม่ตรวจสอบ ancestry)Override ผ่าน environment เท่านั้น: CMUX_SOCKET_MODE=allowAll
บนเครื่องที่ใช้ร่วมกัน ใช้ Off หรือ cmux processes only

ตัวเลือก CLI

Flagคำอธิบาย
--socket PATHกำหนด socket path เอง
--jsonแสดงผลในรูปแบบ JSON
--window IDระบุหน้าต่างเป้าหมาย
--workspace IDระบุ workspace เป้าหมาย
--surface IDระบุ surface เป้าหมาย
--id-format refs|uuids|bothควบคุมรูปแบบ identifier ในเอาต์พุต JSON

คำสั่ง workspace

list-workspaces

แสดงรายการ workspace ที่เปิดอยู่ทั้งหมด

CLI
cmux list-workspaces
cmux list-workspaces --json
Socket
{"id":"ws-list","method":"workspace.list","params":{}}

new-workspace

สร้าง workspace ใหม่

CLI
cmux new-workspace
Socket
{"id":"ws-new","method":"workspace.create","params":{}}

select-workspace

สลับไปยัง workspace ที่ระบุ

CLI
cmux select-workspace --workspace <id>
Socket
{"id":"ws-select","method":"workspace.select","params":{"workspace_id":"<id>"}}

current-workspace

รับ workspace ที่ใช้งานอยู่ปัจจุบัน

CLI
cmux current-workspace
cmux current-workspace --json
Socket
{"id":"ws-current","method":"workspace.current","params":{}}

close-workspace

ปิด workspace

CLI
cmux close-workspace --workspace <id>
Socket
{"id":"ws-close","method":"workspace.close","params":{"workspace_id":"<id>"}}

คำสั่งแยกหน้าจอ

new-split

สร้างพาเนลแยกใหม่ ทิศทาง: left, right, up, down

CLI
cmux new-split right
cmux new-split down
Socket
{"id":"split-new","method":"surface.split","params":{"direction":"right"}}

list-surfaces

แสดงรายการ surface ทั้งหมดใน workspace ปัจจุบัน

CLI
cmux list-surfaces
cmux list-surfaces --json
Socket
{"id":"surface-list","method":"surface.list","params":{}}

focus-surface

โฟกัส surface ที่ระบุ

CLI
cmux focus-surface --surface <id>
Socket
{"id":"surface-focus","method":"surface.focus","params":{"surface_id":"<id>"}}

คำสั่ง input

send

ส่งข้อความไปยังเทอร์มินัลที่โฟกัสอยู่

CLI
cmux send "echo hello"
cmux send "ls -la\n"
Socket
{"id":"send-text","method":"surface.send_text","params":{"text":"echo hello\n"}}

send-key

ส่งการกดปุ่ม คีย์: enter, tab, escape, backspace, delete, up, down, left, right

CLI
cmux send-key enter
Socket
{"id":"send-key","method":"surface.send_key","params":{"key":"enter"}}

send-surface

ส่งข้อความไปยัง surface ที่ระบุ

CLI
cmux send-surface --surface <id> "command"
Socket
{"id":"send-surface","method":"surface.send_text","params":{"surface_id":"<id>","text":"command"}}

send-key-surface

ส่งการกดปุ่มไปยัง surface ที่ระบุ

CLI
cmux send-key-surface --surface <id> enter
Socket
{"id":"send-key-surface","method":"surface.send_key","params":{"surface_id":"<id>","key":"enter"}}

คำสั่งแจ้งเตือน

notify

ส่งการแจ้งเตือน

CLI
cmux notify --title "Title" --body "Body"
cmux notify --title "T" --subtitle "S" --body "B"
Socket
{"id":"notify","method":"notification.create","params":{"title":"Title","subtitle":"S","body":"Body"}}

list-notifications

แสดงรายการแจ้งเตือนทั้งหมด

CLI
cmux list-notifications
cmux list-notifications --json
Socket
{"id":"notif-list","method":"notification.list","params":{}}

clear-notifications

ล้างแจ้งเตือนทั้งหมด

CLI
cmux clear-notifications
Socket
{"id":"notif-clear","method":"notification.clear","params":{}}

คำสั่ง metadata แถบข้าง

ตั้งค่า status pill, progress bar และรายการ log ในแถบข้างสำหรับ workspace ใดก็ได้ เหมาะสำหรับ build script, CI integration และ AI coding agent ที่ต้องการแสดงสถานะอย่างรวดเร็ว

set-status

ตั้ง status pill ในแถบข้าง ใช้ key ที่ไม่ซ้ำเพื่อให้เครื่องมือต่างๆ จัดการรายการของตัวเองได้

CLI
cmux set-status build "compiling" --icon hammer --color "#ff9500"
cmux set-status deploy "v1.2.3" --workspace workspace:2
Socket
set_status build compiling --icon=hammer --color=#ff9500 --tab=<workspace-uuid>

clear-status

ลบรายการ status ในแถบข้างตาม key

CLI
cmux clear-status build
Socket
clear_status build --tab=<workspace-uuid>

list-status

แสดงรายการ status ทั้งหมดในแถบข้างสำหรับ workspace

CLI
cmux list-status
Socket
list_status --tab=<workspace-uuid>

set-progress

ตั้ง progress bar ในแถบข้าง (0.0 ถึง 1.0)

CLI
cmux set-progress 0.5 --label "Building..."
cmux set-progress 1.0 --label "Done"
Socket
set_progress 0.5 --label=Building... --tab=<workspace-uuid>

clear-progress

ล้าง progress bar ในแถบข้าง

CLI
cmux clear-progress
Socket
clear_progress --tab=<workspace-uuid>

log

เพิ่มรายการ log ในแถบข้าง ระดับ: info, progress, success, warning, error

CLI
cmux log "Build started"
cmux log --level error --source build "Compilation failed"
cmux log --level success -- "All 42 tests passed"
Socket
log --level=error --source=build --tab=<workspace-uuid> -- Compilation failed

clear-log

ล้างรายการ log ทั้งหมดในแถบข้าง

CLI
cmux clear-log
Socket
clear_log --tab=<workspace-uuid>

list-log

แสดงรายการ log ในแถบข้าง

CLI
cmux list-log
cmux list-log --limit 5
Socket
list_log --limit=5 --tab=<workspace-uuid>

sidebar-state

แสดง metadata แถบข้างทั้งหมด (cwd, git branch, port, status, progress, log)

CLI
cmux sidebar-state
cmux sidebar-state --workspace workspace:2
Socket
sidebar_state --tab=<workspace-uuid>

คำสั่งยูทิลิตี้

ping

ตรวจสอบว่า cmux กำลังทำงานและตอบสนองอยู่

CLI
cmux ping
Socket
{"id":"ping","method":"system.ping","params":{}}
// Response: {"id":"ping","ok":true,"result":{"pong":true}}

capabilities

แสดง socket method ที่พร้อมใช้งานและโหมดการเข้าถึงปัจจุบัน

CLI
cmux capabilities
cmux capabilities --json
Socket
{"id":"caps","method":"system.capabilities","params":{}}

identify

แสดงบริบทหน้าต่าง/workspace/พาเนล/surface ที่โฟกัสอยู่

CLI
cmux identify
cmux identify --json
Socket
{"id":"identify","method":"system.identify","params":{}}

ตัวแปรสภาพแวดล้อม

ตัวแปรคำอธิบาย
CMUX_SOCKET_PATHOverride socket path ที่ใช้โดย CLI และ integration
CMUX_SOCKET_ENABLEบังคับเปิด/ปิด socket (1/0, true/false, on/off)
CMUX_SOCKET_MODEOverride โหมดการเข้าถึง (cmuxOnly, allowAll, off) รับ cmux-only/cmux_only และ allow-all/allow_all ด้วย
CMUX_WORKSPACE_IDตั้งอัตโนมัติ: workspace ID ปัจจุบัน
CMUX_SURFACE_IDตั้งอัตโนมัติ: surface ID ปัจจุบัน
TERM_PROGRAMตั้งเป็น ghostty
TERMตั้งเป็น xterm-ghostty
ค่า CMUX_SOCKET_MODE แบบเก่า full และ notifications ยังรับได้เพื่อความเข้ากันได้

การตรวจจับ cmux

bash
# 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"

ตัวอย่าง

Python client

python
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

bash
#!/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 พร้อมแจ้งเตือน

bash
#!/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