Skip to content

Commit 7dbb03b

Browse files
committed
Update UnityMcpEditorWindow.cs
Prevention for CLI to be found on Windows.
1 parent 2749b4e commit 7dbb03b

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

UnityMcpBridge/Editor/Windows/UnityMcpEditorWindow.cs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,13 @@ private void RegisterWithClaudeCode(string pythonDir)
901901

902902
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
903903
{
904-
command = "claude";
904+
command = FindClaudeCommand();
905+
906+
if (string.IsNullOrEmpty(command))
907+
{
908+
UnityEngine.Debug.LogError("Claude CLI not found. Please ensure Claude Code is installed and accessible.");
909+
return;
910+
}
905911

906912
// Try to find uv.exe in common locations
907913
string uvPath = FindWindowsUvPath();
@@ -982,7 +988,13 @@ private void UnregisterWithClaudeCode()
982988

983989
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
984990
{
985-
command = "claude";
991+
command = FindClaudeCommand();
992+
993+
if (string.IsNullOrEmpty(command))
994+
{
995+
UnityEngine.Debug.LogError("Claude CLI not found. Please ensure Claude Code is installed and accessible.");
996+
return;
997+
}
986998
}
987999
else
9881000
{
@@ -1151,6 +1163,68 @@ private string FindWindowsUvPath()
11511163
return null; // Will fallback to using 'uv' from PATH
11521164
}
11531165

1166+
private string FindClaudeCommand()
1167+
{
1168+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1169+
{
1170+
// Common locations for Claude CLI on Windows
1171+
string[] possiblePaths = {
1172+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "npm", "claude.cmd"),
1173+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "npm", "claude.cmd"),
1174+
"claude.cmd", // Fallback to PATH
1175+
"claude" // Final fallback
1176+
};
1177+
1178+
foreach (string path in possiblePaths)
1179+
{
1180+
if (path.Contains("\\") && File.Exists(path))
1181+
{
1182+
return path;
1183+
}
1184+
}
1185+
1186+
// Try to find via where command
1187+
try
1188+
{
1189+
var psi = new ProcessStartInfo
1190+
{
1191+
FileName = "where",
1192+
Arguments = "claude",
1193+
UseShellExecute = false,
1194+
RedirectStandardOutput = true,
1195+
CreateNoWindow = true
1196+
};
1197+
1198+
using var process = Process.Start(psi);
1199+
string output = process.StandardOutput.ReadToEnd().Trim();
1200+
process.WaitForExit();
1201+
1202+
if (!string.IsNullOrEmpty(output))
1203+
{
1204+
string[] lines = output.Split('\n');
1205+
foreach (string line in lines)
1206+
{
1207+
string cleanPath = line.Trim();
1208+
if (File.Exists(cleanPath))
1209+
{
1210+
return cleanPath;
1211+
}
1212+
}
1213+
}
1214+
}
1215+
catch
1216+
{
1217+
// Ignore errors and fall back
1218+
}
1219+
1220+
return "claude"; // Final fallback to PATH
1221+
}
1222+
else
1223+
{
1224+
return "/usr/local/bin/claude";
1225+
}
1226+
}
1227+
11541228
private void CheckClaudeCodeConfiguration(McpClient mcpClient)
11551229
{
11561230
try

0 commit comments

Comments
 (0)