Repository navigation
fix(accounts): follow an Orca Claude account switch when the shell sets CLAUDE_CONFIG_DIR - #29890
Conversation
…ts CLAUDE_CONFIG_DIR A user whose shell config or environment sets CLAUDE_CONFIG_DIR switched Claude accounts in Orca, but `claude` relaunched in an open terminal kept running the old account: the terminal's claude function treated any CLAUDE_CONFIG_DIR it did not inject as a deliberate per-terminal override. Host terminals now always carry the user's own folder (ORCA_CLAUDE_USER_CONFIG_DIR, from the login shell's env), also on System default and before that env arrives. The claude function (POSIX, fish, PowerShell) treats a CLAUDE_CONFIG_DIR equal to it, ignoring a trailing separator, as System default's folder and follows the selected account; any other value set in the terminal still wins. WSL panes carry no user folder, so they behave as before. The terminal daemon protocol moves to 49: hourly builds already run v48 daemons whose wrapper has the old function. v48 stays attachable.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3ef924d5-f358-4fa7-921a-b4f3477d8ea2
📒 Files selected for processing: 15
src/main/__fixtures__/shell-wrapper-snapshots/daemon-bash-rcfile.txtsrc/main/__fixtures__/shell-wrapper-snapshots/daemon-fish-init.txtsrc/main/__fixtures__/shell-wrapper-snapshots/daemon-zsh-zshenv.txtsrc/main/__fixtures__/shell-wrapper-snapshots/local-bash-rcfile.txtsrc/main/__fixtures__/shell-wrapper-snapshots/local-fish-init.txtsrc/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zshenv.txtsrc/main/claude-accounts/claude-profile-router.test.tssrc/main/claude-accounts/claude-profile-router.tssrc/main/daemon/daemon-foreground-confirmation-protocol.test.tssrc/main/daemon/daemon-protocol-version.tssrc/main/daemon/macos-daemon-launchd.test.tssrc/shared/claude-shell-function.test.tssrc/shared/claude-shell-function.tssrc/shared/local-build-compatibility-contract.jsonsrc/shared/local-build-compatibility-contract.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
…its separators Orca records the user's CLAUDE_CONFIG_DIR resolved (backslashes on Windows), so a pane value written with forward slashes read as a deliberate override and stopped following the account switch. Co-Authored-By: Claude <[email protected]>
…ly as set Claude keys its login by the literal folder string, so a resolved spelling (a dropped trailing slash) could switch System default to another saved login, and Git Bash on Windows compared a backslash spelling against its rc's forward one.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Normalize Git Bash paths before comparing the user override. · claude-shell-function.ts:19-21
src/shared/claude-shell-function.ts:19-21
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winNormalize Git Bash paths before comparing the user override.
Git Bash can represent the same folder as
C:\Users\...\configand/c/Users/.../config. The guard only removes trailing/, so it treats these values as different and returns before applying the selected profile. Normalize only the comparison operands. Keep the original values for the laterexport, so different-directory overrides remain effective.Suggested fix
local __orca_claude_home __orca_claude_pointer="\${ORCA_CLAUDE_PROFILE_POINTER:-}" + __orca_claude_normalize_config_dir() { + local __orca_claude_path="$1" __orca_claude_drive + case "$__orca_claude_path" in + /[A-Za-z]/*) + __orca_claude_drive="\${__orca_claude_path#?}" + __orca_claude_drive="\${__orca_claude_drive%%/*}" + __orca_claude_path="/$(printf '%s' "$__orca_claude_drive" | tr '[:upper:]' '[:lower:]')\${__orca_claude_path#??}" + ;; + [A-Za-z]:/*|[A-Za-z]:\\\\*) + __orca_claude_drive="\${__orca_claude_path%%:*}" + __orca_claude_path="/$(printf '%s' "$__orca_claude_drive" | tr '[:upper:]' '[:lower:]')\${__orca_claude_path#??}" + __orca_claude_path="$(printf '%s' "$__orca_claude_path" | sed 's#\\\\#/#g')" + ;; + esac + printf '%s' "\${__orca_claude_path%/}" + } # Why: a WSL pane's pointer is relative to the guest home, which the host cannot know at spawn. case "$__orca_claude_pointer" in '~/'*) __orca_claude_pointer="\${HOME:-}/\${__orca_claude_pointer#??}" ;; esac __orca_claude_home="$(cat "$__orca_claude_pointer" 2>/dev/null || :)" if [ -n "\${CLAUDE_CONFIG_DIR:-}" ] && [ "$CLAUDE_CONFIG_DIR" != "\${ORCA_CLAUDE_INJECTED_CONFIG_DIR:-}" ] && - { [ -z "\${ORCA_CLAUDE_USER_CONFIG_DIR:-}" ] || [ "\${CLAUDE_CONFIG_DIR%/}" != "\${ORCA_CLAUDE_USER_CONFIG_DIR%/}" ]; }; then + { [ -z "\${ORCA_CLAUDE_USER_CONFIG_DIR:-}" ] || + [ "$(__orca_claude_normalize_config_dir "$CLAUDE_CONFIG_DIR")" != "$(__orca_claude_normalize_config_dir "$ORCA_CLAUDE_USER_CONFIG_DIR")" ]; }; then
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e5f08c4a-ca4a-4ac3-82fe-cd27b2aa8e2a
📒 Files selected for processing: 4
src/main/claude-accounts/claude-profile-paths.tssrc/main/claude-accounts/claude-profile-router.test.tssrc/main/claude-accounts/claude-profile-router.tssrc/shared/claude-shell-function.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
…ne base pane env The resolved reader now derives from the as-set one, every host pane env builds on one base patch, and the router tests share one shell probe.
ELI5
Some people tell Claude which config folder to use from their shell setup (
export CLAUDE_CONFIG_DIR=...). For them, switching Claude accounts in Orca did nothing in open terminals: quitting Claude and starting it again stayed on the old account, while Orca's status bar showed the new one. Now relaunching Claude follows the account picked in Orca, the same as for everyone else.What Changed
Before: a user who sets
CLAUDE_CONFIG_DIRin their shell config or environment switches accounts in Orca./exitthenclaude --resumein an open terminal still runs the old account.After: the relaunched
clauderuns the account selected in Orca. Switching back to System default runs their own folder again. A differentCLAUDE_CONFIG_DIRtyped into one terminal (for exampleexport CLAUDE_CONFIG_DIR=/tmp/somewhere-else) still wins in that terminal, as before.Mechanism: each Orca terminal has a
claudeshell function. It reads a small file, which Orca rewrites on every switch, naming the selected account's folder. Before using that file, the function ranclaudeunchanged wheneverCLAUDE_CONFIG_DIRheld something Orca had not put there, because it treated that as the user's own choice for that terminal. A shell config export, or a value inherited when the terminal opened on System default, always fell into that case. Orca already knows the user's own folder (it readsCLAUDE_CONFIG_DIRfrom the login shell). Changes:ORCA_CLAUDE_USER_CONFIG_DIRwhen the user has their own folder. This includes terminals opened on System default and terminals opened before the login shell has been read. Until now it was only set when Orca injected an account folder.CLAUDE_CONFIG_DIRequal to that folder (one trailing slash ignored) as System default's folder, so it follows the selection. Any other value is still respected.check-daemon-protocol-crossingpasses (1.4.227 at v47 → candidate at v49: live terminals adopted).WSL panes still get only the selection-file path. The host can't see the guest's
CLAUDE_CONFIG_DIR, so their behaviour doesn't change. SSH panes never get the selection file, so the function isn't defined there.Why
The function already had to tell "a value the user chose for this terminal" apart from "the user's normal folder". It just had no way to recognise the normal folder unless Orca had replaced it. Giving it the folder Orca already resolves is the smallest change that fixes both the spawn-time case and the shell-config export case. Alternatives considered:
CLAUDE_CONFIG_DIRat spawn wouldn't help, because the shell config runs after spawn and exports it again.Linked Issue
N/A (maintainer; reproduced live).
Visual Proof
N/A: there is no UI change. The terminal output before and after is under Testing.
Testing
Real app (macOS, dev build launched in the background with
CLAUDE_CONFIG_DIR=<own folder signed in as account A>and an isolated Orca profile that has one saved account, account B). Terminal opened while System default was selected, thenwindow.api.claudeAccounts.select({accountId: <account B>}), then in that same terminal:Before (origin/main code):
After (this branch):
Automated:
src/shared/claude-shell-function.test.ts: runs the real function in bash, zsh and fish. Covers the user's own folder (inherited, or exported after Orca injected an account) following the selection, System default restoring it, a different folder being respected, no user folder behaving as before, and string checks for the PowerShell variant.src/main/claude-accounts/claude-profile-router.test.ts:terminalEnvcarries the user folder on System default, plus an end-to-end bash run (System default at spawn → account switch follows; shell config export after injection follows; another folder wins).pnpm tc:node, oxlint, andcheck:code-quality:changedpass.AI Disclosure
Review
Agent skill upstream boundary
Notes
Security: no new data leaves the machine. The variable holds a folder path the user already exports. SSH: unaffected (no selection file on remote panes). WSL: unchanged. Backwards compatibility: older daemons stay attachable, and a terminal from an older daemon keeps the old function until it is reopened.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)