@@ -3,8 +3,8 @@ import { homedir } from 'os';
33import { join , dirname } from 'path' ;
44import crypto from 'crypto' ;
55import { bold , cyanBright } from 'ansis' ;
6- import open from 'open' ;
76import { intro , outro , spinner , log , text , select , confirm , isCancel , multiselect } from '@clack/prompts' ;
7+ import { exec } from 'node:child_process' ;
88
99const CLIENT_ID = '9d1c250a-e61b-44d9-88ed-5944d1962f5e' ;
1010const CREDS_PATH = join ( homedir ( ) , '.magnitude' , 'credentials' , 'claudeCode.json' ) ;
@@ -139,6 +139,32 @@ export async function getValidClaudeCodeAccessToken(): Promise<string | null> {
139139 }
140140}
141141
142+ function openUrl ( url : string ) : Promise < void > {
143+ return new Promise ( ( resolve , reject ) => {
144+ let command : string ;
145+
146+ switch ( process . platform ) {
147+ case 'darwin' :
148+ command = `open "${ url } "` ;
149+ break ;
150+ case 'win32' :
151+ command = `start "${ url } "` ;
152+ break ;
153+ default :
154+ command = `xdg-open "${ url } "` ;
155+ break ;
156+ }
157+
158+ exec ( command , ( error ) => {
159+ if ( error ) {
160+ reject ( error ) ;
161+ } else {
162+ resolve ( ) ;
163+ }
164+ } ) ;
165+ } ) ;
166+ }
167+
142168export async function completeClaudeCodeAuthFlow ( ) : Promise < string > {
143169 // Try to get existing valid token
144170 const existingToken = await getValidClaudeCodeAccessToken ( ) ;
@@ -150,7 +176,7 @@ export async function completeClaudeCodeAuthFlow(): Promise<string> {
150176
151177 log . message ( cyanBright `Opening browser for authentication...` ) ;
152178 try {
153- await open ( authUrl ) ;
179+ await openUrl ( authUrl ) ;
154180 } catch ( err ) {
155181 log . message ( 'Could not open browser automatically' ) ;
156182 }
0 commit comments