Skip to content

fix(accounts): follow an Orca Claude account switch when the shell sets CLAUDE_CONFIG_DIR - #29890

Merged
Jinwoo-H merged 6 commits into
mainfrom
fix/claude-switch-user-config-dir
Oct 17, 2026
Merged

Jinwoo-H merged 6 commits into
mainfrom
fix/claude-switch-user-config-dir

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​94
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

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_DIR in their shell config or environment switches accounts in Orca. /exit then claude --resume in an open terminal still runs the old account.

After: the relaunched claude runs the account selected in Orca. Switching back to System default runs their own folder again. A different CLAUDE_CONFIG_DIR typed into one terminal (for example export CLAUDE_CONFIG_DIR=/tmp/somewhere-else) still wins in that terminal, as before.

Mechanism: each Orca terminal has a claude shell function. It reads a small file, which Orca rewrites on every switch, naming the selected account's folder. Before using that file, the function ran claude unchanged whenever CLAUDE_CONFIG_DIR held 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 reads CLAUDE_CONFIG_DIR from the login shell). Changes:

  • Host terminals now always get ORCA_CLAUDE_USER_CONFIG_DIR when 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.
  • The function (bash/zsh, fish and PowerShell) treats a CLAUDE_CONFIG_DIR equal to that folder (one trailing slash ignored) as System default's folder, so it follows the selection. Any other value is still respected.
  • Terminal daemon protocol goes from 48 to 49. Hourly builds already run v48 daemons, and the daemon writes the shell wrapper, so without the bump new terminals would keep reusing a daemon with the old function. v48 stays attachable. check-daemon-protocol-crossing passes (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:

  • Dropping the respect-the-user check altogether would break people who point a single terminal at another folder on purpose.
  • Clearing CLAUDE_CONFIG_DIR at 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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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, then window.api.claudeAccounts.select({accountId: <account B>}), then in that same terminal:

Before (origin/main code):

$ env | grep -E '^(CLAUDE_CONFIG_DIR|ORCA_CLAUDE)'
CLAUDE_CONFIG_DIR=/…/swap-test/a
ORCA_CLAUDE_PROFILE_POINTER=/tmp/ocj/u/claude-profiles/selected-host
$ claude auth status --text      # selection file names the account B folder
Email: [email protected]        # stays on the old account

After (this branch):

$ env | grep -E '^(CLAUDE_CONFIG_DIR|ORCA_CLAUDE)'
CLAUDE_CONFIG_DIR=/…/swap-test/a
ORCA_CLAUDE_PROFILE_POINTER=/tmp/ocj/u/claude-profiles/selected-host
ORCA_CLAUDE_USER_CONFIG_DIR=/…/swap-test/a
$ claude auth status --text      # System default selected
Email: [email protected]
# switch to account B
$ claude auth status --text
Email: [email protected]
$ export CLAUDE_CONFIG_DIR=/…/swap-test/a/; claude auth status --text   # like a shell config export, trailing slash
Email: [email protected]
$ (export CLAUDE_CONFIG_DIR=/tmp/ocj/somewhere-else; claude auth status)
"loggedIn": false                # a deliberate other folder is still respected
# switch back to System default
$ claude auth status --text
Email: [email protected]

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: terminalEnv carries 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).
  • Shell-wrapper snapshots regenerated, and the daemon protocol tests and compatibility contract moved to 49.
  • pnpm tc:node, oxlint, and check:code-quality:changed pass.
  • PowerShell was not run (no pwsh on this machine). Windows and Linux are covered by CI.

AI Disclosure

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

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

  • 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)
  • 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)

…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.
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9239d2a5-5e6b-4849-909b-cece611e81d1
📥 Commits

Reviewing files that changed from the base of the PR and between 0ba015c and 93b8eaf.

📒 Files selected for processing: 5
  • src/main/claude-accounts/claude-profile-paths.test.ts
  • src/main/claude-accounts/claude-profile-paths.ts
  • src/main/claude-accounts/claude-profile-router.test.ts
  • src/main/claude-accounts/claude-profile-router.ts
  • src/shared/claude-shell-function.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

Terminal environments now carry the saved user config directory alongside profile configuration. POSIX, Fish, and PowerShell wrappers compare config paths after removing trailing separators, so they distinguish the saved user value from a different value set in the pane. The daemon protocol version and compatibility contract are updated from 48 to 49.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 93b8e

No confirmed issue remains that would prevent merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: Claude account switching now follows an Orca account switch when the shell sets CLAUDE_CONFIG_DIR.
Description check Passed The description is complete and addresses the required sections. It explains the user impact, implementation, rationale, testing, platform considerations, compatibility, and checklist status. The main…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and addresses the required sections. It explains the user impact, implementation, rationale, testing, platform considerations, compatibility, and checklist status. The maintainer appropriately marks the linked issue as N/A, and the unchecked full test commands are explained as CI coverage.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ef924d5-f358-4fa7-921a-b4f3477d8ea2
📥 Commits

Reviewing files that changed from the base of the PR and between d963f2a and 6f9073c.

📒 Files selected for processing: 15
  • src/main/__fixtures__/shell-wrapper-snapshots/daemon-bash-rcfile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/daemon-fish-init.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/daemon-zsh-zshenv.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-bash-rcfile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-fish-init.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zshenv.txt
  • src/main/claude-accounts/claude-profile-router.test.ts
  • src/main/claude-accounts/claude-profile-router.ts
  • src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
  • src/main/daemon/daemon-protocol-version.ts
  • src/main/daemon/macos-daemon-launchd.test.ts
  • src/shared/claude-shell-function.test.ts
  • src/shared/claude-shell-function.ts
  • src/shared/local-build-compatibility-contract.json
  • src/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.

Comment thread src/shared/claude-shell-function.ts Resolved
Jinwoo-H and others added 2 commits October 16, 2026 19:58
…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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 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 win

Normalize Git Bash paths before comparing the user override.

Git Bash can represent the same folder as C:\Users\...\config and /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 later export, 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
📥 Commits

Reviewing files that changed from the base of the PR and between 3c103de and 0ba015c.

📒 Files selected for processing: 4
  • src/main/claude-accounts/claude-profile-paths.ts
  • src/main/claude-accounts/claude-profile-router.test.ts
  • src/main/claude-accounts/claude-profile-router.ts
  • src/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.
@Jinwoo-H
Jinwoo-H merged commit 30e3119 into main Oct 17, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant