เอกสาร API
cmux มีทั้งเครื่องมือ CLI และ Unix socket สำหรับการควบคุมแบบโปรแกรม ทุกคำสั่งพร้อมใช้งานผ่านทั้งสองอินเทอร์เฟซ
Socket
| Build | Path |
|---|---|
| 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":[...]}}{"command":"..."} ไม่รองรับโหมดการเข้าถึง
| โหมด | คำอธิบาย | วิธีเปิดใช้งาน |
|---|---|---|
| Off | ปิด socket | Settings UI หรือ CMUX_SOCKET_MODE=off |
| cmux processes only | เฉพาะโปรเซสที่เกิดภายในเทอร์มินัล cmux เท่านั้นที่เชื่อมต่อได้ | โหมดเริ่มต้นใน Settings UI |
| allowAll | อนุญาตให้โปรเซสในเครื่องใดก็ได้เชื่อมต่อ (ไม่ตรวจสอบ ancestry) | Override ผ่าน environment เท่านั้น: CMUX_SOCKET_MODE=allowAll |
ตัวเลือก 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 ที่เปิดอยู่ทั้งหมด
cmux list-workspaces
cmux list-workspaces --json{"id":"ws-list","method":"workspace.list","params":{}}new-workspace
สร้าง workspace ใหม่
cmux new-workspace{"id":"ws-new","method":"workspace.create","params":{}}select-workspace
สลับไปยัง workspace ที่ระบุ
cmux select-workspace --workspace <id>{"id":"ws-select","method":"workspace.select","params":{"workspace_id":"<id>"}}current-workspace
รับ workspace ที่ใช้งานอยู่ปัจจุบัน
cmux current-workspace
cmux current-workspace --json{"id":"ws-current","method":"workspace.current","params":{}}close-workspace
ปิด workspace
cmux close-workspace --workspace <id>{"id":"ws-close","method":"workspace.close","params":{"workspace_id":"<id>"}}คำสั่งแยกหน้าจอ
new-split
สร้างพาเนลแยกใหม่ ทิศทาง: left, right, up, down
cmux new-split right
cmux new-split down{"id":"split-new","method":"surface.split","params":{"direction":"right"}}list-surfaces
แสดงรายการ surface ทั้งหมดใน workspace ปัจจุบัน
cmux list-surfaces
cmux list-surfaces --json{"id":"surface-list","method":"surface.list","params":{}}focus-surface
โฟกัส surface ที่ระบุ
cmux focus-surface --surface <id>{"id":"surface-focus","method":"surface.focus","params":{"surface_id":"<id>"}}คำสั่ง input
send
ส่งข้อความไปยังเทอร์มินัลที่โฟกัสอยู่
cmux send "echo hello"
cmux send "ls -la\n"{"id":"send-text","method":"surface.send_text","params":{"text":"echo hello\n"}}send-key
ส่งการกดปุ่ม คีย์: enter, tab, escape, backspace, delete, up, down, left, right
cmux send-key enter{"id":"send-key","method":"surface.send_key","params":{"key":"enter"}}send-surface
ส่งข้อความไปยัง surface ที่ระบุ
cmux send-surface --surface <id> "command"{"id":"send-surface","method":"surface.send_text","params":{"surface_id":"<id>","text":"command"}}send-key-surface
ส่งการกดปุ่มไปยัง surface ที่ระบุ
cmux send-key-surface --surface <id> enter{"id":"send-key-surface","method":"surface.send_key","params":{"surface_id":"<id>","key":"enter"}}คำสั่งแจ้งเตือน
notify
ส่งการแจ้งเตือน
cmux notify --title "Title" --body "Body"
cmux notify --title "T" --subtitle "S" --body "B"{"id":"notify","method":"notification.create","params":{"title":"Title","subtitle":"S","body":"Body"}}list-notifications
แสดงรายการแจ้งเตือนทั้งหมด
cmux list-notifications
cmux list-notifications --json{"id":"notif-list","method":"notification.list","params":{}}clear-notifications
ล้างแจ้งเตือนทั้งหมด
cmux clear-notifications{"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 ที่ไม่ซ้ำเพื่อให้เครื่องมือต่างๆ จัดการรายการของตัวเองได้
cmux set-status build "compiling" --icon hammer --color "#ff9500"
cmux set-status deploy "v1.2.3" --workspace workspace:2set_status build compiling --icon=hammer --color=#ff9500 --tab=<workspace-uuid>clear-status
ลบรายการ status ในแถบข้างตาม key
cmux clear-status buildclear_status build --tab=<workspace-uuid>list-status
แสดงรายการ status ทั้งหมดในแถบข้างสำหรับ workspace
cmux list-statuslist_status --tab=<workspace-uuid>set-progress
ตั้ง progress bar ในแถบข้าง (0.0 ถึง 1.0)
cmux set-progress 0.5 --label "Building..."
cmux set-progress 1.0 --label "Done"set_progress 0.5 --label=Building... --tab=<workspace-uuid>clear-progress
ล้าง progress bar ในแถบข้าง
cmux clear-progressclear_progress --tab=<workspace-uuid>log
เพิ่มรายการ log ในแถบข้าง ระดับ: info, progress, success, warning, error
cmux log "Build started"
cmux log --level error --source build "Compilation failed"
cmux log --level success -- "All 42 tests passed"log --level=error --source=build --tab=<workspace-uuid> -- Compilation failedclear-log
ล้างรายการ log ทั้งหมดในแถบข้าง
cmux clear-logclear_log --tab=<workspace-uuid>list-log
แสดงรายการ log ในแถบข้าง
cmux list-log
cmux list-log --limit 5list_log --limit=5 --tab=<workspace-uuid>sidebar-state
แสดง metadata แถบข้างทั้งหมด (cwd, git branch, port, status, progress, log)
cmux sidebar-state
cmux sidebar-state --workspace workspace:2sidebar_state --tab=<workspace-uuid>คำสั่งยูทิลิตี้
ping
ตรวจสอบว่า cmux กำลังทำงานและตอบสนองอยู่
cmux ping{"id":"ping","method":"system.ping","params":{}}
// Response: {"id":"ping","ok":true,"result":{"pong":true}}capabilities
แสดง socket method ที่พร้อมใช้งานและโหมดการเข้าถึงปัจจุบัน
cmux capabilities
cmux capabilities --json{"id":"caps","method":"system.capabilities","params":{}}identify
แสดงบริบทหน้าต่าง/workspace/พาเนล/surface ที่โฟกัสอยู่
cmux identify
cmux identify --json{"id":"identify","method":"system.identify","params":{}}ตัวแปรสภาพแวดล้อม
| ตัวแปร | คำอธิบาย |
|---|---|
CMUX_SOCKET_PATH | Override socket path ที่ใช้โดย CLI และ integration |
CMUX_SOCKET_ENABLE | บังคับเปิด/ปิด socket (1/0, true/false, on/off) |
CMUX_SOCKET_MODE | Override โหมดการเข้าถึง (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
# 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
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 พร้อมแจ้งเตือน
#!/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