@@ -654,13 +654,23 @@ private static bool IsClaudeConfigured()
654654 {
655655 try
656656 {
657- string command = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? "claude" : "/usr/local/bin/claude" ;
658- var psi = new ProcessStartInfo { FileName = command , Arguments = "mcp list" , UseShellExecute = false , RedirectStandardOutput = true , RedirectStandardError = true , CreateNoWindow = true } ;
659- using var p = Process . Start ( psi ) ;
660- string output = p . StandardOutput . ReadToEnd ( ) ;
661- p . WaitForExit ( 3000 ) ;
662- if ( p . ExitCode != 0 ) return false ;
663- return output . IndexOf ( "UnityMCP" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
657+ string claudePath = ExecPath . ResolveClaude ( ) ;
658+ if ( string . IsNullOrEmpty ( claudePath ) ) return false ;
659+
660+ // Only prepend PATH on Unix
661+ string pathPrepend = null ;
662+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
663+ {
664+ pathPrepend = RuntimeInformation . IsOSPlatform ( OSPlatform . OSX )
665+ ? "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
666+ : "/usr/local/bin:/usr/bin:/bin" ;
667+ }
668+
669+ if ( ! ExecPath . TryRun ( claudePath , "mcp list" , workingDir : null , out var stdout , out var stderr , 5000 , pathPrepend ) )
670+ {
671+ return false ;
672+ }
673+ return ( stdout ?? string . Empty ) . IndexOf ( "UnityMCP" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
664674 }
665675 catch { return false ; }
666676 }
@@ -1330,7 +1340,19 @@ private void RegisterWithClaudeCode(string pythonDir)
13301340 }
13311341 if ( ! ExecPath . TryRun ( claudePath , args , projectDir , out var stdout , out var stderr , 15000 , pathPrepend ) )
13321342 {
1333- UnityEngine . Debug . LogError ( $ "UnityMCP: Failed to start Claude CLI.\n { stderr } \n { stdout } ") ;
1343+ string combined = ( $ "{ stdout } \n { stderr } ") ?? string . Empty ;
1344+ if ( combined . IndexOf ( "already exists" , StringComparison . OrdinalIgnoreCase ) >= 0 )
1345+ {
1346+ // Treat as success if Claude reports existing registration
1347+ var existingClient = mcpClients . clients . FirstOrDefault ( c => c . mcpType == McpTypes . ClaudeCode ) ;
1348+ if ( existingClient != null ) CheckClaudeCodeConfiguration ( existingClient ) ;
1349+ Repaint ( ) ;
1350+ UnityEngine . Debug . Log ( "<b><color=#2EA3FF>UNITY-MCP</color></b>: UnityMCP already registered with Claude Code." ) ;
1351+ }
1352+ else
1353+ {
1354+ UnityEngine . Debug . LogError ( $ "UnityMCP: Failed to start Claude CLI.\n { stderr } \n { stdout } ") ;
1355+ }
13341356 return ;
13351357 }
13361358
0 commit comments