Description
Problem or use case
Summary: Let each worktree bind to a specific Claude managed account, so multiple worktrees can run different accounts at the same time.
Today, Claude account selection is global per host (activeClaudeManagedAccountId / activeClaudeManagedAccountIdsByRuntime, resolved in src/main/claude-accounts/runtime-selection.ts). New launches inherit the one active account, and switching is global — it re-materializes shared ~/.claude and is gated against live sessions (live-pty-gate). So you can't run worktree A on a work account and worktree B on a personal account concurrently, and per-project defaults aren't possible.
This is the concurrency superset of the per-project requests in #5203 and #5635, and it's the workflow heavy parallel-agent users hit immediately (e.g. spreading load across accounts, or keeping work and personal subscriptions separated per worktree).
Proposed solution
Add an optional claudeAccountId bound to the worktree (first-class, not per-PTY), and at launch inject that account's CLAUDE_CONFIG_DIR instead of materializing creds into shared ~/.claude.
The mechanism already exists in-tree: Orca's WSL path does exactly this per-account injection (src/main/claude-accounts/runtime-auth-service.ts:640-648 → { configDir: managedAuthPath, envPatch: { CLAUDE_CONFIG_DIR }, stripAuthEnv: true }). The host path is the only one that materializes instead. Proposal: when a worktree has an assigned account, the host path returns the same WSL-shaped injection and doSyncForCurrentSelection early-returns — bypassing materialization, the live-pty-gate switch block, and read-back. Unassigned worktrees are unchanged (purely additive).
Binding & resolution (pinning across agent churn). The assignment is durable worktree metadata (claudeAccountId on WorktreeMeta), resolved fresh at every spawn (worktreeId → account → CLAUDE_CONFIG_DIR, injected per-terminal and inherited by child agents). Nothing global is mutated and nothing is cached on the agent, so agents spawning/despawning in any order across worktrees stay deterministically pinned to their worktree's account (e.g. 6 worktrees split 2-on-account-A / 4-on-account-B, cycling agents continuously, never drift).
Isolation unit = account/config-dir; refresh is CLI-owned. Multiple worktrees may bind the same account (in the example above, 2 config dirs with several live tenants each), so config dirs are multi-tenant. Crucially, doSyncForCurrentSelection early-returns for injected accounts — Orca does no proactive refresh, read-back, or materialization for a pinned account; each Claude CLI manages its own config dir's tokens. So the multi-tenant refresh race is owned by the Claude CLI per config dir (Orca isn't doing the refresh and so can't lock it), and injected accounts never touch the shared ~/.claude runtime. The only coordination change needed is exempting injected launches from the global isClaudeAuthSwitchInProgress switch-block (they don't use shared creds, so a global account switch must not stall a pinned-worktree launch) — no new lock or gate rearchitecture. Token rotation (#6234) is preserved: each injected dir is single-tenant from Orca's side and the CLI refreshes it in place.
Cross-platform (verified — src/main/claude-accounts/keychain.ts credential ops are darwin-only no-ops):
| Platform | Work needed |
|---|---|
| Linux / Windows / SSH-remote host | None — file-based; simpler than today's materialize-to-shared |
| WSL | Already shipped (this is the WSL path) |
| macOS | Seed the scoped Keychain service Claude Code-credentials-<sha256(configDir)[:8]> once per launch (reuse getActiveClaudeService) |
UI: account selector in the create-worktree modal (beside the Agent picker in NewWorkspaceComposerCard) + an "Assign Account" submenu in WorktreeContextMenu (mirroring "Move to Status"). Accounts filtered by the worktree's runtime (a WSL worktree binds a WSL account, etc.).
We're ready to implement this and open the PR. We've already traced the full implementation path — data model on WorktreeMeta, launch-time resolution in pty.ts, the host-injection branch in runtime-auth-service.ts, exempting injected launches from the global switch-block, and the two UI surfaces — and can start as soon as you confirm the approach fits your intended direction. We're raising the design first only to align before writing code. v1 scope: binding + launch injection + the two UI surfaces; per-worktree usage/rate-limit display deferred as a documented limitation. Happy to adjust scope or structure to match your preferences.
Alternatives or additional context
- Related: [Feature] Different Claude Accounts for different projects #5203 and [Feature] Multiple AI Account, Per Project? #5635 (per-project accounts, both labeled P1), Add multi-provider auth methods and per-account model mapping to Claude managed accounts #2314 (multi-provider — @nwparker's triage flagged the same
getPreparation/environment.tsauth boundary this touches), [Feature]: Make Orca's managed Claude (cloud subscription) auth survive token rotation — stop daily re-auth #6234 (survive token rotation). - Designing around reviewer concerns already raised on Add multi-provider auth methods and per-account model mapping to Claude managed accounts #2314: the binding is worktree-scoped (not the "Per-PTY 2/10" pattern), and macOS seeds the scoped Keychain service once per launch, not per token op (avoids "N+1 keychain").
- Open questions for maintainers: preferred home for the binding (on
WorktreeMeta, following theworkspaceStatusprecedent?), and whether you'd want per-worktree usage display in v1 or as a follow-up.
Activity
srs-adamr commentedon Jun 30, 2026
Implemented in #6963 (draft) — branch
srs-adamr/feat-per-worktree-claude-account, rebased on currentmain. Covers the additiveclaudeAccountIdbinding, host injection reusing the WSL path, the macOS scoped-keychain seed, the switch-block exemption, and the two UI surfaces (account selector + Assign Account submenu). Zero new test failures vs main.metheoryt commentedon Aug 1, 2026
Answering your open question — "preferred home for the binding (on
WorktreeMeta, following theworkspaceStatusprecedent?)" — with a suggestion for one extra tier in the resolution chain: project group.To be clear up front: per-project (this issue's per-project defaults, plus #5203 / #7782) already covers my immediate need, and it satisfies the #10922 constraint the same way — a static binding resolved at spawn, rather than a runtime switch. So this is not "group instead of project". The narrower claim is that group is the zero-config inheritance tier: drop a new repo into an existing group and it is already bound, with no per-repo step. For anyone who organises the sidebar by client/employer/personal, that's the difference between binding once and binding once per repo forever.
Orca already scopes a runtime-affecting setting to a project group
This isn't a new mechanism —
executionHostIdonProjectGroupalready does exactly this, and the resolver shape you'd need for accounts is shipped. Derived from the packaged bundle (v1.4.162), so worth confirming against source, but the behaviour is:projectGroupId, finds that group, and uses the group'sexecutionHostId; the repo's own value wins and the group is the fallback. The same repo-then-group precedence is applied toconnectionId.folderWorkspaceId→ its folder workspace →projectGroupId→ group →executionHostId.parentGroupId, and there is already a cycle-guarded walk up the parent chain (used for the group breadcrumb path). So inheritance through nested groups needs no new traversal.GroupExecutionHostId,GroupExecutionHostIdForRows,GroupExecutionHostIdForFolderPathStatus), not an ad-hoc lookup.The ask, in one sentence
Put the account binding on
ProjectGroupalongsideexecutionHostId, and resolve it through the same precedence walk: worktree → repo → group chain (viaparentGroupId) → global.That composes with the worktree binding proposed here rather than competing with it — worktree stays the most specific tier, and #7782's proposed hierarchy just gains one level between project and global.
Durability note
projectGroupsis persisted config, not transient sidebar state — it lives inorca-data.jsonwithid,name,parentGroupId,connectionId,createdAt/updatedAt, etc. But it is per-profile and machine-local: the file sits underprofiles/<profile>/, so a group binding would not follow a user to a second machine. That's fine for the execution-host precedent (hosts are machine-specific anyway) and probably fine for accounts, but it is worth being deliberate about, since an account identity is conceptually portable in a way an execution host isn't.Related: #7782 (project/worktree hierarchy), #5203, and #10922 — on a headless
orca serveruntime, account switching does not work at all, which makes a static bound-at-spawn account the only viable model there rather than a convenience.