fix(desktop): stop Usage "Add account" from replacing a signed-in profile

Closed
HA
2d ago
+192-4

What & why

Part of PARA-3523 ("adding accounts in Usage is broken").

In Settings → Usage → Add account, the profile name always defaulted to work, and nothing checked it against the profiles already on the host. Adding a second Claude or Codex account with the prefilled name ran claude auth login (or codex login) again in ~/.claude-work / ~/.codex-work. That replaced the first account, and because findCompletedLogin accepts a CLI that exits 0, the dialog still reported " is signed in". The user ends up with one account where they expected two.

Changes

  • utils/profileNames (new): freeProfileName picks the first of work, work-2, … that is not a signed-in profile. isProfileSignedIn compares against the host's logins list, normalizing separators and a trailing slash.
  • AddAccountDialog:
    • The default name follows each poll until the user edits it, so a stale cache can't leave a taken default, and typing is never overwritten.
    • A typed name that maps to a signed-in profile disables Sign in and hides the copy-paste command (remote host), with an inline message.
    • Switch sign-in (switchTarget) is unchanged.
  • 1 new string, translated into all 17 locales.

How I tested it

  • bun test src/renderer/routes/_authenticated/settings/usage: 50 pass (4 new in profileNames.test.ts).
  • tsc --noEmit for desktop is clean, biome is clean, and bun run check:i18n passes.
  • I rendered the real dialog in Storybook against a host that already has ~/.claude-work signed in (a throwaway story, not committed):
    • Before: the default is work and Sign in is enabled.
    • After: the default is work-2, and typing work blocks Sign in.
  • Not tested: a real second browser login in the desktop app. This sandbox has no signed-in desktop session.
  • A subagent reviewed the change. I fixed its findings: the copy-paste path wasn't blocked, the default came from stale cache, and the path comparison was exact-string.

Screenshots, video, and the cloud chat sign-in verification for PARA-3523: https://app.superset.sh/page/para-3523-chat-sign-in-cloud-and-usage-add-account-ou4a3c

Summary by CodeRabbit

  • New Features
    • New account profiles automatically receive an available name when you haven’t entered one.
    • If the chosen name is already in use by a signed-in profile, you’ll see an error and can choose a different name.
    • Profile-name conflict messages are available in multiple languages.