Skip to content

Commit a07cfd4

Browse files
committed
fix(server): resolve relative Claude config paths
1 parent 498f6d2 commit a07cfd4

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,14 +1380,23 @@ export const layerQueryRunner: Layer.Layer<
13801380
),
13811381
subagentModel: Effect.fn("ClaudeAgentSdkQueryRunner.subagentModel")(function* (input) {
13821382
const homeDirectory = yield* HostProcess.HomeDirectory;
1383+
const environment = input.environment.CLAUDE_CONFIG_DIR
1384+
? {
1385+
...input.environment,
1386+
CLAUDE_CONFIG_DIR: path.resolve(
1387+
input.dir ?? ".",
1388+
input.environment.CLAUDE_CONFIG_DIR,
1389+
),
1390+
}
1391+
: input.environment;
13831392
const usesHostConfig =
1384-
claudeConfigDirOf(path, input.environment, homeDirectory) ===
1393+
claudeConfigDirOf(path, environment, homeDirectory) ===
13851394
claudeConfigDirOf(path, hostEnvironment, homeDirectory);
13861395
if (!usesHostConfig) {
13871396
const result = yield* runClaudeWorker({
13881397
method: "getSubagentModel",
13891398
sessionId: input.sessionId,
1390-
environment: input.environment,
1399+
environment,
13911400
options: { agentId: input.agentId, ...(input.dir === null ? {} : { dir: input.dir }) },
13921401
}).pipe(
13931402
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,68 @@ it.effect("forks a session stored under the instance's own CLAUDE_CONFIG_DIR", (
111111
}).pipe(Effect.provide(forkRunnerLayer)),
112112
).pipe(Effect.provide(NodeServices.layer)),
113113
);
114+
115+
it.effect.each(["absolute", "relative"] as const)(
116+
"reads a fork model from a %s custom Claude configuration directory",
117+
(kind) =>
118+
Effect.scoped(
119+
Effect.gen(function* () {
120+
const fileSystem = yield* FileSystem.FileSystem;
121+
const path = yield* Path.Path;
122+
const configDir = yield* fileSystem.makeTempDirectoryScoped({
123+
prefix: "t3-claude-model-config-",
124+
});
125+
const projectDir = yield* writeClaudeSession(configDir);
126+
const agentId = "agent-test";
127+
const subagentsDir = path.join(projectDir, FORK_SESSION_ID, "subagents");
128+
yield* fileSystem.makeDirectory(subagentsDir, { recursive: true });
129+
yield* fileSystem.writeFileString(
130+
path.join(subagentsDir, `agent-${agentId}.jsonl`),
131+
[
132+
{
133+
type: "user",
134+
uuid: "aaaaaaaa-0000-4000-8000-000000000011",
135+
parentUuid: null,
136+
sessionId: FORK_SESSION_ID,
137+
agentId,
138+
isSidechain: true,
139+
cwd: "/repo",
140+
message: { role: "user", content: "hello" },
141+
},
142+
{
143+
type: "assistant",
144+
uuid: "aaaaaaaa-0000-4000-8000-000000000012",
145+
parentUuid: "aaaaaaaa-0000-4000-8000-000000000011",
146+
sessionId: FORK_SESSION_ID,
147+
agentId,
148+
isSidechain: true,
149+
cwd: "/repo",
150+
message: {
151+
role: "assistant",
152+
model: "claude-haiku-4-5",
153+
content: [{ type: "text", text: "hi" }],
154+
},
155+
},
156+
]
157+
.map((entry) => JSON.stringify(entry))
158+
.join("\n") + "\n",
159+
);
160+
const runner = yield* ClaudeAgentSdkQueryRunner;
161+
const model = yield* runner.subagentModel({
162+
sessionId: FORK_SESSION_ID,
163+
agentId,
164+
dir: "/repo",
165+
environment: {
166+
...process.env,
167+
CLAUDE_CONFIG_DIR: kind === "relative" ? path.relative("/repo", configDir) : configDir,
168+
},
169+
threadId: ThreadId.make("thread-fork-model-config"),
170+
providerSessionId: ProviderSessionId.make("session-fork-model-config"),
171+
});
172+
assert.equal(model, "claude-haiku-4-5");
173+
}).pipe(Effect.provide(forkRunnerLayer)),
174+
).pipe(Effect.provide(NodeServices.layer)),
175+
);
114176
const realQueryRunner = layerQueryRunner.pipe(
115177
Layer.provide(PortScanner.layerTest),
116178
Layer.provide(

0 commit comments

Comments
 (0)