Skip to content

Commit d29e7cd

Browse files
t3dotggclaude
andcommitted
fix(server): Claude threads no longer join the Claude session that launched T3
When T3 starts from inside a Claude Code session, every claude it spawned inherited that session's id, messaging socket and token, and effort. mergeClaudeProcessEnvironment now drops those host-session variables before the instance env is applied. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d01b92c commit d29e7cd

2 files changed

Lines changed: 58 additions & 24 deletions

File tree

‎apps/server/src/provider/Drivers/ClaudeHome.test.ts‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,44 @@ it.layer(NodeServices.layer)("ClaudeHome", (it) => {
5959
);
6060
});
6161

62-
it.effect("labels Claude processes t3-code unless instance env or Claude settings set one", () =>
63-
Effect.gen(function* () {
64-
const fileSystem = yield* FileSystem.FileSystem;
65-
const path = yield* Path.Path;
66-
const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
67-
const host = { CLAUDE_CODE_ENTRYPOINT: "claude-desktop", KEEP: "1" };
68-
const instance = [{ name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false }];
62+
it.effect(
63+
"drops the launching Claude session and labels processes t3-code unless overridden",
64+
() =>
65+
Effect.gen(function* () {
66+
const fileSystem = yield* FileSystem.FileSystem;
67+
const path = yield* Path.Path;
68+
const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
69+
const host = {
70+
CLAUDE_CODE_ENTRYPOINT: "claude-desktop",
71+
CLAUDECODE: "1",
72+
CLAUDE_CODE_SESSION_ID: "host-session",
73+
CLAUDE_CODE_MESSAGING_SOCKET: "/tmp/host-claude.sock",
74+
CLAUDE_EFFORT: "high",
75+
KEEP: "1",
76+
};
77+
const instance = [
78+
{ name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false },
79+
{ name: "CLAUDE_EFFORT", value: "low", sensitive: false },
80+
];
6981

70-
expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toMatchObject({
71-
CLAUDE_CODE_ENTRYPOINT: "t3-code",
72-
KEEP: "1",
73-
});
74-
expect(
75-
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).CLAUDE_CODE_ENTRYPOINT,
76-
).toBe("instance");
82+
expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toEqual({
83+
CLAUDE_CODE_ENTRYPOINT: "t3-code",
84+
KEEP: "1",
85+
});
86+
expect(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).toEqual({
87+
CLAUDE_CODE_ENTRYPOINT: "instance",
88+
CLAUDE_EFFORT: "low",
89+
KEEP: "1",
90+
});
7791

78-
yield* fileSystem.writeFileString(
79-
path.join(homePath, "settings.json"),
80-
JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
81-
);
82-
expect(
83-
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).CLAUDE_CODE_ENTRYPOINT,
84-
).toBe("custom");
85-
}),
92+
yield* fileSystem.writeFileString(
93+
path.join(homePath, "settings.json"),
94+
JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
95+
);
96+
expect(
97+
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host))
98+
.CLAUDE_CODE_ENTRYPOINT,
99+
).toBe("custom");
100+
}),
86101
);
87102
});

‎apps/server/src/provider/Drivers/ClaudeHome.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function
4545
};
4646
});
4747

48+
// A Claude Code session that launched T3 exports these. A claude spawned with them acts as part of
49+
// that session: its session id, messaging socket and token, and effort.
50+
const CLAUDE_HOST_SESSION_VARIABLES = [
51+
"CLAUDECODE",
52+
"CLAUDE_CODE_SESSION_ID",
53+
"CLAUDE_CODE_HOST_SESSION_ID",
54+
"CLAUDE_CODE_CHILD_SESSION",
55+
"CLAUDE_CODE_SESSION_ATTENDED",
56+
"CLAUDE_CODE_MESSAGING_SOCKET",
57+
"CLAUDE_CODE_MESSAGING_TOKEN",
58+
"CLAUDE_CODE_EXECPATH",
59+
"CLAUDE_CODE_DESKTOP_APP_VERSION",
60+
"CLAUDE_EFFORT",
61+
"CLAUDE_PID",
62+
"CLAUDE_AGENT_SDK_VERSION",
63+
];
64+
4865
/**
4966
* Base env for the Claude processes T3 Code runs, before `makeClaudeEnvironment`.
5067
* Claude Code reads its entrypoint from the process env, not its settings `env`, so T3 Code applies that override itself.
@@ -54,10 +71,12 @@ export const mergeClaudeProcessEnvironment = Effect.fn("mergeClaudeProcessEnviro
5471
instanceEnvironment: ProviderInstanceEnvironment | undefined,
5572
hostEnvironment: NodeJS.ProcessEnv,
5673
) {
57-
const environment = yield* mergeProviderInstanceEnvironment(instanceEnvironment, {
74+
const baseEnvironment: NodeJS.ProcessEnv = {
5875
...hostEnvironment,
5976
CLAUDE_CODE_ENTRYPOINT: "t3-code",
60-
});
77+
};
78+
for (const name of CLAUDE_HOST_SESSION_VARIABLES) delete baseEnvironment[name];
79+
const environment = yield* mergeProviderInstanceEnvironment(instanceEnvironment, baseEnvironment);
6180
const settingsEntrypoint = (yield* readClaudeSettingsEnv(config, undefined, environment))
6281
.CLAUDE_CODE_ENTRYPOINT;
6382
return settingsEntrypoint

0 commit comments

Comments
 (0)