Skip to content

Persistent terminals (v2 experimental persistent-pty) #720

Open

Description

@ivanfenenko

Why

Terminals on mobile die whenever the app goes to background or the connection drops. OpenCode 2.x now has persistent PTYs that survive client disconnects (anomalyco/opencode#52760), so the app can reattach instead of losing the shell.

Current state

  • No /api/experimental/persistent-pty/* calls on either platform.
  • capabilities.persistentPty from /api/info is not read.
  • Android: data/remote/PtyApi.kt, domain/terminal/TerminalConnectRequest.kt (5ab410b only fixed query encoding). iOS: no persistent-pty code found.

Upstream API (origin/dev, v2 openapi)

  • GET|PUT|DELETE /api/experimental/persistent-pty/{ptyID} (info / update / kill)
  • GET /api/experimental/persistent-pty/{ptyID}/snapshot (scrollback to restore on reattach)
  • POST /api/experimental/persistent-pty/{ptyID}/connect-token + GET .../{ptyID}/connect (WebSocket attach)
  • POST /api/experimental/persistent-pty/handoff (returns {directory, instanceID, ticket, expiresAt})
  • POST /api/experimental/persistent-pty/shutdown
  • Schemas: PersistentPty.Info, CreateInput, UpdateInput, Snapshot, ReadResult, Handoff

Tasks

  • Read capabilities.persistentPty and gate the feature (v1 and older 2.x keep current PTY behaviour)
  • Remote client for persistent-pty routes (Android + iOS)
  • Create terminals as persistent when supported; keep ptyID per session/project
  • On foreground/reconnect: fetch snapshot, render scrollback, then reattach via connect-token + connect
  • Terminal list shows surviving persistent terminals; explicit kill uses DELETE
  • Investigate handoff (desktop <-> mobile) and whether the app should ever call shutdown
  • Tests for reattach after background/network loss

Routes are experimental; expect churn. Tracked in the OpenCode tracker inventory as "Persistent terminals: not done" (also listed under nice-to-have in #546 / OPE-272).

Activity

  1. added
    enhancement
    ios
    android
    shared
    todo
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    androidenhancementiossharedtodo

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions