# เอกสาร CLI

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":[...]}}
```

JSON socket request ต้องใช้ method และ params Legacy v1 JSON payload เช่น `{"command":"..."}` ไม่รองรับ

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

| โหมด | คำอธิบาย | วิธีเปิดใช้งาน |
| --- | --- | --- |
| **Off** | ปิด socket | Settings 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
cmux new-split down --command "npm run dev"
```

Socket

```
{"id":"split-new","method":"surface.split","params":{"direction":"right"}}
{"id":"split-cmd","method":"surface.split","params":{"direction":"down","initial_input":"npm run dev\r"}}
```

#### list-panels

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

CLI

```
cmux list-panels
cmux list-panels --json
```

Socket

```
{"id":"surface-list","method":"surface.list","params":{}}
```

#### list-pane-surfaces

แสดงรายการ surface ในพาเนลที่โฟกัสอยู่

CLI

```
cmux list-pane-surfaces
cmux list-pane-surfaces --json
```

Socket

```
{"id":"pane-surfaces","method":"pane.surfaces","params":{}}
```

#### focus-panel

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

CLI

```
cmux focus-panel --panel <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 <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 <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" --priority 80
cmux set-status deploy "v1.2.3" --workspace workspace:2
```

Socket

```
set_status build compiling --icon=hammer --color=#ff9500 --priority=80 --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_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\_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
```

Canonical: https://cmux.com/th/docs/api

Documentation index: https://cmux.com/llms.txt
