GPU-rendered terminal wrapper for Claude Code with hot-swappable backend support.
Embed Claude Code in an in-process GPU terminal (PTY child), and run a local reverse proxy that Claude Code talks to. The proxy routes requests to a chosen backend; the user can hot-swap backends on the fly without restarting Claude Code. The UI (header / footer chrome + popups) renders on top of the terminal.
- SOLID — single responsibility, depend on existing seams, no leaky abstractions.
- DRY — extract a helper when the duplication is real.
- KISS — the simpler shape wins.
(YAGNI is not a project principle: deliberately forward-built engine
capability in term_ui / uikit is intentional, not cruft.)
main.rs → anyclaude::ui::gpu::run (src/ui/gpu/bootstrap.rs). run wires the
config / settings / debug logger / tokio runtime / proxy server / teammate shim,
prepares the Claude Code spawn params, builds the winit event loop, and hands off
to GpuApp. There is no --gpu flag and no legacy ratatui path — the GPU
stack is the only UI (the ratatui / crossterm / alacritty / arboard stack and the
old src/{pty,ipc,ui/*.rs} were removed in the cutover).
The local HTTP reverse proxy Claude Code is pointed at, plus backend state.
proxy/— the reverse proxy:server.rs(bind + serve),router.rs(request routing + hot-swap),pipeline/(per-request stages: extract / resolve / model-rewrite / header / forward),thinking/(thinking-block registry + session cache),sse.rs+src/sse.rs(SSE parsing),pool.rs,timeout.rs,connection.rs,health.rs,hooks.rs,model_rewrite.rs,shutdown.rs.backend/—BackendState(active backend, switch log, validation) and the subagent / teammateAgentBackendStateoverrides.config/— config + Claude settings load/save (TOML),ClaudeSettingsManager.metrics/—ObservabilityHub(per-backend request counts / latency) + the per-session debug logger.args/— Claude Code spawn-param assembly (URL / session token / hooks).shim/— the teammate-routing shim prepended toPATH.
A retained + reactive UI engine (replaced the old MVI / ratatui stack).
ui/gpu/app/— theGpuAppcoordinator (a winitApplicationHandler), decomposed intomod.rs(struct +new+ consts) plus responsibility submodules:events(the event loop +ApplicationHandler),render(the per-frame paint),geometry(cell metrics / grid fit / scroll bounds / mouse hit-test),popups,clipboard,session_ops(drain PTY / restart).ui/gpu/collaborators:bootstrap(entry),overlay(the chrome + popupterm_uiretained trees and their paint pipeline),session(PTY child- VT emulator + spawn params),
text(font system + caches + palette),timers(momentum / gesture-end / 1 Hz heartbeat),backends(proxy + config handles),chrome(dimension constants),diagnostic(debug-only state dump),pty(ChildPty).
- VT emulator + spawn params),
ui/app_state.rs— the single authoritativeAppState(UI-decision state) plus theMsg/Effect/applyloop (see below).ui/pure presenters + state machines:input(key/shortcut mapping),term_geometry(layout/hit-test math),chrome_labels+popup_view(build the term_ui views),popup_anim(fade epoch), and the three popup state machinesbackend_switch/·history/·settings/(plainapply()enums, not MVI).
Every winit / user event funnels through one cycle:
event → GpuApp::dispatch → AppState::apply(Msg, &ApplyCtx) -> Vec<Effect>
→ GpuApp::perform_effects(effects)
AppStateis plain owned data — noRc/RefCell/GPU handles. It is the single state-transition point and is unit-testable without a window.applyis pure onAppState+ a read-onlyApplyCtx; every side effect (PTY write, clipboard, timers, redraw, popup toggle, …) comes back as anEffectforperform_effects— the one place state touches a resource.- The coordinator pre-resolves resource-backed facts (the cell under the cursor,
DECCKM / mouse-protocol state, the un-composed key) into a pure
Msg, leaning on pure tested helpers interm_gpu(encode_key/encode_mouse_report/encode_motion_report). See the doc comment onAppState::applyfor the reduce/resolve boundary. - Rendering (R5): the chrome bars and popups are
term_uiretained trees painted in the overlay; the terminal grid is a directpopulate_panelfull-emit each frame (the emulator has no dirty API, so a retained grid would re-emit wholesale anyway).
anyclaude is the top crate; it depends on six lower crates (never the reverse):
term_core— minimal VT parser + emulator (grid, scrollback, cursor, protocol flags). Not a full VT — scoped to Claude Code's ink TUI.term_gpu— wgpu renderer: glyph atlas (RGBA texture array, emoji-capable), cosmic-text shaping,populate_panel, cursor / selection rects, scroll math, key / mouse encoders.term_ui— the retained + reactive UI engine (arena tree, reconcile, flex-lite layout, paint). Seedocs/design/term-ui-design.mdfor the binding invariants R1–R15.uikit— reusable widgets overterm_ui(chrome bars, popup list).term_clipboard— macOSNSPasteboardclipboard (text / HTML / paths / images), with an in-memory fallback off macOS.term_layout— BSP split-panel tree. Currently exercised only byterm_gpuexamples; the live app is single-panel.
All tests live in tests/ (anyclaude) and crates/*/tests/. No #[cfg(test)]
in src/. Workspace lints: dead_code = "deny", unused_imports = "deny"
(Cargo.toml), so unused internal code can't compile. cargo check after each
commit; full cargo test --workspace at milestones.
main.rs → ui::gpu::run (bootstrap)
├── proxy / backend / config / metrics / args / shim (the proxy core)
└── GpuApp (ui/gpu/app)
├── AppState (ui/app_state — Msg/apply/Effect)
├── term_ui / uikit (retained chrome + popups)
├── term_gpu / term_core (grid render + VT)
└── term_clipboard
anyclaude → the term_* / uikit crates, never the reverse. For the UI engine's
detailed design and invariants, see docs/design/term-ui-design.md.