cmux
Control cmux terminal multiplexer programmatically via its Unix socket API or CLI.
Socket Connection
CODEBLOCK0
Send JSON-RPC requests:
CODEBLOCK1
CLI Quick Reference
CODEBLOCK2
Workspace
| Action | CLI | Socket Method |
|---|
| List all | INLINECODE0 | INLINECODE1 |
| Create new |
cmux new-workspace |
workspace.create |
| Select |
cmux select-workspace --workspace <id> |
workspace.select |
| Get current |
cmux current-workspace |
workspace.current |
| Close |
cmux close-workspace --workspace <id> |
workspace.close |
Splits & Surfaces
| Action | CLI | Socket Method |
|---|
| New split | INLINECODE10 | INLINECODE11 (direction: left/right/up/down) |
| List surfaces |
cmux list-surfaces |
surface.list |
| Focus surface |
cmux focus-surface --surface <id> |
surface.focus |
Input
| Action | CLI | Socket Method |
|---|
| Send text | INLINECODE16 | INLINECODE17 |
| Send key |
cmux send-key enter |
surface.send_key |
| Send to surface |
cmux send-surface --surface <id> "cmd" |
surface.send_text (with surface_id) |
Keys: enter, tab, escape, backspace, delete, up, down, left, INLINECODE30
Notifications
CODEBLOCK3
Sidebar Metadata
| Action | CLI | Socket Method |
|---|
| Set status | INLINECODE31 | (socket only) |
| Clear status |
cmux clear-status <key> | (socket only) |
| Set progress |
cmux set-progress 0.5 --label "Building..." | (socket only) |
| Clear progress |
cmux clear-progress | (socket only) |
| Log entry |
cmux log "message" --level error | (socket only) |
| Clear log |
cmux clear-log | (socket only) |
System
| Action | CLI | Socket Method |
|---|
| Ping | INLINECODE37 | INLINECODE38 |
| Capabilities |
cmux capabilities |
system.capabilities |
| Identify context |
cmux identify |
system.identify |
Python Client
CODEBLOCK4
Shell Helper
CODEBLOCK5
Check if cmux is Available
CODEBLOCK6
cmux
通过Unix套接字API或CLI以编程方式控制cmux终端多路复用器。
套接字连接
bash
SOCKETPATH=${CMUXSOCKET_PATH:-/tmp/cmux.sock}
发送JSON-RPC请求:
json
{id:req-1,method:workspace.list,params:{}}
CLI快速参考
bash
输出为JSON格式
cmux --json
指定目标工作区/表面
cmux --workspace --surface
工作区
| 操作 | CLI | 套接字方法 |
|---|
| 列出所有 | cmux list-workspaces | workspace.list |
| 创建新 |
cmux new-workspace | workspace.create |
| 选择 | cmux select-workspace --workspace | workspace.select |
| 获取当前 | cmux current-workspace | workspace.current |
| 关闭 | cmux close-workspace --workspace | workspace.close |
分割与表面
| 操作 | CLI | 套接字方法 |
|---|
| 新建分割 | cmux new-split <direction> | surface.split (方向:left/right/up/down) |
| 列出表面 |
cmux list-surfaces | surface.list |
| 聚焦表面 | cmux focus-surface --surface | surface.focus |
输入
| 操作 | CLI | 套接字方法 |
|---|
| 发送文本 | cmux send echo hello | surface.sendtext |
| 发送按键 |
cmux send-key enter | surface.sendkey |
| 发送到表面 | cmux send-surface --surface cmd | surface.sendtext (带surfaceid) |
按键:enter, tab, escape, backspace, delete, up, down, left, right
通知
bash
cmux notify --title 标题 --body 内容
套接字:notification.create
侧边栏元数据
| 操作 | CLI | 套接字方法 |
|---|
| 设置状态 | cmux set-status <key> <value> | (仅套接字) |
| 清除状态 |
cmux clear-status | (仅套接字) |
| 设置进度 | cmux set-progress 0.5 --label 构建中... | (仅套接字) |
| 清除进度 | cmux clear-progress | (仅套接字) |
| 日志条目 | cmux log 消息 --level error | (仅套接字) |
| 清除日志 | cmux clear-log | (仅套接字) |
系统
| 操作 | CLI | 套接字方法 |
|---|
| Ping | cmux ping | system.ping |
| 能力 |
cmux capabilities | system.capabilities |
| 识别上下文 | cmux identify | system.identify |
Python客户端
python
import json
import os
import socket
SOCKETPATH = os.environ.get(CMUXSOCKET_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.AFUNIX, socket.SOCKSTREAM) 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))
列出工作区
print(rpc(workspace.list, req_id=ws))
发送通知
print(rpc(notification.create, {title: 你好, body: 来自Python!}))
Shell辅助函数
bash
cmux_cmd() {
SOCK=${CMUXSOCKETPATH:-/tmp/cmux.sock}
printf %s\n $1 | nc -U $SOCK
}
cmux_cmd {id:ws,method:workspace.list,params:{}}
检查cmux是否可用
bash
[ -S ${CMUXSOCKETPATH:-/tmp/cmux.sock} ] && echo cmux套接字可用
command -v cmux &>/dev/null && echo cmux CLI可用