From 83d7a140fb83ce9bb600f9f696f4d4d23b3b7f18 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 20 Nov 2026 05:48:22 -0300 Subject: [PATCH] fix(server): stream a foreground Claude command's output on Windows claudeTaskOutputRoot returned undefined whenever process.getuid was missing, which is always the case on Windows, so the live output tail never started and a running command showed nothing until it finished. Claude Code on Windows writes task output to \claude\\\tasks, with no uid suffix. CLAUDE_CODE_TMPDIR replaces TEMP when set. TMP and TMPDIR are ignored there. Resolve that root on win32. --- .../Adapters/ClaudeTaskOutputTail.test.ts | 24 +++++++++++++++++++ .../Adapters/ClaudeTaskOutputTail.ts | 8 ++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts index 51c9a7848f100..ca36ce9aca1e3 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts @@ -1,3 +1,4 @@ +import * as NodePath from "@effect/platform-node/NodePath"; import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, describe, it } from "@effect/vitest"; import * as Deferred from "effect/Deferred"; @@ -163,4 +164,27 @@ describe("claudeTaskOutputRoot", () => { ); }).pipe(Effect.provide(NodeServices.layer)), ); + + it.effect("uses the folder Claude Code names without a uid on Windows, from TEMP only", () => + Effect.gen(function* () { + const path = yield* Path.Path; + const temp = "C:\\Users\\me\\AppData\\Local\\Temp"; + const root = (environment: Record, cwd: string | null = null) => + claudeTaskOutputRoot(environment, path, cwd, "win32"); + assert.equal(root({ TEMP: temp }), `${temp}\\claude`); + assert.equal(root({ TEMP: `${temp}\\` }), `${temp}\\claude`); + // Claude Code ignores TMP and TMPDIR on Windows, and so does this. + assert.equal(root({ TEMP: temp, TMP: "D:\\other", TMPDIR: "/tmp" }), `${temp}\\claude`); + assert.isUndefined(root({ TMP: "D:\\other", TMPDIR: "/tmp" })); + assert.isUndefined(root({})); + assert.equal( + root({ CLAUDE_CODE_TMPDIR: "D:\\claude-tmp", TEMP: temp }), + "D:\\claude-tmp\\claude", + ); + assert.equal( + root({ CLAUDE_CODE_TMPDIR: "reltmp", TEMP: temp }, "C:\\work\\project"), + "C:\\work\\project\\reltmp\\claude", + ); + }).pipe(Effect.provide(NodePath.layerWin32)), + ); }); diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.ts index 7eac250d7afde..2fc3035d84c17 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.ts @@ -13,13 +13,19 @@ const MAX_LOCATE_ATTEMPTS = 40; /** Skip ahead of fast writers; only the tail is displayed. */ const MAX_READ_BYTES = 256 * 1024; -/** Claude Code's per-user temp root, or none where it has no uid (Windows). */ +/** Claude Code's per-user temp root, or none when this host cannot tell where it is. */ export function claudeTaskOutputRoot( environment: Readonly> | undefined, path: Path.Path, cwd: string | null, platform: NodeJS.Platform, ): string | undefined { + if (platform === "win32") { + // Windows has no uid, so the folder is a plain `claude`. The base is TEMP and nothing else: + // Claude Code ignores TMP and TMPDIR there, and without TEMP it picks a default we cannot see. + const base = environment?.CLAUDE_CODE_TMPDIR?.trim() || environment?.TEMP; + return base ? path.resolve(cwd ?? ".", base, "claude") : undefined; + } const uid = process.getuid?.(); if (uid === undefined) return undefined; // Claude Code's macOS build falls back to /tmp and ignores the TMPDIR that