@@ -200,6 +200,12 @@ export function useHomeCommands(options: UseHomeCommandsOptions) {
200200
201201 const isAuthenticated = await engine . auth . isAuthenticated ( )
202202
203+ // Special handling for OpenCode when already authenticated
204+ if ( providerId === "opencode" && isAuthenticated ) {
205+ await handleOpenCodeAddProvider ( providerId , providerName )
206+ return
207+ }
208+
203209 if ( isAuthenticated ) {
204210 toast . show ( {
205211 variant : "info" ,
@@ -221,6 +227,40 @@ export function useHomeCommands(options: UseHomeCommandsOptions) {
221227 ) )
222228 }
223229
230+ /**
231+ * Handles adding another OpenCode provider by spawning `opencode auth login` interactively
232+ */
233+ const handleOpenCodeAddProvider = async ( providerId : string , providerName : string ) => {
234+ const { registry } = await import ( "../../../../../infra/engines/index.js" )
235+
236+ dialog . show ( ( ) => (
237+ < SelectMenu
238+ message = { `${ providerName } is authenticated. Add another provider?` }
239+ choices = { [
240+ { title : "Add another provider" , value : "add" } ,
241+ { title : "Cancel" , value : "cancel" } ,
242+ ] }
243+ onSelect = { async ( choice : string ) => {
244+ dialog . close ( )
245+ if ( choice === "cancel" ) return
246+
247+ const engine = registry . get ( providerId )
248+ if ( ! engine ) return
249+
250+ await dialog . handleAuthCommand (
251+ `${ providerName } - Add Provider` ,
252+ async ( ) => {
253+ // Call ensureAuth(true) directly to force interactive login
254+ // This bypasses handleLogin's clack confirmation which doesn't work well after TUI destruction
255+ await engine . auth . ensureAuth ( true )
256+ }
257+ )
258+ } }
259+ onCancel = { ( ) => dialog . close ( ) }
260+ />
261+ ) )
262+ }
263+
224264 const handleLogoutCommand = async ( ) => {
225265 const { registry } = await import ( "../../../../../infra/engines/index.js" )
226266 const { handleLogout } = await import ( "../../../../commands/auth.command.js" )
0 commit comments