The Termopus Bridge is a Rust agent that runs on your computer and acts as the secure intermediary between Claude Code and your phone. It sits in the menu bar, manages Claude sessions, encrypts all communication, and maintains persistent connections through a Cloudflare relay.
Structured Claude CLI protocol parser using claude -p --output-format stream-json. Handles all event types from the Claude CLI:
init— session initialization with model infotext_delta— streaming text outputmessage_delta— message completion with token usagetool_use— file edits, bash commands, search operationsresult— final session result with cost datathinking— extended thinking blocks
The main session lifecycle manager (~2,000 lines) handling:
- Resume & crash recovery — auto-detects orphaned sessions, resumes with fresh relay room
- Conversation catchup — sends last 20 messages when reconnecting
- Live state tracking — real-time status broadcast (Idle / Thinking / ToolUse / Respawning / Exited)
- Respawn limiter — max 3 auto-restart attempts with exponential backoff
- Native command handlers — Optimize Chat, Start Fresh, Statistics, Undo, Plan Mode
3-tier permission engine that intercepts every Claude Code tool call:
┌─────────────────┐
│ Mode Override │ ← "plan" mode blocks all writes
├─────────────────┤
│ Rule Matching │ ← settings.local.json glob patterns
├─────────────────┤
│ Phone Fallback │ ← send to phone for user decision
└─────────────────┘
- Atomic file IPC (write-to-tmp + rename)
- Auto-writes "Always Allow" glob rules (e.g.,
"Bash(git *)") - Intercepts
AskUserQuestion→ renders as interactive card on phone
- EC P-256 keypair generation
- ECDH key exchange with phone's hardware-backed keys
- AES-256-GCM encryption for all relay messages
- HKDF key derivation for session keys
Desktop interface built with egui:
- Menu bar tray icon with session status
- QR code display for phone pairing
- Session list with right-click management
- Setup wizard for first-time configuration
┌──────────────────────────────────────────────┐
│ Termopus Bridge │
│ │
│ ┌────────────┐ ┌─────────────────────┐ │
│ │ GUI (egui) │ │ Session Manager │ │
│ │ Tray icon │ │ Multi-session │ │
│ │ QR display │ │ Crash recovery │ │
│ └─────┬──────┘ └──────────┬──────────┘ │
│ │ │ │
│ ┌─────┴───────────────────────┴──────────┐ │
│ │ Session Task Loop │ │
│ │ Stream-JSON ↔ Crypto ↔ Relay WS │ │
│ └─────┬──────────────────────────┬───────┘ │
│ │ │ │
│ ┌─────┴──────┐ ┌──────┴────────┐ │
│ │ Hook System│ │ File Transfer │ │
│ │ 3-tier │ │ Chunked E2E │ │
│ │ Permissions│ │ Session-scoped │ │
│ └────────────┘ └───────────────┘ │
└──────────┬───────────────────────┬───────────┘
│ stdio │ WebSocket
┌─────┴─────┐ ┌──────┴──────┐
│Claude Code│ │ CF Relay │
└───────────┘ └─────────────┘
| Binary | Purpose |
|---|---|
termopus |
Main bridge agent — GUI, sessions, relay |
termopus-hook |
Claude Code hook handler — standalone binary for 3-tier permission engine |
| Component | Technology |
|---|---|
| Language | Rust (2021 edition) |
| Async Runtime | Tokio |
| WebSocket | tokio-tungstenite |
| GUI | egui + eframe |
| Crypto | aes-gcm, p256, hkdf, x25519-dalek |
| CLI Interface | Stream-JSON protocol |
| HTTP | reqwest (rustls-tls) |
