fix: account switcher disappears from the TUI with multiple accounts - #266
fix: account switcher disappears from the TUI with multiple accounts#266carson2222 wants to merge 2 commits into
Conversation
Greptile SummaryFixes a schema validation error that caused the account-switcher prompt to disappear in the TUI whenever two or more Claude Code accounts were configured. When
Confidence Score: 5/5The change is safe to merge — it fixes a one-character-class bug (undefined vs. string) with no risk of regression on the single-account path. The diff is a single-line change in the source and matching test updates. The only behavioral difference is that non-active account options now carry their source string as a hint instead of undefined, which is exactly what the schema requires. The single-account code path (returns [] early) is untouched. Tests are updated to reflect and guard the new shape, including an explicit invariant asserting hint is always a string. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/index.ts | Single-line fix: non-active account option now sets hint to a.source instead of undefined, satisfying the schema's string requirement and restoring the TUI account switcher. |
| src/index.test.ts | Test helper updated to mirror the corrected builder shape; assertions fixed to check a.source for non-active hints; new invariant test added to assert hint is always a string. |
Sequence Diagram
sequenceDiagram
participant TUI as opencode TUI
participant EP as GET /provider/auth
participant Plugin as Claude Auth Plugin
participant Schema as opencode Schema Validator
TUI->>EP: GET /provider/auth (2+ accounts)
EP->>Plugin: prompts getter
Plugin->>Plugin: currentAccounts.map(...)
note over Plugin: Before fix: hint = undefined for non-active accounts
Plugin-->>EP: options with hint: undefined
EP->>Schema: validate response
Schema-->>EP: SchemaError (hint must be string)
EP-->>TUI: validation failure / empty response
TUI-->>TUI: fallback to API key input (switcher never shown)
note over Plugin: After fix: hint = a.source for non-active accounts
TUI->>EP: GET /provider/auth (2+ accounts)
EP->>Plugin: prompts getter
Plugin->>Plugin: currentAccounts.map(...)
note over Plugin: hint = "active" | a.source (always string)
Plugin-->>EP: options with hint: string
EP->>Schema: validate response
Schema-->>EP: OK
EP-->>TUI: select prompt with all accounts
TUI-->>TUI: account switcher renders correctly
Reviews (1): Last reviewed commit: "test: assert account hint is always a st..." | Re-trigger Greptile
|
I must have broken this when I updated the plugin to auto switch to the account cswap auto rotates to. |
With 2+ Claude Code accounts, the account switcher never shows up in the TUI — picking Anthropic under
/connectgoes straight to the API key input, as if the plugin weren't loaded.opencode auth loginstill works, which makes it look like a plugin loading issue.It isn't.
GET /provider/authis throwing:opencode's schema wants
hintto be a string, and we passundefinedfor every non-active account. The whole response fails validation, so the TUI gets nothing back for anthropic and falls through to the API key prompt. The CLI path doesn't go through that endpoint, hence the split behavior.Needs 2+ accounts to reproduce — with one account
promptsreturns[]early and the options array is never built, which is probably why it went unnoticed.Fix is to pass the source as the hint for non-active accounts, which is what it was before #99.
Also updated
buildSelectOptionsin the tests — it mirrors the real builder rather than importing it, so it was happily asserting the broken shape.Verified against opencode 1.18.12:
/provider/authreturns 200 with all accounts, switcher renders again.