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 <noreply@anthropic.com>
This commit is contained in:
MelekiandClaude Opus 4.8 committed 2026-06-08 08:07:31 +02:00
1 parent 9acf57b032
commit fe18fc324e
1 file changed
+13 -4
+13 -4
View File
@@ -56,7 +56,7 @@ public class ClaudeCliService
return dir;
}
private ProcessStartInfo CreateCliStartInfo(List<string> args, bool redirectInput = false, string effort = null)
private ProcessStartInfo CreateCliStartInfo(List<string> 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<CliChatResult> RunCliStreamingAsync(
@@ -237,7 +245,8 @@ public class ClaudeCliService
string stdinPrompt,
Func<CliStreamEvent, Task> 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 };