Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<string, string>, 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)),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, string | undefined>> | 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
Expand Down
Loading