Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ClaudeHome.ts

45 lines1.7 KB

1import * as NodeOS from "node:os";
2​
3import type { ClaudeSettings } from "@t3tools/contracts";
4import * as Effect from "effect/Effect";
5import * as Path from "effect/Path";
6​
7import { expandHomePath } from "../../pathExpansion.ts";
8​
9export const resolveClaudeHomePath = Effect.fn("resolveClaudeHomePath")(function* (
10 config: Pick<ClaudeSettings, "homePath">,
11): Effect.fn.Return<string, never, Path.Path> {
12 const path = yield* Path.Path;
13 const homePath = config.homePath.trim();
14 return path.resolve(homePath.length > 0 ? expandHomePath(homePath) : NodeOS.homedir());
15});
16​
17export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function* (
18 config: Pick<ClaudeSettings, "homePath">,
19 baseEnv?: NodeJS.ProcessEnv,
20): Effect.fn.Return<NodeJS.ProcessEnv, never, Path.Path> {
21 const resolvedBaseEnv = baseEnv ?? process.env;
22 const homePath = config.homePath.trim();
23 if (homePath.length === 0) return resolvedBaseEnv;
24 const resolvedHomePath = yield* resolveClaudeHomePath(config);
25 return {
26 ...resolvedBaseEnv,
27 HOME: resolvedHomePath,
28 };
29});
30​
31export const makeClaudeContinuationGroupKey = Effect.fn("makeClaudeContinuationGroupKey")(
32 function* (config: Pick<ClaudeSettings, "homePath">): Effect.fn.Return<string, never, Path.Path> {
33 const resolvedHomePath = yield* resolveClaudeHomePath(config);
34 return `claude:home:${resolvedHomePath}`;
35 },
36);
37​
38export const makeClaudeCapabilitiesCacheKey = Effect.fn("makeClaudeCapabilitiesCacheKey")(
39 function* (
40 config: Pick<ClaudeSettings, "binaryPath" | "homePath">,
41 ): Effect.fn.Return<string, never, Path.Path> {
42 const resolvedHomePath = yield* resolveClaudeHomePath(config);
43 return `${config.binaryPath}\0${resolvedHomePath}`;
44 },
45);