-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(claude): isolate capability probe settings #8908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,66 @@ export const resolveClaudeHomePath = Effect.fn("resolveClaudeHomePath")(function | |
| return path.resolve(homePath.length > 0 ? expandHomePath(homePath) : NodeOS.homedir()); | ||
| }); | ||
|
|
||
| /** | ||
| * Resolve the Claude config directory the spawned CLI uses. An explicit | ||
| * provider override wins, followed by the instance environment, then | ||
| * Claude's default `$HOME/.claude` location. | ||
| */ | ||
| export const resolveClaudeConfigDirPath = Effect.fn("resolveClaudeConfigDirPath")(function* ( | ||
| config: Pick<ClaudeSettings, "homePath">, | ||
| environment?: NodeJS.ProcessEnv, | ||
| cwd?: string, | ||
| ): Effect.fn.Return<string, never, Path.Path> { | ||
| const path = yield* Path.Path; | ||
| const homePath = config.homePath.trim(); | ||
| if (homePath.length > 0) { | ||
| return yield* resolveClaudeHomePath(config); | ||
| } | ||
|
|
||
| const resolvedEnvironment = environment ?? process.env; | ||
| // No tilde expansion here: the spawned CLI receives this env var verbatim | ||
| // (env vars are never shell-expanded), so a literal `~` must stay literal | ||
| // for discovery to scan the same directory the runtime would. A relative | ||
| // value is resolved against the workspace cwd — the subprocess's own cwd — | ||
| // for the same reason. | ||
| const environmentConfigDir = resolvedEnvironment.CLAUDE_CONFIG_DIR?.trim() ?? ""; | ||
| if (environmentConfigDir.length > 0) { | ||
| return cwd ? path.resolve(cwd, environmentConfigDir) : path.resolve(environmentConfigDir); | ||
| } | ||
| const inheritedHome = | ||
| resolvedEnvironment.HOME?.trim() || resolvedEnvironment.USERPROFILE?.trim() || NodeOS.homedir(); | ||
| return path.join(path.resolve(inheritedHome), ".claude"); | ||
| }); | ||
|
|
||
| /** | ||
| * Capability probes run from an existing neutral cwd because Claude treats | ||
| * `<cwd>/.claude/settings.json` as project settings. The intended config dir | ||
| * remains available through CLAUDE_CONFIG_DIR, including when it does not yet | ||
| * exist or arrived as a relative inherited environment variable. | ||
| */ | ||
| export const makeClaudeCapabilitiesProbeContext = Effect.fn("makeClaudeCapabilitiesProbeContext")( | ||
| function* ( | ||
| config: Pick<ClaudeSettings, "homePath">, | ||
| environment?: NodeJS.ProcessEnv, | ||
| workspaceCwd?: string, | ||
| ): Effect.fn.Return< | ||
| { readonly cwd: string; readonly environment: NodeJS.ProcessEnv }, | ||
| never, | ||
| Path.Path | ||
| > { | ||
| const path = yield* Path.Path; | ||
| const resolvedEnvironment = environment ?? process.env; | ||
| const configDirPath = yield* resolveClaudeConfigDirPath(config, environment, workspaceCwd); | ||
| return { | ||
| cwd: path.resolve(NodeOS.tmpdir()), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift Use a private probe directory. Line 71 runs the CLI from the shared system temporary-directory root. If Create an owned, unique, existing temporary subdirectory for the probe cwd. Clean it up when the provider is disposed. Keep the workspace only in 🤖 Prompt for AI Agents |
||
| environment: { | ||
| ...resolvedEnvironment, | ||
| CLAUDE_CONFIG_DIR: configDirPath, | ||
| }, | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function* ( | ||
| config: Pick<ClaudeSettings, "homePath">, | ||
| baseEnv?: NodeJS.ProcessEnv, | ||
|
|
@@ -47,10 +107,11 @@ export const makeClaudeContinuationGroupKey = Effect.fn("makeClaudeContinuationG | |
| export const makeClaudeCapabilitiesCacheKey = Effect.fn("makeClaudeCapabilitiesCacheKey")( | ||
| function* ( | ||
| config: Pick<ClaudeSettings, "binaryPath" | "homePath">, | ||
| cwd?: string, | ||
| environment?: NodeJS.ProcessEnv, | ||
| workspaceCwd?: string, | ||
| ): Effect.fn.Return<string, never, Path.Path> { | ||
| const resolvedHomePath = yield* resolveClaudeHomePath(config); | ||
| return `${config.binaryPath}\0${resolvedHomePath}\0${cwd ?? ""}`; | ||
| const configDirPath = yield* resolveClaudeConfigDirPath(config, environment, workspaceCwd); | ||
| return `${config.binaryPath}\0${configDirPath}`; | ||
| }, | ||
| ); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.