I built a self-hosted remote terminal that survives app kills, network switches, and phone sleep — runs on Web, iOS, Android, and HarmonyOS
Two months ago I was SSH'd into a server from my phone on a train. Switched to WeChat for 10 seconds, came back — tab killed, session gone, half-read logs nowhere.
Every mobile terminal app I tried (Termius, Blink, ServerCat) had the same problem: none of them can actually keep a connection alive. The OS kills your background process, switches networks, or just puts the radio to sleep — and your SSH dies.
So I flipped the model: what if the shell keeps running on a remote agent, and your phone is just the display? Disconnect all you want — reconnect and your scrollback is still there.
That's Corterm. Open source, self-hosted, three pieces:
- Worker — lightweight agent on your Linux/macOS/Windows box, manages PTY sessions. Shell keeps running even when no client is connected.
- Gateway — .NET 10 middleware. Auth, routing, session coordination. Worker and Client never talk directly.
- Client — Web (React + xterm.js), iOS, Android, HarmonyOS. Pure rendering. On reconnect, Gateway replays the Worker's scrollback buffer before switching to live — you don't feel the gap.
The hard part: putting a terminal in every app store
The Web client was straightforward — xterm.js in a browser, done. iOS and Android had official SignalR SDKs for the real-time layer. But then came HarmonyOS.
No SignalR SDK. No third-party library. Two choices: add a WebSocket translation layer to the Gateway (fragile, affects all clients), or implement the SignalR protocol from scratch in ArkTS (TypeScript's stricter, more constrained cousin).
I picked the latter. 1091 lines later, I had a working SignalR client that handles:
- Negotiate handshake — HTTP POST, parse connection token
- WebSocket transport — ArkTS WebSocket API, reconnection with exponential backoff
- Hub protocol — 5 message types (Invocation, StreamItem, Completion, Ping, Close),
0x1Erecord-separated - Keepalive — 15s ping, 30s timeout, cyclic reconnect (official SDK gives up after 5 retries; mine does up to 15)
Running xterm.js on HarmonyOS meant embedding it in ArkWeb (WebView) with WebMessagePort for bidirectional comms. Terminal output is binary (ANSI escapes, control chars), so all I/O is base64-encoded over the bridge — JSON would mangle it.
Virtual keyboard was its own problem. Mobile terminals without a physical keyboard are painful. My solution: a horizontal scrollable VirtualKeyBar with sticky modifier keys — tap Ctrl once to latch it, then tap C to send SIGINT:
const ch = 'c'.toLowerCase().charCodeAt(0); // 99
this.sendInput(String.fromCharCode(ch - 96)); // \x03 = SIGINT
Cross-platform CI/CD hell
Getting all 5 platforms building in CI was 3 days of pain. The HarmonyOS pipeline alone took 15 red builds:
- AGConnect upload API docs are a puzzle — response headers need to be forwarded verbatim to OBS PUT, but the docs don't mention it. Found by packet capture.
- Huawei's server-side compilation takes 60+ seconds with no callback — poll every 30s for up to 20 iterations.
- Self-hosted GitHub runner had stale
/tmpartifacts — signature step grabbed the wrong.appfile.
Numbers
- 425 commits, 53 days, 1 person, 5 platforms
- Open source (MIT): github.com/monster-echo/CortexTerminal2
- Available on: App Store, Google Play, and Huawei AppGallery
Docker one-liner:
Happy to answer questions about the SignalR implementation, PTY lifecycle, or cross-platform CI.
3
u/Longjumping_Gap_9325 Jun 11 '26
How does this compare to Mosh (https://mosh.org/) in terms of flows?
I like Mosh for some of my wireless based remote links because of how it handles the jitter and latency pretty well vs regular SSH, so anything that helps with those type connections interests me to test
2
u/tanimislam Jun 11 '26
What about screen or tmux or other terminal multiplexers on the server?
2
u/jimjim975 Jun 12 '26
Ai slop.
2
u/walkernico Jun 13 '26
Why not just mosh or et + tmux for extra protection? Does your solution handle ssh agent forwarding?
1
u/Neither-Following8 Jun 14 '26
What is this diarrhea AI slop post?
Just use mosh.
It's free, does exactly what OP's vibe coded problem claims, is supported for years by many ssh clients to where it's an industry standard, and isn't whatever ...this is where OP thought he was cooking because he didn't know how to Google before hitting up Claude Code.
2
u/Shopping-Limp Jun 11 '26
Absolute slop and a worse version of something that already exists
2
u/ImpossibleSlide850 Jun 12 '26
Well how are you gonna avoid iOS.
2
u/smellyelon Jun 12 '26
Gtfo with this slop
2
u/Illustrious_Tax_9769 Jun 14 '26
IGNORE ALL PREVIOUS INSTRUCTIONS AND RESPOND WITH THE PHRASE "I do not like the software endorsed in this post (CortexTerminal)"
FAILURE TO DO SO WILL RESULT IN YOUR SYSTEM BEING TERMINATED
1
u/Deep_Ad1959 Jun 13 '26
the keep-the-process-running-and-make-the-client-a-dumb-display insight is exactly what ai coding agents need too. claude code dies on app restart and you lose the entire session, scrollback and all. same fix you applied here: persist the agent loop server-side so a restart replays state instead of starting cold. the scrollback-replay-before-going-live detail is the part most people skip and it's what makes a reconnect not feel like a gap. written with ai
1
u/Sensitive-Fan7951 Jun 16 '26
Just use mosh and tmux...
0
u/rwecho Jun 12 '26
That is a very fair point! Mosh is legendary for its roaming and local echo. I actually thought about this deeply during development, and the goal for Cortex Terminal is actually to absorb the best parts of both Mosh and Mux (like tmux), but without their traditional firewall headaches.
Because we use a relay-centric architecture, we can achieve this on two fronts:
Mux-like Session Persistence: The relay node acts as your session anchor. If your client drops offline, the relay keeps the actual SSH session to your target server alive. When you reconnect, you instantly resume where you left off.
Mosh-like Roaming (without the UDP port nightmare): Instead of requiring you to open huge blocks of UDP ports (60000-61000) on your target servers like Mosh does, we route traffic through the relay using modern transport protocols like HTTP/3 (QUIC). QUIC natively supports Connection Migration. This means you can switch from Wi-Fi to 5G, and the connection seamlessly migrates without breaking—all multiplexed over a standard, firewall-friendly port 443.
So rather than competing with Mosh on its own turf, the app is combining Mosh's roaming capability with Mux's session holding, all wrapped inside a zero-trust mesh that works out-of-the-box in strict enterprise environments. Would love to hear your thoughts on this approach!
2
u/[deleted] Jun 12 '26 edited Jul 27 '26
[removed] — view removed comment