Skip to content

Commit 5d61cf1

Browse files
only21milclaude
andcommitted
fix(claude): keep /tmp for live Bash output on macOS
Claude Code's macOS build looks for its task files under CLAUDE_CODE_TMPDIR or /tmp and never reads TMPDIR, which launchd sets on every Mac. Reading TMPDIR there sent the tail to the wrong directory. TMPDIR, TMP and TEMP now apply only off macOS, where Claude Code uses os.tmpdir(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5cc9d06 commit 5d61cf1

5 files changed

Lines changed: 41 additions & 20 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6421,7 +6421,8 @@ describe("ClaudeAdapterV2 background wake turns", () => {
64216421
prefix: "t3-claude-task-output-cwd-",
64226422
});
64236423
// The session opens in /workspace; a relative TMPDIR puts Claude's
6424-
// task files under whichever cwd the CLI was launched in.
6424+
// task files under whichever cwd the CLI was launched in. Linux,
6425+
// because Claude Code's macOS build ignores TMPDIR.
64256426
const harness = yield* makeWakeHarnessWithOptions({ environment: { TMPDIR: "tmp" } });
64266427
const now = yield* DateTime.now;
64276428
const toolUseId = "toolu_foreground_bash";
@@ -6506,6 +6507,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
65066507
);
65076508
assert.deepEqual(chunks, ["line 1\n"]);
65086509
}).pipe(
6510+
Effect.provideService(HostProcess.Platform, "linux"),
65096511
Effect.provide(
65106512
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
65116513
),

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,12 @@ const writeReplayTaskOutputFiles = Effect.fn("ClaudeReplay.writeTaskOutputFiles"
10241024
const stderr = typeof result.stderr === "string" ? result.stderr : "";
10251025
outputByToolUseId.set(toolResult.tool_use_id, `${result.stdout}${stderr}`);
10261026
}
1027-
const root = claudeTaskOutputRoot({ CLAUDE_CODE_TMPDIR: tmpRoot }, path, null);
1027+
const root = claudeTaskOutputRoot(
1028+
{ CLAUDE_CODE_TMPDIR: tmpRoot },
1029+
path,
1030+
null,
1031+
yield* HostProcess.Platform,
1032+
);
10281033
for (const frame of frames) {
10291034
if (frame.type !== "system" || frame.subtype !== "task_started") continue;
10301035
if (frame.task_type !== "local_bash" || frame.is_backgrounded !== false) continue;

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,6 +3920,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
39203920
adapterOptions.environment,
39213921
).pipe(Effect.provideService(Path.Path, path));
39223922
const hostEnvironment = yield* HostProcess.Environment;
3923+
const hostPlatform = yield* HostProcess.Platform;
39233924
const customHome =
39243925
adapterOptions.settings.homePath.trim().length > 0 ||
39253926
adapterOptions.environment.CLAUDE_CONFIG_DIR !== hostEnvironment.CLAUDE_CONFIG_DIR;
@@ -9367,6 +9368,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
93679368
adapterOptions.environment,
93689369
path,
93699370
turnInput.runtimePolicy.cwd,
9371+
hostPlatform,
93709372
),
93719373
};
93729374
yield* Ref.set(queryContext, context);

‎apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,34 @@ describe("tailClaudeTaskOutput", () => {
109109

110110
describe("claudeTaskOutputRoot", () => {
111111
it.effect.skipIf(process.getuid === undefined)(
112-
"uses the temp dir Claude Code resolves from its environment",
112+
"uses the temp dir Claude Code resolves from its environment on each platform",
113113
() =>
114114
Effect.gen(function* () {
115115
const path = yield* Path.Path;
116116
const user = `claude-${process.getuid?.()}`;
117-
const root = (environment: Record<string, string>, cwd: string | null = null) =>
118-
claudeTaskOutputRoot(environment, path, cwd);
119-
assert.equal(root({ TMPDIR: "/var/folders/x/T/" }), `/var/folders/x/T/${user}`);
120-
assert.equal(root({ TMP: "/tmp/user/1000" }), `/tmp/user/1000/${user}`);
117+
const root = (
118+
environment: Record<string, string>,
119+
platform: NodeJS.Platform,
120+
cwd: string | null = null,
121+
) => claudeTaskOutputRoot(environment, path, cwd, platform);
122+
assert.equal(root({ TMPDIR: "/var/folders/x/T/" }, "linux"), `/var/folders/x/T/${user}`);
123+
assert.equal(root({ TMP: "/tmp/user/1000" }, "linux"), `/tmp/user/1000/${user}`);
124+
assert.equal(root({}, "linux"), `/tmp/${user}`);
125+
assert.equal(root({ TMPDIR: "/var/folders/x/T/" }, "darwin"), `/tmp/${user}`);
121126
assert.equal(
122-
root({ CLAUDE_CODE_TMPDIR: "/srv/claude", TMPDIR: "/var/folders/x/T/" }),
127+
root({ CLAUDE_CODE_TMPDIR: "/srv/claude", TMPDIR: "/var/folders/x/T/" }, "linux"),
123128
`/srv/claude/${user}`,
124129
);
125-
assert.equal(root({}), `/tmp/${user}`);
126-
assert.equal(root({ TMPDIR: "tmp" }, "/work/project"), `/work/project/tmp/${user}`);
127130
assert.equal(
128-
root({ CLAUDE_CODE_TMPDIR: "../claude" }, "/work/project"),
131+
root({ CLAUDE_CODE_TMPDIR: "/srv/claude", TMPDIR: "/var/folders/x/T/" }, "darwin"),
132+
`/srv/claude/${user}`,
133+
);
134+
assert.equal(
135+
root({ TMPDIR: "tmp" }, "linux", "/work/project"),
136+
`/work/project/tmp/${user}`,
137+
);
138+
assert.equal(
139+
root({ CLAUDE_CODE_TMPDIR: "../claude" }, "darwin", "/work/project"),
129140
`/work/claude/${user}`,
130141
);
131142
}).pipe(Effect.provide(NodeServices.layer)),

‎apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ export function claudeTaskOutputRoot(
2727
environment: Readonly<Record<string, string | undefined>> | undefined,
2828
path: Path.Path,
2929
cwd: string | null,
30+
platform: NodeJS.Platform,
3031
): string | undefined {
3132
const uid = process.getuid?.();
3233
if (uid === undefined) return undefined;
33-
// Claude Code falls back to `os.tmpdir()`, which reads these from the
34-
// environment it was launched with: macOS always sets TMPDIR. A relative
35-
// value is relative to Claude's working directory, not this server's.
36-
const base =
37-
environment?.CLAUDE_CODE_TMPDIR?.trim() ||
38-
environment?.TMPDIR ||
39-
environment?.TMP ||
40-
environment?.TEMP ||
41-
"/tmp";
34+
// Claude Code's macOS build falls back to /tmp and ignores the TMPDIR that
35+
// launchd always sets. Its other builds use `os.tmpdir()`, which reads these
36+
// from the environment it was launched with. A relative value is relative
37+
// to Claude's working directory, not this server's.
38+
const fallback =
39+
platform === "darwin"
40+
? "/tmp"
41+
: environment?.TMPDIR || environment?.TMP || environment?.TEMP || "/tmp";
42+
const base = environment?.CLAUDE_CODE_TMPDIR?.trim() || fallback;
4243
return path.resolve(cwd ?? ".", base, `claude-${uid}`);
4344
}
4445

0 commit comments

Comments
 (0)