import { useTranslations } from "next-intl"; import { getTranslations } from "next-intl/server"; import { buildAlternates } from "../../../../i18n/seo"; import { CodeBlock } from "../../components/code-block"; import { Callout } from "../../components/callout"; export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) { const { locale } = await params; const t = await getTranslations({ locale, namespace: "docs.api" }); return { title: t("metaTitle"), description: t("metaDescription"), alternates: buildAlternates(locale, "/docs/api"), }; } function Cmd({ name, desc, cli, socket, }: { name: string; desc: string; cli: string; socket: string; }) { return (

{name}

{desc}

{cli} {socket}
); } export default function ApiPage() { const t = useTranslations("docs.api"); return ( <>

{t("title")}

{t("intro")}

{t("socket")}

{t("buildHeader")} {t("pathHeader")}
{t("release")} /tmp/cmux.sock
{t("debug")} /tmp/cmux-debug.sock
{t("taggedDebug")} /tmp/cmux-debug-<tag>.sock

{t("socketOverride")}

{`{"id":"req-1","method":"workspace.list","params":{}} // Response: {"id":"req-1","ok":true,"result":{"workspaces":[...]}}`} {t.rich("socketCallout", { legacy: (chunks) => {chunks}, })}

{t("accessModes")}

{t("modeHeader")} {t("descriptionHeader")} {t("howToEnableHeader")}
Off {t("offMode")} {t("offEnable")}
cmux processes only {t("cmuxOnlyMode")} {t("cmuxOnlyEnable")}
allowAll {t("allowAllMode")} {t("allowAllEnable")}
{t("accessCallout")}

{t("cliOptions")}

{t("flagHeader")} {t("descriptionHeader")}
--socket PATH {t("customSocketPath")}
--json {t("outputJson")}
--window ID {t("targetWindow")}
--workspace ID {t("targetWorkspace")}
--surface ID {t("targetSurface")}
--id-format refs|uuids|both {t("idFormat")}

{t("workspaceCommands")}

`} socket={`{"id":"ws-select","method":"workspace.select","params":{"workspace_id":""}}`} /> `} socket={`{"id":"ws-close","method":"workspace.close","params":{"workspace_id":""}}`} />

{t("splitCommands")}

`} socket={`{"id":"surface-focus","method":"surface.focus","params":{"surface_id":""}}`} />

{t("inputCommands")}

"command"`} socket={`{"id":"send-surface","method":"surface.send_text","params":{"surface_id":"","text":"command"}}`} /> enter`} socket={`{"id":"send-key-surface","method":"surface.send_key","params":{"surface_id":"","key":"enter"}}`} />

{t("notificationCommands")}

{t("sidebarMetadata")}

{t("sidebarMetadataDesc")}

`} /> `} /> `} /> `} /> `} /> -- Compilation failed`} /> `} /> `} /> `} />

{t("utilityCommands")}

{t("envVariables")}

{t("variableHeader")} {t("descriptionHeader")}
CMUX_SOCKET_PATH {t("socketPathDesc")}
CMUX_SOCKET_ENABLE {t("socketEnableDesc")}
CMUX_SOCKET_MODE {t("socketModeDesc")}
CMUX_WORKSPACE_ID {t("workspaceIdDesc")}
CMUX_SURFACE_ID {t("surfaceIdDesc")}
TERM_PROGRAM {t("termProgramDesc")}
TERM {t("termDesc")}
{t("envCallout")}

{t("detectingCmux")}

{`# 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"`}

{t("examples")}

{t("pythonClient")}

{`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" ))`}

{t("shellScript")}

{`#!/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"}}'`}

{t("buildScriptNotification")}

{`#!/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`} ); }