fix(auth): show the account occupying a config dir after an in-place switch-account - #13
Merged
Merged
Conversation
…switch-account accounts switch-account switches a session IN PLACE: it swaps the live auth files inside the config dir and records the new occupant in .accounts-auth/switched-account.json, without moving the dir or re-pointing the registry. The statusline resolved the profile from the registry entry keyed by dir, or from the dir's path name — both describe the dir's OWNER, so after a switch it kept rendering the old account until a fresh login landed. Read the occupant marker and let it win over both the registry and the layout name, for the profile segment and the registry-email fallback alike. The session's own live state file still wins for the email — it is what the session actually authenticates as. A dir whose marker is cleared (owner restored / fresh login) falls back to the owner as before. Sessions sharing one config dir still render identically — that is accurate, not a collapse: the dir is shared auth state and an in-place switch flips every session bound to it together.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
accounts switch-accountswitches a session's account in place: it swaps the live auth files inside the config dir and records the new occupant in.accounts-auth/switched-account.json— without moving the dir or re-pointing the registry. The statusline resolved the session profile from the registry entry keyed by dir, or from the dir's path name. Both describe the dir's owner, so after a switch the statusline kept rendering the old account indefinitely (PR #8 made resolution per-session, but per-session resolution still named the dir owner, not the dir occupant).This PR reads the occupant marker and lets it win over both the registry and the layout name — for the
auth-profilesegment and the registry-email fallback insessionAccountEmail. The session's own live state file (.claude.json→oauthAccount.emailAddress) still wins for the email, since it is what the session actually authenticates as. When the marker is cleared (owner restored or fresh login), resolution falls back to the owner exactly as before.Root-cause evidence (real machine state, spark02)
The dir
~/.hasna/accounts/profiles/claude/account088was really switched on 2026-07-29:.claude.jsonoauthAccount.emailAddress= the occupant account's email.accounts-auth/switched-account.json={ "profile": "account033", ... }.accounts-auth/oauth-account.json= the parked owner identityRendering against that dir:
account088 · hasna(stale)account033 · hasna(the actual occupant)Three dirs rendered simultaneously with this branch:
account088→account033,account002→account002,account030→account033— sessions on different accounts differ; dirs genuinely occupied by the same account agree.On "same statusline across sessions"
Sessions sharing one config dir rendering identically is accurate, not a display collapse: the dir is shared auth state, and an in-place switch flips every session bound to it together (
accountssays so itself: "3 live sessions share this config dir; all of them switch together"). After fleet account rotation, several dirs are genuinely occupied by the same account, so identical statuslines across those sessions are the truth — previously they were identical and stale.Tests
bun run typecheckRC=0,bun testRC=0 (measured unpiped),bun run buildRC=0.Notes
@hasna/accounts' claude-layout module, which owns it but exports no public reader; the code comment marks it for replacement via the same lazy import used for the registry paths if one appears. This matches the existing idiom insrc/accounts.ts(registry filename/layout constants documented as the owning package's defaults).Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.