Skip to content

Terminal Streaming Protocol

A protocol for remote terminal sessions with durable output streaming and resumable connections.

What is Terminal Streaming Protocol?

The Terminal Streaming Protocol enables remote terminal access over HTTP with full resumability. Unlike traditional WebSocket-based terminals, sessions survive disconnections - clients can reconnect and replay any missed output from the exact point they left off.

Built on top of Unbroken Protocol, it combines:

  • PTY (Pseudo-Terminal) for shell interaction
  • Unbroken Protocol for output persistence and resumption
  • HTTP for input delivery

Key Features

FeatureDescription
ResumableReconnect and continue from any point
Persistent OutputFull session history preserved
Web NativeWorks in browsers via SSE
CLI CompatibleLong-polling for terminal clients
Low LatencyBatched I/O for responsive interaction

Architecture

┌─────────────────────────────────────────────────────────────┐
│ Client │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Terminal │ │ Input │ │ Offset │ │
│ │ Renderer │ │ Buffer │ │ Storage │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
└─────────┼──────────────────┼──────────────────┼─────────────┘
│ SSE/Long-poll │ POST │
▼ ▼ │
┌─────────────────────────────────────────────────────────────┐
│ Terminal Server │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Durable │◀───│ PTY │◀───│ Input │ │
│ │ Stream │ │ Process │ │ Handler │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘

Quick Example

Terminal window
# Create a terminal session
curl -X PUT http://localhost:9999/terminal/my-session \
-H "Content-Type: application/json" \
-d '{"cols": 80, "rows": 24}'
# Stream output (SSE)
curl "http://localhost:9999/terminal/my-session?offset=-1&live=sse"
# Send input
curl -X POST http://localhost:9999/terminal/my-session/input \
-d "ls -la"$'\r'
# Resize terminal
curl -X POST http://localhost:9999/terminal/my-session/resize \
-H "Content-Type: application/json" \
-d '{"cols": 120, "rows": 40}'

Protocol at a Glance

Endpoints

MethodPathDescription
PUT/terminal/{id}Create session
GET/terminal/{id}?offset=XRead output (catch-up)
GET/terminal/{id}?offset=X&live=sseStream output (SSE)
POST/terminal/{id}/inputSend input
POST/terminal/{id}/resizeResize terminal
DELETE/terminal/{id}Kill session
HEAD/terminal/{id}Check session exists

Headers

HeaderDirectionDescription
Stream-Next-OffsetResponseOffset for resumption
Stream-Up-To-DateResponseAt end of output

SSE Event Types

EventDescription
dataTerminal output (JSON-encoded string)
controlStream metadata with offset

Input Protocol

InputBytesDescription
Enter\rCarriage return
Ctrl+C\x03Interrupt (SIGINT)
Ctrl+D\x04End of file
Ctrl+Z\x1ASuspend (SIGTSTP)
Up Arrow\x1b[AEscape sequence
Down Arrow\x1b[BEscape sequence

Use Cases

  • Remote Development: SSH-like access over HTTP
  • Cloud Shells: Browser-based terminal for cloud platforms
  • Session Recording: Full session replay for auditing
  • Pair Programming: Share terminal sessions with replay
  • CI/CD Logs: Live streaming build output with history

Specification

For the complete protocol specification, see PROTOCOL.md.

Default Port

The terminal server uses port 9999/tcp by default (same as Unbroken Protocol).

Requirements

  • Server: Bun runtime with bun-pty package
  • Client: Any HTTP client (browser, curl, custom)