From 1101bb83a0fc29e80728fa15d1d41ae7863ab54c Mon Sep 17 00:00:00 2001 From: Meleki Date: Tue, 24 Mar 2026 17:33:16 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20CLI-Pfad-Suche=20f=C3=BCr=20Windows-Dien?= =?UTF-8?q?st=20verbessern=20+=20CLAUDE=5FCLI=5FPATH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CLAUDE_CLI_PATH Umgebungsvariable als höchste Priorität bei CLI-Suche - CreateCliStartInfo() Helper dedupliziert ProcessStartInfo-Erstellung - .cmd-Wrapper-Logik entfernt (nicht benötigt) - PATH-Suche priorisiert .exe für Windows Co-Authored-By: Claude Opus 4.6 --- Services/ClaudeCliService.cs | 67 +++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/Services/ClaudeCliService.cs b/Services/ClaudeCliService.cs index 3625314..6d66ccd 100644 --- a/Services/ClaudeCliService.cs +++ b/Services/ClaudeCliService.cs @@ -35,13 +35,42 @@ public class ClaudeCliService public bool IsAvailable => _isAvailable; public string CliPath => _cliPath; + private ProcessStartInfo CreateCliStartInfo(List args, bool redirectInput = false) + { + var psi = new ProcessStartInfo + { + FileName = _cliPath, + RedirectStandardInput = redirectInput, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, + StandardOutputEncoding = Encoding.UTF8, + StandardErrorEncoding = Encoding.UTF8 + }; + + foreach (var arg in args) + psi.ArgumentList.Add(arg); + + return psi; + } + private static string FindCliPath() { + // 1. Expliziter Pfad über Umgebungsvariable (höchste Priorität) + var envPath = Environment.GetEnvironmentVariable("CLAUDE_CLI_PATH"); + if (!string.IsNullOrEmpty(envPath) && File.Exists(envPath)) + return envPath; + + // 2. Bekannte Installationspfade var possiblePaths = new[] { - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude"), - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude.exe"), + // Windows: standalone install Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "claude-code", "claude.exe"), + // Windows/Linux: local bin (funktioniert nur wenn Dienst unter dem richtigen User läuft) + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude.exe"), + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude"), + // Linux: system paths "/usr/local/bin/claude", "/usr/bin/claude" }; @@ -52,15 +81,16 @@ public class ClaudeCliService return path; } + // 3. PATH-Suche try { var pathEnv = Environment.GetEnvironmentVariable("PATH") ?? ""; foreach (var dir in pathEnv.Split(Path.PathSeparator)) { - var exePath = Path.Combine(dir, "claude"); + var exePath = Path.Combine(dir, "claude.exe"); if (File.Exists(exePath)) return exePath; - exePath = Path.Combine(dir, "claude.exe"); + exePath = Path.Combine(dir, "claude"); if (File.Exists(exePath)) return exePath; } } @@ -191,20 +221,7 @@ public class ClaudeCliService try { - var startInfo = new ProcessStartInfo - { - FileName = _cliPath, - RedirectStandardInput = true, - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true, - StandardOutputEncoding = Encoding.UTF8, - StandardErrorEncoding = Encoding.UTF8 - }; - - foreach (var arg in args) - startInfo.ArgumentList.Add(arg); + var startInfo = CreateCliStartInfo(args, redirectInput: true); using var process = new Process { StartInfo = startInfo }; @@ -560,19 +577,7 @@ public class ClaudeCliService try { - var startInfo = new ProcessStartInfo - { - FileName = _cliPath, - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true, - StandardOutputEncoding = Encoding.UTF8, - StandardErrorEncoding = Encoding.UTF8 - }; - - foreach (var arg in args) - startInfo.ArgumentList.Add(arg); + var startInfo = CreateCliStartInfo(args); using var process = new Process { StartInfo = startInfo }; process.OutputDataReceived += (s, e) => { if (e.Data != null) output.AppendLine(e.Data); };