feat(multi-account): Accounts tab in Settings (Batch 2b part 1)

Merged
GR
4mo ago
+384-6

Summary

Batch 2b (part 1) of multi-account support (follows #123): an Accounts tab in Settings — manage Claude Code accounts from the UI instead of the terminal.

  • List configured accounts: label, identity (email / "not logged in" hint), default marker
  • Add an account (creates the registry entry + regenerates accounts.sh; shows the claude <label> log-in hint)
  • Remove an account (unregisters; keeps its folder on disk; anchor ~/.claude account is protected)
  • Set default — what bare claude resolves to (2e, now clickable)
  • Shell integration install/uninstall (the marker-guarded ~/.zshrc source block)

Architecture

The tab is a set of thin IPC handlers (accounts-get/add/remove/set-default/shell-hook in main.ts) over the same shared manager (src/cli/account-manager.ts) that the codev account CLI uses — one generator for accounts.json + accounts.sh, no drift between CLI and UI. Mutations invalidate the accounts cache so the Sessions tab picks up changes.

  • src/popup.tsx — new accounts tab (state + handlers + UI, matching the existing tab style)
  • src/preload.ts / src/electron-api.d.ts — API wiring + CodevAccountInfo type
  • src/main.ts — IPC handlers

Scope notes

  • Rename is deferred: labels name their dirs (~/.claude-<label>), so rename implies a dir migration; remove+add covers the rare need.
  • codev binary on PATH is the remaining 2b item (next PR) — until then the CLI runs via yarn account <cmd>.

Supported shells & terminals

  • Shell integration (Install button / codev account install): writes ~/.zshrc — zsh only for now (the macOS default). The generated accounts.sh is bash-compatible (bash users can source it from .bashrc manually); fish is unsupported (different function syntax). Shell detection is future work (design doc §6.C).
  • Account-aware resume/launch: every terminal CodeV supports — iTerm2, Terminal.app, Ghostty, cmux, and the embedded Term tab. VS Code sessions can't be account-switched (#121).

Checking which account a session runs under (gotcha)

Inside any Claude Code session, !claude auth status reports the global default, not the session's account — Claude Code snapshots your interactive shell's functions, so in-session claude is the accounts.sh dispatcher. Valid probes:

  • !command claude auth status ✅ — command bypasses shell functions, so the real binary inherits the session process's own CLAUDE_CONFIG_DIR → the session's actual account
  • !echo ${CLAUDE_CONFIG_DIR:-unset} ✅ — the session's own config dir (unset = anchor account)

Full write-up: #123's "Gotcha" section + design doc §6.A.

How to test

Needs yarn make (main-process + renderer changes):

  1. Settings → Accounts tab: your accounts appear with email + default marker; shell integration shows Uninstall (already installed).
  2. Add a test account → appears as "not logged in — run: claude test"; registry + accounts.sh regenerate.
  3. Set default on test → notice appears; yarn account list shows * moved (restore after).
  4. Remove test → gone from list; ~/.claude-test folder stays.
  5. Sessions tab still shows personal+work sessions with badges (cache invalidation works).

Automated: yarn test 13/13; tsc --noEmit 0 errors.

🤖 Generated with Claude Code


Summary by cubic

Adds a new Accounts tab in Settings so you can manage Claude Code accounts from the UI instead of the terminal. This lets you add/remove accounts, set the default for bare claude, and toggle shell integration.

  • New Features

    • List accounts with identity (email or “not logged in”), a “default” marker, and the exact launch command (claude or claude <name>).
    • Add an account (shows login hint: claude <name>), remove an account (keeps its folder), and set the global default.
    • Install/uninstall shell integration for ~/.zshrc.
    • IPC handlers (accounts-get/add/remove/set-default/shell-hook) wrap the shared account-manager used by the codev account CLI; mutations invalidate the Sessions cache.
    • Notes: the anchor ~/.claude account is protected; rename is deferred; remaining 2b item is a real codev binary on PATH.
  • Bug Fixes

    • Seed the anchor ~/.claude account on first extra add so the existing machine default stays registered and remains the global default.
    • accounts-add returns the enriched shape and derives isCurrentDefault in the fallback path to match CodevAccountInfo; shell-hook action is validated (malformed payloads fail).
    • UI hardening: async refresh with error handling, stale notices cleared on tab open, clear guidance when shell integration isn’t installed, and a busy guard to serialize account operations.

Summary by CodeRabbit

  • New Features
    • Added an Accounts tab in Settings for multi-account management.
    • Users can view accounts, add/remove accounts, and set the default (with current-default indicators).
    • Added UI to install/uninstall shell integration from the Accounts tab.
    • Settings can now open directly to the Accounts tab.
  • Chores
    • Updated the app version to v1.0.78 and refreshed the release entry.