Skip to content

fix: account switcher disappears from the TUI with multiple accounts - #266

Open
carson2222 wants to merge 2 commits into
griffinmartin:mainfrom
carson2222:fix-hint-string
Open

fix: account switcher disappears from the TUI with multiple accounts#266
carson2222 wants to merge 2 commits into
griffinmartin:mainfrom
carson2222:fix-hint-string

Conversation

@carson2222

Copy link
Copy Markdown

With 2+ Claude Code accounts, the account switcher never shows up in the TUI — picking Anthropic under /connect goes straight to the API key input, as if the plugin weren't loaded. opencode auth login still works, which makes it look like a plugin loading issue.

It isn't. GET /provider/auth is throwing:

SchemaError: Expected string, got undefined
  at ["anthropic"][0]["prompts"][0]["options"][0]["hint"]

opencode's schema wants hint to be a string, and we pass undefined for 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 prompts returns [] 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 buildSelectOptions in 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/auth returns 200 with all accounts, switcher renders again.

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

Fixes 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 GET /provider/auth was called, building the options array for the select prompt set hint: undefined for non-active accounts; opencode's schema requires hint to be a string, so the entire response failed validation and the TUI fell back to the API-key input.

  • src/index.ts: Changes the hint for non-active accounts from undefined to a.source (the account's credential-source string), guaranteeing the field is always a string.
  • src/index.test.ts: Updates the mirrored buildSelectOptions helper and the corresponding assertions to match the corrected shape, and adds an explicit "always a string" invariant test.

Confidence Score: 5/5

The 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.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "test: assert account hint is always a st..." | Re-trigger Greptile

@griffinmartin

Copy link
Copy Markdown
Owner

I must have broken this when I updated the plugin to auto switch to the account cswap auto rotates to.

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.

2 participants