You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(accounts): keep a caller's own Claude/Codex account at spawn - #44636
If a script starts an agent and says "use this account", Orca should start it on that account. On a computer where you picked a different account in Orca's settings, Orca swapped in your picked account at the last moment, so the agent started (and was remembered) under the wrong account.
What Changed
Before: agent.launch / terminal create with accountEnv: { CLAUDE_CONFIG_DIR } or { CODEX_HOME } (or the same keys in env) on a host with Orca-managed Claude or Codex accounts. withHostAccountLaunchEnv keeps the caller's keys over the plan, but the runtime spawn preflight then replaced them:
withClaudeProfileTerminalEnv (claude-profile-installed-router.ts) spreads the selected profile's CLAUDE_CONFIG_DIR, ORCA_CLAUDE_INJECTED_CONFIG_DIR and ORCA_CLAUDE_PROFILE_POINTER over the caller's env ({ ...env, ...profileEnv }). Even a kept CLAUDE_CONFIG_DIR would lose: with the injected marker equal to it, the claude shell function re-reads the host pointer and runs the selected account.
prepareClaudeAuth(target) prepares the host's selected account and its envPatch is spread over the env again (ipc/pty/runtime/spawn-preflight.ts). It can also fail the launch on the selected account's own setup problems.
Codex: resolvePtySpawnHostEnv takes the pane's home from getSelectedCodexHomePath, which returns the selected managed account's home whatever CODEX_HOME the launch carries. That path becomes the pane's CODEX_HOME/ORCA_CODEX_HOME (daemon buildPtyHostEnv, local codexHomePathOverride) and is what onCodexHomePtySpawned records for the pane.
After: the caller's own account variables (AGENT_LAUNCH_ACCOUNT_ENV_KEYS taken from the request's env and accountEnv) ride to spawn as accountEnv on the runtime PTY spawn args. When they name CLAUDE_CONFIG_DIR, the preflight keeps them and adds no host profile env or pointer, and does not prepare the selected account's Claude auth. When they name CODEX_HOME, that path is the pane's Codex home, so the pane runs and is recorded under it. Launches without a caller account are unchanged.
Why
withHostAccountLaunchEnv already says "explicit caller env/accountEnv still wins". The spawn path reversed that only on hosts with managed accounts. The fix carries that precedence one step further, to the only place that knows which keys came from the caller. Deciding from env at spawn was the other option. It would let a user's agentDefaultEnvCLAUDE_CONFIG_DIR/CODEX_HOME beat their account selection, which the plan merge deliberately does not do.
Linked Issue
None. I searched open PRs and issues for this first.
Visual Proof
N/A: no UI change. This changes which account a programmatic launch's process gets.
Testing
spawn-preflight-caller-account.test.ts (runtime spawn preflight): a Claude launch with a caller CLAUDE_CONFIG_DIR keeps it, with no host pointer and no prepareClaudeAuth call. A Codex launch with a caller CODEX_HOME gets it as the pane's Codex home. Without a caller account, both still get the host's selection.
host-account-launch-env.test.ts: withHostAccountLaunchEnv carries only the caller's account keys to spawn, also when this host pushes none.
Both fail with the fix reverted (results below).
oxlint, oxfmt --check, tc:node, tc:web, tc:cli, and the neighbouring suites (src/main/ipc/pty/**, src/main/runtime/terminal/launch/*, the Claude profile router, account env schema) ran on Linux.
Results (Linux x64, git 2.43.0, branch on v1.4.263; the same patch applies unchanged to main at e340748, which CI will cover):
New tests: 3/3 pass. With the source changes reverted (tests kept), all 3 fail: the caller's CLAUDE_CONFIG_DIR comes back as the selected profile's home, the Codex home comes back as the selected account's home, and accountEnv is undefined.
Neighbours: 14 files, 44/45 in one parallel run. The one failure was spawn-push-target-materialization-real-git.test.ts (a real-git fixture, 11.8 s, upstream config read back ''). It passed 2/2 when run alone with this change and 1/1 without it, so it looks load-sensitive and is not touched by this diff.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
Only launches whose request carries account keys behave differently. One case to know: a request env copied from an existing Orca pane (with Orca's own injected CLAUDE_CONFIG_DIR and pointer) now counts as a caller account. Its pointer is kept, so the shell's claude still follows the selection, but spawn no longer waits on the selected account's setup for it. The renderer IPC spawn path carries no caller account and is unchanged. Back out with a plain revert. Nothing is persisted in a new format.
Level: Low
AI Disclosure
Prepared with Claude (Anthropic), reviewed by the submitter.
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
SSH workspaces return before host account env (unchanged). The WSL target path is unchanged except that a caller's CLAUDE_CONFIG_DIR also suppresses the WSL pointer there.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
An agent launch that names its own account (CLAUDE_CONFIG_DIR or CODEX_HOME in
`env`/`accountEnv`) already wins over the desktop-pushed account in
withHostAccountLaunchEnv. On a host with Orca-managed accounts the spawn
preflight then replaced it: withClaudeProfileTerminalEnv spread the selected
profile's CLAUDE_CONFIG_DIR, injected marker and pointer over it,
prepareClaudeAuth patched in the selected account again, and the Codex home
selection set CODEX_HOME to the selected account's home and recorded the pane
under it.
The caller's account variables now ride to spawn as `accountEnv`. The runtime
preflight keeps them over the profile env, skips the selected account's Claude
auth preparation, and uses the caller's CODEX_HOME as the pane's Codex home.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The launch path now carries caller account variables through terminal startup and PTY spawn. Recognized caller values take precedence over matching host-provided values. During spawn preparation, a caller-provided Claude config directory bypasses installed-profile environment handling and Claude auth preparation. A caller-provided Codex home takes precedence over the host-selected home. Tests cover caller-provided and fallback paths.
Merge Risk: Moderate · up to 14359
Programmatic launches that supply their own Claude or Codex account mostly keep that account. Resumed Codex sessions can still run under a different home than the one requested. Claude launches can retain a host profile pointer, and they can still wait on host account setup. Resolve the resume behavior and the pointer cleanup before merge.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a caller's own Claude/Codex account is kept at spawn, which matches the summaries (caller CLAUDE_CONFIG_DIR/CODEX_HOME carried as accountEnv and preserved in the runti…
Description check
The description follows the repository template closely. It has ELI5, What Changed (before/after and mechanism), Why (with the alternative considered), Linked Issue (explicitly 'None', with a search n…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: a caller's own Claude/Codex account is kept at spawn, which matches the summaries (caller CLAUDE_CONFIG_DIR/CODEX_HOME carried as accountEnv and preserved in the runtime PTY spawn preflight). The 'fix(accounts)' prefix is a conventional-commit style and the title is 64 characters, a single sentence.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed (before/after and mechanism), Why (with the alternative considered), Linked Issue (explicitly 'None', with a search note), Visual Proof (N/A with reason), Testing (test files, results, and the one unrelated flaky failure), Risk (level Low, scope of impact, and back-out path), AI Disclosure, Agent skill boundary, Notes, and Checklist. Gaps: the Linked Issue section has no 'Fixes #' issue and the template says outside contributors need an actual issue. The final pnpm lint/typecheck/test/build checklist item is unchecked, and the Testing section says CI will cover the main branch run. The author also states the change was tested on Linux only, so cross-platform coverage is not verified.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Minor · Skip host Claude account preparation when the caller… · runtime-agent-terminal-startup.ts:305-306
src/main/runtime/terminal/launch/runtime-agent-terminal-startup.ts:305-306 Minor · Stability & Availability · Quick win
Skip host Claude account preparation when the caller supplies CLAUDE_CONFIG_DIR.
prepareHostAgentTerminalLaunch awaits prepareHostAgentLaunch before it extracts the caller's account keys. For a Claude launch, the host-selected folder is refreshed even when the caller already supplies CLAUDE_CONFIG_DIR. The launch then waits for that refresh, and on a fresh WSL host it can also wait up to 5 seconds for the first desktop push. A rejected refresh also fails the launch, since refreshSelectedClaudeProfile does not catch errors.
Extract the caller account keys before this await. When they include CLAUDE_CONFIG_DIR, skip the selected-account Claude preparation. The required behavior is that a caller-pinned Claude launch does not depend on host account setup. Decide separately whether the first-push gate should also be skipped for those launches.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ccf90748-7fdb-458e-b7ad-d884028be0c5
Commits
Reviewing files that changed from the base of the PR and between 5e86110 and 143594c.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Remove the inherited profile pointer from the caller-account result.
When env carries ORCA_CLAUDE_PROFILE_POINTER, the spread at line 47 keeps it after the caller's CLAUDE_CONFIG_DIR is applied. The caller-account path must omit the host pointer. The shell wrapper reads the pointer when the caller's CLAUDE_CONFIG_DIR equals ORCA_CLAUDE_USER_CONFIG_DIR, so it can replace the caller's directory with the host account's home. Delete the key from the merged result.
Import CLAUDE_PROFILE_POINTER_ENV from src/shared/agent-accounts/claude/claude-profile-routing.ts. Add test coverage for a request env that already contains the pointer.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Heavy lift
Resumed launches can record a different Codex home than the caller's CODEX_HOME.
When accountEnv supplies CODEX_HOME and the launch resumes a session whose transcript resolves to an unshared home A, the pane records A. Resume preparation accepts launchEnv but never reads it. The reconciliation step then returns A without comparing it with the caller's home. The selector at spawn-host-env.ts:144 never runs for this resume, so the caller's value is dropped with no error.
The PR states that a caller-specified CODEX_HOME becomes the pane's home. This path breaks that contract without a signal. The pane runs under A when the caller asked for B.
Make the resumed path either honor the caller's CODEX_HOME for the recorded pane home, or fail the launch with a clear conflict. Do not return A silently. The choice between these two behaviors needs a decision from the author, so no patch is proposed here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
If a script starts an agent and says "use this account", Orca should start it on that account. On a computer where you picked a different account in Orca's settings, Orca swapped in your picked account at the last moment, so the agent started (and was remembered) under the wrong account.
What Changed
Before:
agent.launch/ terminal create withaccountEnv: { CLAUDE_CONFIG_DIR }or{ CODEX_HOME }(or the same keys inenv) on a host with Orca-managed Claude or Codex accounts.withHostAccountLaunchEnvkeeps the caller's keys over the plan, but the runtime spawn preflight then replaced them:withClaudeProfileTerminalEnv(claude-profile-installed-router.ts) spreads the selected profile'sCLAUDE_CONFIG_DIR,ORCA_CLAUDE_INJECTED_CONFIG_DIRandORCA_CLAUDE_PROFILE_POINTERover the caller's env ({ ...env, ...profileEnv }). Even a keptCLAUDE_CONFIG_DIRwould lose: with the injected marker equal to it, theclaudeshell function re-reads the host pointer and runs the selected account.prepareClaudeAuth(target)prepares the host's selected account and itsenvPatchis spread over the env again (ipc/pty/runtime/spawn-preflight.ts). It can also fail the launch on the selected account's own setup problems.resolvePtySpawnHostEnvtakes the pane's home fromgetSelectedCodexHomePath, which returns the selected managed account's home whateverCODEX_HOMEthe launch carries. That path becomes the pane'sCODEX_HOME/ORCA_CODEX_HOME(daemonbuildPtyHostEnv, localcodexHomePathOverride) and is whatonCodexHomePtySpawnedrecords for the pane.After: the caller's own account variables (
AGENT_LAUNCH_ACCOUNT_ENV_KEYStaken from the request'senvandaccountEnv) ride to spawn asaccountEnvon the runtime PTY spawn args. When they nameCLAUDE_CONFIG_DIR, the preflight keeps them and adds no host profile env or pointer, and does not prepare the selected account's Claude auth. When they nameCODEX_HOME, that path is the pane's Codex home, so the pane runs and is recorded under it. Launches without a caller account are unchanged.Why
withHostAccountLaunchEnvalready says "explicit caller env/accountEnv still wins". The spawn path reversed that only on hosts with managed accounts. The fix carries that precedence one step further, to the only place that knows which keys came from the caller. Deciding fromenvat spawn was the other option. It would let a user'sagentDefaultEnvCLAUDE_CONFIG_DIR/CODEX_HOMEbeat their account selection, which the plan merge deliberately does not do.Linked Issue
None. I searched open PRs and issues for this first.
Visual Proof
N/A: no UI change. This changes which account a programmatic launch's process gets.
Testing
spawn-preflight-caller-account.test.ts(runtime spawn preflight): a Claude launch with a callerCLAUDE_CONFIG_DIRkeeps it, with no host pointer and noprepareClaudeAuthcall. A Codex launch with a callerCODEX_HOMEgets it as the pane's Codex home. Without a caller account, both still get the host's selection.host-account-launch-env.test.ts:withHostAccountLaunchEnvcarries only the caller's account keys to spawn, also when this host pushes none.tc:node,tc:web,tc:cli, and the neighbouring suites (src/main/ipc/pty/**,src/main/runtime/terminal/launch/*, the Claude profile router, account env schema) ran on Linux.Results (Linux x64, git 2.43.0, branch on
v1.4.263; the same patch applies unchanged tomainat e340748, which CI will cover):oxlint 0 warnings / 0 errors; oxfmt --check clean;
tc:node,tc:web,tc:cli0 errors.New tests: 3/3 pass. With the source changes reverted (tests kept), all 3 fail: the caller's
CLAUDE_CONFIG_DIRcomes back as the selected profile's home, the Codex home comes back as the selected account's home, andaccountEnvisundefined.Neighbours: 14 files, 44/45 in one parallel run. The one failure was
spawn-push-target-materialization-real-git.test.ts(a real-git fixture, 11.8 s, upstream config read back''). It passed 2/2 when run alone with this change and 1/1 without it, so it looks load-sensitive and is not touched by this diff.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
Only launches whose request carries account keys behave differently. One case to know: a request env copied from an existing Orca pane (with Orca's own injected
CLAUDE_CONFIG_DIRand pointer) now counts as a caller account. Its pointer is kept, so the shell'sclaudestill follows the selection, but spawn no longer waits on the selected account's setup for it. The renderer IPC spawn path carries no caller account and is unchanged. Back out with a plain revert. Nothing is persisted in a new format.Level: Low
AI Disclosure
Prepared with Claude (Anthropic), reviewed by the submitter.
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
SSH workspaces return before host account env (unchanged). The WSL target path is unchanged except that a caller's
CLAUDE_CONFIG_DIRalso suppresses the WSL pointer there.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code