Skip to content

REST API

Manage sessions, windows, and panes over HTTP under /api. Send the access token with every request.

Terminal window
api="${BTMUX_API_URL:-http://127.0.0.1:8004}/api"
auth="Authorization: Bearer $BTMUX_AUTH_TOKEN"
# Create a session; the reply has its first pane's ID
curl -H "$auth" -X POST "$api/sessions" --json '{"name":"build"}'
# Type into a pane, then read its screen
curl -H "$auth" -X POST "$api/panes/<pane-id>/input" --json '{"text":"echo hi","keys":["Enter"]}'
curl -H "$auth" "$api/panes/<pane-id>/capture?lines=20"
# Bring a pane to the front in every client
curl -H "$auth" -X POST "$api/panes/<pane-id>/focus"
  • input sends text verbatim, then keys: tmux-style key names such as Enter, Tab, Escape, Space, BSpace, Up, PageDown, F5, C-c, or M-x. Cursor keys follow the program’s cursor key mode, as in tmux.
  • capture returns the pane as rendered plain text with wrapped lines joined, like tmux capture-pane -pJ. It covers the visible screen; scrollback=true adds all retained history above it, and history=N at most N rows of it. lines=N keeps the last N lines.
  • output returns the raw bytes instead, escapes included.
  • split takes direction (left, right, up, or down: where the new pane goes), optional cwd, and select (default true), and returns the new pane_id. Creating a session or window returns its pane_id too.
  • focus switches every connected client to the pane’s window and session. It replies 204, or 404 for an unknown pane.
  • open-file-browser does the same and then opens a dialog there. Its mode is "files" (default), "git", or "process", as <prefix> + f, g, and t open. In file mode, path is the directory and optional focus_file names an entry in it to focus.

The API reference gives each endpoint’s parameters, request and response bodies, and status codes. It is generated from the server’s code as an OpenAPI 3.1 document, which clients and tools can read too: a server serves the one for its version at /api/openapi.json, and this site the latest. Endpoints the btmux app uses for itself, such as file previews and editors, aren’t listed.

Every endpoint can reply 401 for a missing or wrong token, and 403 for a Host or Origin the server doesn’t allow. Error bodies, if any, are plain text. Malformed IDs and JSON bodies get 400, a body over the size limit 413, one without Content-Type: application/json 415, and one that doesn’t match its schema 422.

Endpoint Does
GET /api/sessions List sessions
POST /api/sessions Create a session
DELETE /api/sessions Clear sessions
GET /api/sessions/{session_id} Get a session
DELETE /api/sessions/{session_id} Kill a session
POST /api/sessions/{session_id}/rename Rename a session
Endpoint Does
POST /api/sessions/{session_id}/windows Create a window
POST /api/sessions/{session_id}/windows/switch Switch windows
POST /api/sessions/{session_id}/windows/rename Rename the active window
POST /api/sessions/{session_id}/windows/close Close the active window
DELETE /api/windows/{window_id} Kill a window
POST /api/windows/{window_id}/select Select a window
POST /api/windows/{window_id}/rename Rename a window
Endpoint Does
GET /api/panes List panes
POST /api/panes/{pane_id}/split Split a pane
DELETE /api/panes/{pane_id} Kill a pane
POST /api/panes/{pane_id}/select Select a pane
GET /api/panes/{pane_id}/ports List a pane's listening ports
GET /api/panes/{pane_id}/exit Wait for a pane's program to exit
POST /api/panes/{pane_id}/focus Focus a pane
POST /api/panes/{pane_id}/open-file-browser Open the file browser
POST /api/panes/{pane_id}/open-editor Open an editor
Endpoint Does
POST /api/sessions/{session_id}/panes/{pane_id}/split Split an active-window pane
DELETE /api/sessions/{session_id}/panes/{pane_id} Kill an active-window pane
POST /api/sessions/{session_id}/panes/{pane_id}/zoom Zoom a pane
POST /api/sessions/{session_id}/panes/{pane_id}/select Select an active-window pane
POST /api/sessions/{session_id}/panes/navigate Move to a neighboring pane
POST /api/sessions/{session_id}/panes/cycle Cycle panes
POST /api/sessions/{session_id}/panes/swap Swap panes
POST /api/sessions/{session_id}/layout Select a layout
POST /api/sessions/{session_id}/layout/next Next layout
Endpoint Does
POST /api/panes/{pane_id}/input Send input
GET /api/panes/{pane_id}/output Read raw output
GET /api/panes/{pane_id}/capture Capture the screen
Endpoint Does
GET /api/agents List agents
POST /api/panes/{pane_id}/prompt Prompt an agent
GET /api/panes/{pane_id}/wait Wait for an agent
GET /api/panes/{pane_id}/agent-status Explain an agent's status
POST /api/panes/{pane_id}/agent-status Set an agent's status
DELETE /api/panes/{pane_id}/agent-status Clear an agent's status
GET /api/telemetry Agent usage
GET /api/agent-limits Subscription limits
Endpoint Does
POST /api/panes/{pane_id}/worktree Create a worktree
DELETE /api/panes/{pane_id}/worktree Remove a worktree
Endpoint Does
POST /api/panes/{pane_id}/popup Open a popup
GET /api/panes/{pane_id}/popup/{id} Wait for a popup
Endpoint Does
GET /api/events Stream events
Endpoint Does
POST /api/notify Show a notification
POST /api/panes/{pane_id}/notify Report an agent event
DELETE /api/panes/{pane_id}/notify Clear a pane's notification
Endpoint Does
GET /api/info Describe the server
GET /api/system Describe the server host
GET /api/health Check optional programs
POST /api/server/upgrade Upgrade in place
POST /api/server/shutdown Shut down the server
GET /api/openapi.json This API's OpenAPI document