From fe18fc324ec05ff7bc265a0a87f2792f03743c83 Mon Sep 17 00:00:00 2001 From: Meleki Date: Mon, 8 Jun 2026 08:07:31 +0200 Subject: [PATCH] Set CLI child working directory to the workspace The Claude CLI child process inherited the gott server's CWD because CreateCliStartInfo never set WorkingDirectory. On Linux systemd usually sets WorkingDirectory= to the workspace, so it worked by accident; on Windows the service starts from its install directory, so the CLI's own built-in tools resolved relative patterns (e.g. Glob "Sources/**") against the wrong directory and returned "No files found", while absolute paths still worked. --add-dir only grants access, it does not set the CWD. Thread the workspace through ChatStreamingAsync -> RunCliStreamingAsync -> CreateCliStartInfo and set psi.WorkingDirectory (guarded by Directory.Exists). GetStatusAsync stays without a CWD. Co-Authored-By: Claude Opus 4.8 --- Services/ClaudeCliService.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Services/ClaudeCliService.cs b/Services/ClaudeCliService.cs index 5368086..d6f4bdc 100644 --- a/Services/ClaudeCliService.cs +++ b/Services/ClaudeCliService.cs @@ -56,7 +56,7 @@ public class ClaudeCliService return dir; } - private ProcessStartInfo CreateCliStartInfo(List args, bool redirectInput = false, string effort = null) + private ProcessStartInfo CreateCliStartInfo(List args, bool redirectInput = false, string effort = null, string workingDirectory = null) { var psi = new ProcessStartInfo { @@ -70,6 +70,14 @@ public class ClaudeCliService StandardErrorEncoding = Encoding.UTF8 }; + // Arbeitsverzeichnis explizit auf den Workspace setzen. + // Ohne das erbt der CLI-Child das CWD des gott-Servers (unter Windows das + // Dienst-/Installationsverzeichnis), wodurch RELATIVE Tool-Pfade wie + // Glob "Sources/**" ins Leere laufen ("No files found"), während absolute + // Pfade funktionieren. --add-dir erteilt nur Zugriff, setzt aber NICHT das CWD. + if (!string.IsNullOrEmpty(workingDirectory) && Directory.Exists(workingDirectory)) + psi.WorkingDirectory = workingDirectory; + // 1h-Prompt-Cache-TTL für Claude CLI aktivieren (seit CLI 2.1.108). // Anthropic hat Anfang März 2026 den Default von 1h auf 5min gesenkt, // dieser Flag holt die 1h-TTL zurück (gilt für API-Key, Bedrock, Vertex, Foundry). @@ -229,7 +237,7 @@ public class ClaudeCliService args.Add(mcpConfigPath); } - return await RunCliStreamingAsync(args, prompt, onEvent, cancellationToken, effort); + return await RunCliStreamingAsync(args, prompt, onEvent, cancellationToken, effort, workspace); } private async Task RunCliStreamingAsync( @@ -237,7 +245,8 @@ public class ClaudeCliService string stdinPrompt, Func onEvent, CancellationToken cancellationToken, - string effort = null) + string effort = null, + string workspace = null) { var result = new CliChatResult(); var fullOutput = new StringBuilder(); @@ -257,7 +266,7 @@ public class ClaudeCliService try { - var startInfo = CreateCliStartInfo(args, redirectInput: true, effort: effort); + var startInfo = CreateCliStartInfo(args, redirectInput: true, effort: effort, workingDirectory: workspace); using var process = new Process { StartInfo = startInfo };