Use this when you need a long-lived Bash driven over WebSocket: PTY mode behaves like a real terminal (colors, stty, resize); pipe mode (pty=0) splits stdout/stderr without a TTY. Unix/macOS/Linux only — not supported on Windows.
-
Create a session (shell starts on the first WebSocket, not here):
curl -s -X POST http://127.0.0.1:44772/pty \ -H 'Content-Type: application/json' \ -d '{"cwd":"/tmp"}' # → { "session_id": "<id>" }
-
Open WebSocket — default is PTY mode:
ws://127.0.0.1:44772/pty/<session_id>/wsQuery Use pty=0Pipe mode instead of PTY since=<offset>After reconnect, replay from byte offset (use output_offsetfromGET /pty/:id) -
Traffic — after a JSON
connectedframe, the server sends binary chunks: first byte is the channel (0x01stdout,0x02stderr in pipe mode only,0x03replay with an 8-byte offset header). Send stdin as binary:0x00+ raw bytes. For resize / signals / ping, send JSON text frames, e.g.{"type":"resize","cols":120,"rows":40},{"type":"signal","signal":"SIGINT"},{"type":"ping"}. -
One WebSocket per session — a second connection gets 409 until the first closes.
-
End — when Bash exits, you get a JSON
exitframe withexit_codeand the socket closes. UseDELETE /pty/:idto tear down the session from the server side.
- PTY (default) — ANSI and TTY-aware tools work as usual.
- Pipe —
?pty=0; stderr is separate binary frames. Good when you do not need a TTY.
- Output is also buffered for replay; reconnect with
since=to catch up. - In PTY streams, shell echo may appear before your command’s real output, so avoid matching only on text that also appears in the typed line.