Skip to content

Add Claude account support with model-aware AI streaming#167

Open
eachann1024 wants to merge 2 commits into
SuperCmdLabs:chat-modelfrom
eachann1024:feat/ai-provider-minimal-fix
Open

Add Claude account support with model-aware AI streaming#167
eachann1024 wants to merge 2 commits into
SuperCmdLabs:chat-modelfrom
eachann1024:feat/ai-provider-minimal-fix

Conversation

@eachann1024
Copy link
Copy Markdown
Contributor

Summary

This PR adds Claude account support to the AI stack and makes model selection flow through both the launcher prompt and the dedicated AI chat window.

It also fixes account-backed streaming so token updates reach the UI incrementally instead of waiting on line-based SSE parsing.

Related issues

#1

Motivation

SuperCmd already supports multiple AI providers, but flat subscription workflows were still incomplete for account-backed providers. Users could not sign in with Claude Code, switch between account-backed models consistently, or rely on streaming behavior staying responsive across the launcher and chat window.

This change closes that gap by wiring Claude account auth into settings, preserving the chosen model/provider in conversations, and making upstream SSE parsing robust for streamed responses.

Features Added

  • Add Claude account login, logout, status, model lookup, and browser-code auth handoff inside Settings.
  • Add Claude account model routing for Sonnet, Opus, and Haiku in both launcher AI and AI chat conversations.
  • Surface the active model/provider in the launcher AI view and the AI chat window.
  • Keep account-backed responses streaming incrementally with improved SSE event parsing.

Changes

  • src/main/claude-auth.ts, src/main/claude-upstream.ts, src/main/settings-store.ts, src/main/preload.ts, src/main/main.ts, src/renderer/types/electron.d.ts:
    • Add the Claude Code auth bridge, persisted Claude account tokens, IPC handlers, and renderer API typings.
    • Route Claude account requests through the upstream bridge and expose account model metadata to the renderer.
  • src/main/ai-provider.ts, src/main/chatgpt-upstream.ts, src/main/memory.ts:
    • Add Claude account model resolution and multi-turn streaming support.
    • Fix SSE parsing so streamed payloads are processed per event block rather than per raw line.
    • Fall back to local memory search if remote Supermemory lookup fails.
  • src/renderer/src/settings/AITab.tsx, src/renderer/src/utils/ai-models.ts, src/renderer/src/hooks/useAiChat.ts, src/renderer/src/views/AiChatManager.tsx, src/renderer/src/views/AiChatView.tsx, src/renderer/src/App.tsx, src/renderer/src/i18n/locales/en.json, src/renderer/src/i18n/locales/zh-Hans.json:
    • Add Claude account controls to Settings.
    • Unify model option resolution across launcher AI and AI chat.
    • Show the active model/provider in AI surfaces and keep conversation model changes in sync.

Benefits

Testing

  • bun run build:main
  • bun run build:renderer
  • node <guardrail-check> --phase repo --repo <repo-root> --contribution-model direct --upstream-url https://github.com/SuperCmdLabs/SuperCmd.git --require-clean false
  • node <guardrail-check> --phase commit --mode staged --max-files 20 --max-top-level 2 --allow-cjk-files "src/renderer/src/i18n/locales/zh-Hans.json"
  • node <guardrail-check> --phase commit --mode range --base upstream/chat-model --head HEAD --check-commit-messages true --max-files 20 --max-top-level 2 --allow-cjk-files "src/renderer/src/i18n/locales/zh-Hans.json"
  • Manual check: sign in with ChatGPT account and confirm launcher/chat streaming still updates incrementally.
  • Manual check: sign in with Claude account, complete the browser auth code flow, switch models, and continue the conversation in the AI chat window.

@eachann1024
Copy link
Copy Markdown
Contributor Author

eachann1024 commented Apr 2, 2026

@shobhit99 Please check if it meets the points you mentioned, and I also found some areas that need optimization; when I input quickly, it turns into landscape mode.

Resources 2026-04-02 at 17 20 43@2x
  1. If I input content, exit the checkbox and come back, the input box will be cleared again. Or when I am chatting with the AI, if I leave the floating window halfway, switch to another interface and come back, the input box will also disappear. An appropriate solution should be to add a time timer to automatically return to the search box.

@shobhit99
Copy link
Copy Markdown
Contributor

Thanks @eachann1024

I tried running the code in branch. when logging in, it gets stuck on the login button for claude
image

@eachann1024 eachann1024 force-pushed the feat/ai-provider-minimal-fix branch from a1b8119 to 23a1b11 Compare April 3, 2026 13:37
@eachann1024
Copy link
Copy Markdown
Contributor Author

@shobhit99 Thanks for catching this. I reproduced the issue locally and the root cause was that the Claude login bridge was only matching the older authorization URL format (claude.ai/oauth/authorize). Current Claude Code now emits claude.com/cai/oauth/authorize, so SuperCmd never detected the auth URL and stayed stuck on "Preparing Claude login...".

I have pushed a fix that handles both URL variants so the login flow works with both older and current Claude Code outputs. The updated commit is now on this PR branch (23a1b11). Please pull the latest branch and try the Claude login flow again.

@shobhit99
Copy link
Copy Markdown
Contributor

Hi @eachann1024
I tried with the latest pull. I still am facing the same issue. on click on login it doesn't open anything
attached the video

Screen.Recording.2026-04-04.at.1.55.48.AM.mov

… PATH issues

Three root causes identified for the login flow not opening the browser:

1. URL regex too specific — only matched two exact paths. Newer or older
   Claude Code versions may use different URLs (e.g. different subdomain,
   different path prefix). Replaced with a broad pattern that matches any
   HTTPS URL from claude.ai, claude.com, or anthropic.com.

2. BROWSER=none suppression — on systems where Claude Code respects the
   BROWSER env variable, setting it to 'none' can silently prevent both the
   browser from opening AND the fallback URL from being printed. Removed
   BROWSER=none so Claude Code handles browser-opening with its own
   reliable mechanism.

3. No fallback when URL parsing fails — if the output URL cannot be matched
   (future format change, split chunks), the code modal never appeared.
   Added a secondary trigger: if Claude Code prints 'Opening browser…' we
   immediately set browserOpened=true and show the code modal proactively,
   since current Claude Code always uses the code-based PKCE flow.

Additional improvements:
- Augmented PATH in all spawn/execFile calls with common Claude install
  locations (/opt/homebrew/bin, ~/.nvm, ~/.bun, ~/.volta, etc.) so that
  claude CLI is found when Electron launches without a full shell PATH.
- When Claude Code already opened the browser we skip the redundant
  shell.openExternal call (avoids opening duplicate browser tabs).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@eachann1024
Copy link
Copy Markdown
Contributor Author

Hi @shobhit99
I guess I have successfully solved your problem this time. I have simultaneously called opus and 5.4xhigh to verify the cause of the issue, covering all three possible scenarios, and also performed an extra action.

It will handle this kind of situation, for example, when the user is calling and their SDK is an old version, they may need to input and obtain a token, then pass the token to the software popup. This has also been done, but this is a compatibility handling measure. By default, it should be like my GIF image.

Resources 2026-04-04 at 14 52 24

@shobhit99
Copy link
Copy Markdown
Contributor

Hi @eachann1024
The login button opens the browser now, but i see this error after i login.

Also is this going to affect our implementation - https://x.com/bcherny/status/2040206440556826908

image

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