API-reference

cmux tilbyder både et CLI-værktøj og en Unix socket til programmatisk styring. Alle kommandoer er tilgængelige via begge grænseflader.

Socket

BuildSti
Release/tmp/cmux.sock
Debug/tmp/cmux-debug.sock
Tagget debug build/tmp/cmux-debug-<tag>.sock

Overskriv med CMUX_SOCKET_PATH-miljøvariablen. Send én linjetermineret JSON-anmodning per kald:

{"id":"req-1","method":"workspace.list","params":{}}
// Response:
{"id":"req-1","ok":true,"result":{"workspaces":[...]}}
JSON socket-anmodninger skal bruge method og params. Legacy v1 JSON-payloads som {"command":"..."} understøttes ikke.

Adgangstilstande

TilstandBeskrivelseSådan aktiveres
OffSocket deaktiveretIndstillinger-UI eller CMUX_SOCKET_MODE=off
cmux processes onlyKun processer startet inde i cmux-terminaler kan forbinde.Standardtilstand i Indstillinger-UI
allowAllTillad enhver lokal proces at forbinde (ingen ancestry-kontrol).Kun miljøvariabel-override: CMUX_SOCKET_MODE=allowAll
På delte maskiner, brug Fra eller Kun cmux-processer.

CLI-indstillinger

FlagBeskrivelse
--socket PATHBrugerdefineret socketsti
--jsonOutput i JSON-format
--window IDMålret et specifikt vindue
--workspace IDMålret et specifikt workspace
--surface IDMålret en specifik surface
--id-format refs|uuids|bothStyr ID-format i JSON-output

Workspace-kommandoer

list-workspaces

List alle åbne workspaces.

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

new-workspace

Opret et nyt workspace.

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

select-workspace

Skift til et specifikt workspace.

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

current-workspace

Hent det aktuelt aktive workspace.

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

close-workspace

Luk et workspace.

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

Opdelingskommandoer

new-split

Opret et nyt opdelt panel. Retninger: 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

List alle surfaces i det aktuelle workspace.

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

focus-surface

Fokusér en specifik surface.

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

Inputkommandoer

send

Send tekstinput til den fokuserede terminal.

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

Send et tastetryk. Taster: 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

Send tekst til en specifik 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

Send et tastetryk til en specifik surface.

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

Notifikationskommandoer

notify

Send en notifikation.

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

List alle notifikationer.

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

clear-notifications

Ryd alle notifikationer.

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

Sidebar-metadatakommandoer

Sæt statuspiller, fremskridtsbjælker og logposter i sidebaren for ethvert workspace. Nyttigt til build-scripts, CI-integrationer og AI-kodningsagenter der vil vise tilstand med et blik.

set-status

Sæt en sidebar-statuspille. Brug en unik nøgle så forskellige værktøjer kan håndtere deres egne poster.

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

Fjern en sidebar-statuspost ved nøgle.

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

list-status

List alle sidebar-statusposter for et workspace.

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

set-progress

Sæt en fremskridtsbjælke i sidebaren (0.0 til 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

Ryd sidebar-fremskridtsbjælken.

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

log

Tilføj en logpost til sidebaren. Niveauer: 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

Ryd alle sidebar-logposter.

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

list-log

List sidebar-logposter.

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

sidebar-state

Dump al sidebar-metadata (cwd, git branch, porte, status, fremskridt, logs).

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

Hjælpekommandoer

ping

Tjek om cmux kører og er responsiv.

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

capabilities

List tilgængelige socket-metoder og aktuel adgangstilstand.

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

identify

Vis fokuseret vindue/workspace/panel/surface-kontekst.

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

Miljøvariabler

VariabelBeskrivelse
CMUX_SOCKET_PATHOverskriv socketstien brugt af CLI og integrationer
CMUX_SOCKET_ENABLETving aktivering/deaktivering af socket (1/0, true/false, on/off)
CMUX_SOCKET_MODEOverskriv adgangstilstand (cmuxOnly, allowAll, off). Accepterer også cmux-only/cmux_only og allow-all/allow_all
CMUX_WORKSPACE_IDAuto-sat: nuværende workspace-ID
CMUX_SURFACE_IDAuto-sat: nuværende surface-ID
TERM_PROGRAMSat til ghostty
TERMSat til xterm-ghostty
Legacy CMUX_SOCKET_MODE-værdier full og notifications accepteres stadig for kompatibilitet.

Detektering af 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"

Eksempler

Python-klient

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 med notifikation

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