orca icon indicating copy to clipboard operation
orca copied to clipboard

[Feature] Managed Codex account switching for SSH remote worktrees

Open vthuan1889 opened this issue 6 months ago • 2 comments

Summary

Orca's managed Codex account switcher works on host and WSL, but not on SSH remote worktrees. On SSH, Codex uses the remote user's ~/.codex/auth.json; changing the account in Orca Settings or the status bar does not affect terminals on the remote host.

I'd like SSH worktrees to support the same managed multi-account Codex workflow as local and WSL.

Problem

When using an SSH worktree:

  • Remote PTYs are spawned without Orca-injected CODEX_HOME for the selected managed account (buildPtyHostEnv is skipped when connectionId is set — see src/main/ipc/pty.ts).
  • Codex identity comes from ~/.codex on the remote machine, not from Orca's managed account list.
  • To use a different account, I must run codex login, a third-party switcher, or use separate Linux users on the server.

I use multiple Codex accounts for quota/plan rotation. Local and WSL switching in Orca is enough there; SSH is the gap.

Expected behavior

For worktrees attached to an SSH target:

  1. Select and manage multiple Codex accounts per SSH target (or per remote runtime) in Settings → AI Provider Accounts and/or the status-bar switcher.
  2. Remote Codex terminals use the selected managed account (via a prepared remote CODEX_HOME), not only whatever is in ~/.codex.
  3. Usage / rate limits reflect the active remote account, or the UI clearly states when that isn't available.
  4. Switching accounts applies to new remote Codex sessions, with an optional restart prompt for existing sessions (similar to local pane-scoped restart UX).

Why this matters

  • SSH worktrees are documented as a first-class feature: https://www.onorca.dev/docs/ssh
  • The README highlights Account Switcher & Usage Tracking as a core workflow.
  • The current behavior is easy to misread: the UI implies global Codex account control, but SSH terminals ignore it.

Precedent in this repo

WSL parity is a good model for SSH:

  • #2649 — runtime-aware managed accounts (host vs wsl)
  • #4318 — WSL launch homes with isolated auth.json
  • #4323 — shared Codex SQLite/state across launch homes

SSH could add a third runtime (e.g. runtime: 'ssh' + connectionId / targetId) with managed homes on the remote host (via relay/SFTP), not on the laptop's userData.

Current behavior (as I understand it)

  • docs/codex-account-auth-isolated-launch-homes.md lists a non-goal: "Do not redesign SSH remote Codex home handling… SSH still uses the remote user's Codex home."
  • #3032 (open) improves remote Codex runtime/hooks by copying one ~/.codex/auth.json into a remote Orca runtime home — useful for hooks, but not Orca-managed multi-account switching.
  • CodexAccountSelectionTarget is only 'host' | 'wsl' (src/main/codex-accounts/runtime-selection.ts).
  • codexHookService.installRemote notes that Codex host-managed hook registration for SSH is not available yet.

This issue asks to revisit the SSH non-goal now that host/WSL launch homes are in place.

Proposed direction (suggestion)

  1. Extend CodexAccountSelectionTarget for SSH (e.g. { runtime: 'ssh', connectionId, targetId }).
  2. Keep credentials in Orca userData; materialize the selected launch home on the remote during launch/PTY spawn (similar to WSL, over SSH).
  3. Set remote PTY CODEX_HOME / ORCA_CODEX_HOME to that home without leaking host paths or local hook tokens (preserve the SSH env guard in pty.ts and #1308 notes).
  4. Fetch rate limits from the remote launch home when possible; otherwise show a clear degraded state.
  5. Default new SSH targets to System default (~/.codex on the remote) until the user configures managed accounts.

Acceptance criteria

  • [ ] I can store two or more managed Codex accounts and pick the active one per SSH target.
  • [ ] A new Codex terminal in an SSH worktree uses the selected account without manual codex login on the server.
  • [ ] Switching accounts in Orca and starting a new remote Codex session uses the new account.
  • [ ] Host and WSL behavior is unchanged.
  • [ ] Host userData paths and local hook tokens are not injected into remote PTY env.
  • [ ] Docs updated (/docs/ssh, usage tracking) to describe remote managed accounts vs system default.

Alternatives considered

Approach Pros Cons
Document-only: use codex-switch on the server No Orca work Worse UX vs host/WSL
One SSH target = one Linux user Strong isolation High operational cost
Overwrite remote ~/.codex on switch Simple mental model Mutates shared global Codex state on the server

Environment

  • Orca version: (not specified — reporter on latest public release)
  • Client OS: Linux (TrueNAS host environment)
  • SSH target: (user to fill in if needed)
  • Remote Codex CLI: (user to fill in if needed)

Related

  • #3032 — remote Codex runtime home (single-auth copy)
  • #2323 — SSH workspace sync / codex resume
  • #4318, #2649 — WSL parity
  • docs/codex-account-auth-isolated-launch-homes.md

vthuan1889 avatar Jun 01 '26 11:06 vthuan1889

Update after the SSH relay was retired (#27214, #27215): SSH terminals now start inside the host's managed Orca server, so the relay-era buildPtyHostEnv/connectionId detail no longer applies. The request still stands, though: the status-bar switcher only targets this computer or a paired server, so for an SSH workspace Codex still uses the host's own ~/.codex (or that server's account selection) instead of the account picked on the desktop.

OrcaWin avatar Oct 11 '26 06:10 OrcaWin

This is fixed on main and shipped in v1.4.261: SSH projects now run on the host's own managed Orca server, so the status-bar Codex switcher, Add Account and usage all act on that host (#27214, #27687, #31461, #29430).

Please update to the latest Orca and try again. If you still see it, comment here and we'll reopen.

AmoabaKelvin avatar Nov 17 '26 22:11 AmoabaKelvin