fix: CLI-Pfad-Suche für Windows-Dienst verbessern + CLAUDE_CLI_PATH

- 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 <noreply@anthropic.com>
This commit is contained in:
MelekiandClaude Opus 4.6 committed 2026-03-24 17:33:16 +01:00
1 parent 9391b5a6fa
commit 1101bb83a0
1 file changed
+36 -31
+36 -31
View File
@@ -35,13 +35,42 @@ public class ClaudeCliService
public bool IsAvailable => _isAvailable; public bool IsAvailable => _isAvailable;
public string CliPath => _cliPath; public string CliPath => _cliPath;
private ProcessStartInfo CreateCliStartInfo(List<string> 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() 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[] var possiblePaths = new[]
{ {
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude"), // Windows: standalone install
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude.exe"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "claude-code", "claude.exe"), 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/local/bin/claude",
"/usr/bin/claude" "/usr/bin/claude"
}; };
@@ -52,15 +81,16 @@ public class ClaudeCliService
return path; return path;
} }
// 3. PATH-Suche
try try
{ {
var pathEnv = Environment.GetEnvironmentVariable("PATH") ?? ""; var pathEnv = Environment.GetEnvironmentVariable("PATH") ?? "";
foreach (var dir in pathEnv.Split(Path.PathSeparator)) 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; if (File.Exists(exePath)) return exePath;
exePath = Path.Combine(dir, "claude.exe"); exePath = Path.Combine(dir, "claude");
if (File.Exists(exePath)) return exePath; if (File.Exists(exePath)) return exePath;
} }
} }
@@ -191,20 +221,7 @@ public class ClaudeCliService
try try
{ {
var startInfo = new ProcessStartInfo var startInfo = CreateCliStartInfo(args, redirectInput: true);
{
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);
using var process = new Process { StartInfo = startInfo }; using var process = new Process { StartInfo = startInfo };
@@ -560,19 +577,7 @@ public class ClaudeCliService
try try
{ {
var startInfo = new ProcessStartInfo var startInfo = CreateCliStartInfo(args);
{
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);
using var process = new Process { StartInfo = startInfo }; using var process = new Process { StartInfo = startInfo };
process.OutputDataReceived += (s, e) => { if (e.Data != null) output.AppendLine(e.Data); }; process.OutputDataReceived += (s, e) => { if (e.Data != null) output.AppendLine(e.Data); };