The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as NodeOS from "node:os"; |
| 2 | |
| 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 4 | import { describe, expect, it } from "@effect/vitest"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as FileSystem from "effect/FileSystem"; |
| 7 | import * as Path from "effect/Path"; |
| 8 | |
| 9 | import { |
| 10 | makeClaudeCapabilitiesCacheKey, |
| 11 | makeClaudeContinuationGroupKey, |
| 12 | makeClaudeEnvironment, |
| 13 | mergeClaudeProcessEnvironment, |
| 14 | resolveClaudeHomePath, |
| 15 | } from "./ClaudeHome.ts"; |
| 16 | |
| 17 | it.layer(NodeServices.layer)("ClaudeHome", (it) => { |
| 18 | describe("Claude home resolution", () => { |
| 19 | it.effect("resolves configured Claude HOME and stamps continuation/cache keys with it", () => |
| 20 | Effect.gen(function* () { |
| 21 | const path = yield* Path.Path; |
| 22 | const homePath = "~/.claude-work"; |
| 23 | const resolved = path.resolve(NodeOS.homedir(), ".claude-work"); |
| 24 | |
| 25 | expect(yield* resolveClaudeHomePath({ homePath })).toBe(resolved); |
| 26 | expect((yield* makeClaudeEnvironment({ homePath })).CLAUDE_CONFIG_DIR).toBe(resolved); |
| 27 | expect(yield* makeClaudeContinuationGroupKey({ homePath })).toBe(`claude:home:${resolved}`); |
| 28 | expect(yield* makeClaudeCapabilitiesCacheKey({ binaryPath: "claude", homePath })).toBe( |
| 29 | `claude\0${resolved}\0`, |
| 30 | ); |
| 31 | }), |
| 32 | ); |
| 33 | |
| 34 | it.effect("uses inherited CLAUDE_CONFIG_DIR when homePath is empty", () => |
| 35 | Effect.gen(function* () { |
| 36 | const path = yield* Path.Path; |
| 37 | const inherited = path.resolve("/tmp/claude-inherited"); |
| 38 | const environment = { CLAUDE_CONFIG_DIR: inherited }; |
| 39 | |
| 40 | expect(yield* resolveClaudeHomePath({ homePath: "" }, environment)).toBe(inherited); |
| 41 | expect(yield* makeClaudeContinuationGroupKey({ homePath: "" }, environment)).toBe( |
| 42 | `claude:home:${inherited}`, |
| 43 | ); |
| 44 | |
| 45 | const explicit = path.resolve(NodeOS.homedir(), ".claude-work"); |
| 46 | expect(yield* resolveClaudeHomePath({ homePath: "~/.claude-work" }, environment)).toBe( |
| 47 | explicit, |
| 48 | ); |
| 49 | }), |
| 50 | ); |
| 51 | |
| 52 | it.effect("separates capability probes by cwd", () => |
| 53 | Effect.gen(function* () { |
| 54 | const config = { binaryPath: "claude", homePath: "" }; |
| 55 | const first = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-a"); |
| 56 | const second = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-b"); |
| 57 | expect(first).not.toBe(second); |
| 58 | }), |
| 59 | ); |
| 60 | }); |
| 61 | |
| 62 | it.effect( |
| 63 | "drops the launching Claude session and Electron's run-as-Node flag, 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 | ELECTRON_RUN_AS_NODE: "1", |
| 76 | KEEP: "1", |
| 77 | }; |
| 78 | const instance = [ |
| 79 | { name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false }, |
| 80 | { name: "CLAUDE_EFFORT", value: "low", sensitive: false }, |
| 81 | ]; |
| 82 | |
| 83 | expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toEqual({ |
| 84 | CLAUDE_CODE_ENTRYPOINT: "t3-code", |
| 85 | KEEP: "1", |
| 86 | }); |
| 87 | expect(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).toEqual({ |
| 88 | CLAUDE_CODE_ENTRYPOINT: "instance", |
| 89 | CLAUDE_EFFORT: "low", |
| 90 | KEEP: "1", |
| 91 | }); |
| 92 | |
| 93 | yield* fileSystem.writeFileString( |
| 94 | path.join(homePath, "settings.json"), |
| 95 | JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }), |
| 96 | ); |
| 97 | expect( |
| 98 | (yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)) |
| 99 | .CLAUDE_CODE_ENTRYPOINT, |
| 100 | ).toBe("custom"); |
| 101 | }), |
| 102 | ); |
| 103 | }); |