Skip to content

fix(auth): show the account occupying a config dir after an in-place switch-account - #13

Merged
andrei-hasna merged 1 commit into
mainfrom
fix/statusline-switched-account-marker
Jul 30, 2026
Merged

fix(auth): show the account occupying a config dir after an in-place switch-account#13
andrei-hasna merged 1 commit into
mainfrom
fix/statusline-switched-account-marker

Conversation

@andrei-hasna

@andrei-hasna andrei-hasna commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What

accounts switch-account switches 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-profile segment and the registry-email fallback in sessionAccountEmail. The session's own live state file (.claude.jsonoauthAccount.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/account088 was really switched on 2026-07-29:

  • live .claude.json oauthAccount.emailAddress = the occupant account's email
  • .accounts-auth/switched-account.json = { "profile": "account033", ... }
  • .accounts-auth/oauth-account.json = the parked owner identity

Rendering against that dir:

build first line
installed 0.0.4 (before) account088 · hasna (stale)
this branch 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 (accounts says 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

  • TDD: 8 new tests written first, 6 failed on unfixed code (positive control), all 183 pass after: switch flip, occupant-over-layout, nameless occupant suppresses stale owner name, marker clear restores owner, corrupt marker degrades, two dirs differ simultaneously, occupant email beats owner registry email, live state file still beats marker email.
  • bun run typecheck RC=0, bun test RC=0 (measured unpiped), bun run build RC=0.

Notes

  • The marker filename mirrors @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 in src/accounts.ts (registry filename/layout constants documented as the owning package's defaults).
  • No dependency changes.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…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.
@andrei-hasna
andrei-hasna merged commit ea96624 into main Jul 30, 2026
2 checks passed
@andrei-hasna
andrei-hasna deleted the fix/statusline-switched-account-marker branch July 30, 2026 09:25
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