Skip to content

Commit 7be852b

Browse files
t3dotggclaude
andcommitted
Resolve relative CLAUDE_CONFIG_DIR against the workspace cwd
The spawned CLI resolves a relative CLAUDE_CONFIG_DIR against its own cwd (the workspace), while discovery resolved it against the server process's cwd — scanning a different skills directory. Resolve against the workspace cwd for parity. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent c1aba5c commit 7be852b

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,34 @@ it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
160160
}),
161161
);
162162

163+
it.effect("resolves a relative CLAUDE_CONFIG_DIR against the workspace cwd", () =>
164+
Effect.gen(function* () {
165+
const fs = yield* FileSystem.FileSystem;
166+
const path = yield* Path.Path;
167+
const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
168+
const workspace = path.join(tempDir, "workspace");
169+
yield* fs.makeDirectory(workspace, { recursive: true });
170+
171+
// The spawned CLI resolves a relative CLAUDE_CONFIG_DIR against its own
172+
// cwd (the workspace), so discovery must do the same.
173+
yield* writeSkill(
174+
path.join(workspace, "relative-config", "skills"),
175+
"relative-skill",
176+
["---", "name: relative-skill", "---"].join("\n"),
177+
);
178+
179+
const skills = yield* discoverClaudeSkills({ homePath: "" }, workspace, {
180+
CLAUDE_CONFIG_DIR: "relative-config",
181+
});
182+
183+
assert.deepEqual(
184+
skills.map((skill) => skill.name),
185+
["relative-skill"],
186+
);
187+
assert.equal(skills[0]?.scope, "user");
188+
}),
189+
);
190+
163191
it.effect("returns an empty list when no skill roots exist", () =>
164192
Effect.gen(function* () {
165193
const fs = yield* FileSystem.FileSystem;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function parseSkillFrontmatter(contents: string): SkillFrontmatter {
6464
const resolveClaudeConfigDirPath = Effect.fn("resolveClaudeConfigDirPath")(function* (
6565
config: Pick<ClaudeSettings, "homePath">,
6666
environment: NodeJS.ProcessEnv,
67+
cwd?: string,
6768
): Effect.fn.Return<string, never, Path.Path> {
6869
const path = yield* Path.Path;
6970
const homePath = config.homePath.trim();
@@ -72,10 +73,12 @@ const resolveClaudeConfigDirPath = Effect.fn("resolveClaudeConfigDirPath")(funct
7273
}
7374
// No tilde expansion here: the spawned CLI receives this env var verbatim
7475
// (env vars are never shell-expanded), so a literal `~` must stay literal
75-
// for discovery to scan the same directory the runtime would.
76+
// for discovery to scan the same directory the runtime would. A relative
77+
// value is resolved against the workspace cwd — the subprocess's own cwd —
78+
// for the same reason.
7679
const environmentConfigDir = environment.CLAUDE_CONFIG_DIR?.trim() ?? "";
7780
if (environmentConfigDir.length > 0) {
78-
return path.resolve(environmentConfigDir);
81+
return cwd ? path.resolve(cwd, environmentConfigDir) : path.resolve(environmentConfigDir);
7982
}
8083
return path.join(NodeOS.homedir(), ".claude");
8184
});
@@ -94,7 +97,7 @@ export const discoverClaudeSkills = Effect.fn("discoverClaudeSkills")(function*
9497
): Effect.fn.Return<ReadonlyArray<ServerProviderSkill>, never, FileSystem.FileSystem | Path.Path> {
9598
const fileSystem = yield* FileSystem.FileSystem;
9699
const path = yield* Path.Path;
97-
const configDirPath = yield* resolveClaudeConfigDirPath(config, environment ?? process.env);
100+
const configDirPath = yield* resolveClaudeConfigDirPath(config, environment ?? process.env, cwd);
98101

99102
const roots: ReadonlyArray<{ directory: string; scope: ClaudeSkillScope }> = [
100103
{ directory: path.join(configDirPath, "skills"), scope: "user" },

0 commit comments

Comments
 (0)