@@ -573,6 +573,18 @@ export class ClaudeAppendSystemPromptMissingValueError extends Schema.TaggedErro
573573 }
574574}
575575
576+ export class ClaudeSettingsLaunchArgError extends Schema.TaggedError<ClaudeSettingsLaunchArgError>()(
577+ "ClaudeSettingsLaunchArgError",
578+ {
579+ path: Schema.optional(Schema.String),
580+ cause: Schema.optional(Schema.Defect()),
581+ },
582+ ) {
583+ override get message(): string {
584+ return `Claude could not read the --settings launch argument${this.path === undefined ? "" : ` at ${this.path}`} as a JSON object. Fix it in the Claude launch arguments, then send the message again.`;
585+ }
586+ }
587+
576588export interface ClaudeAgentSdkQueryRunnerShape {
577589 readonly allocateSessionId: Effect.Effect<string, ClaudeAgentSdkQueryRunnerError>;
578590 readonly open: (
@@ -648,7 +660,7 @@ export interface ClaudeAgentSdkLoggedQueryOptions {
648660 readonly cwd?: ClaudeAgentSdkQueryOptions["cwd"];
649661 readonly allowedTools?: ClaudeAgentSdkQueryOptions["allowedTools"];
650662 readonly disallowedTools?: ClaudeAgentSdkQueryOptions["disallowedTools"];
651- readonly settings ?: ClaudeAgentSdkQueryOptions["settings"] ;
663+ readonly settingKeys ?: ReadonlyArray<string> ;
652664 readonly effort?: ClaudeAgentSdkQueryOptions["effort"];
653665 readonly includePartialMessages?: true;
654666 readonly pathToClaudeCodeExecutable?: ClaudeAgentSdkQueryOptions["pathToClaudeCodeExecutable"];
@@ -787,7 +799,10 @@ export function loggedClaudeQueryOptions(
787799 ...(options.cwd === undefined ? {} : { cwd: options.cwd }),
788800 ...(options.allowedTools === undefined ? {} : { allowedTools: options.allowedTools }),
789801 ...(options.disallowedTools === undefined ? {} : { disallowedTools: options.disallowedTools }),
790- ...(options.settings === undefined ? {} : { settings: options.settings }),
802+ // Settings can carry the user's --settings values, such as an env block with credentials.
803+ ...(typeof options.settings === "object" && options.settings !== null
804+ ? { settingKeys: Object.keys(options.settings) }
805+ : {}),
791806 ...(options.effort === undefined ? {} : { effort: options.effort }),
792807 ...(options.includePartialMessages === true ? { includePartialMessages: true } : {}),
793808 ...(options.pathToClaudeCodeExecutable === undefined
@@ -1431,6 +1446,8 @@ export function makeClaudeQueryOptions(input: {
14311446 "dangerously-skip-permissions": launchArgSkipPermissions,
14321447 "append-system-prompt": launchArgAppendSystemPrompt,
14331448 "append-system-prompt-file": _launchArgAppendSystemPromptFile,
1449+ // The SDK replaces this flag with options.settings, so it arrives read as sdkSettings.
1450+ settings: _launchArgSettings,
14341451 ...extraArgs
14351452 } = input.settings === undefined ? {} : parseCliArgs(input.settings.launchArgs).flags;
14361453 // Claude Code overwrites its CLI append text with the SDK's initialize
@@ -1579,6 +1596,42 @@ const readClaudeAppendSystemPromptFile = Effect.fnUntraced(function* (input: {
15791596 );
15801597});
15811598
1599+ const decodeClaudeLaunchArgSettings = Schema.decodeUnknownEffect(
1600+ fromLenientJson(Schema.Record(Schema.String, Schema.Unknown)),
1601+ );
1602+
1603+ /**
1604+ * Reads the --settings launch argument: a value starting with a brace is inline
1605+ * JSON, anything else is a file path relative to the cwd. makeClaudeQueryOptions
1606+ * merges the result beneath T3's own settings.
1607+ */
1608+ const readClaudeLaunchArgSettings = Effect.fn("ClaudeAdapterV2.readLaunchArgSettings")(
1609+ function* (input: {
1610+ readonly settings: ClaudeSettings | undefined;
1611+ readonly cwd: string | null;
1612+ readonly fileSystem: FileSystem.FileSystem;
1613+ readonly path: Path.Path;
1614+ }) {
1615+ if (input.settings === undefined) return undefined;
1616+ const value = parseCliArgs(input.settings.launchArgs).flags.settings;
1617+ if (value === undefined) return undefined;
1618+ const trimmed = value?.trim() ?? "";
1619+ if (trimmed.length === 0) return yield* new ClaudeSettingsLaunchArgError({});
1620+ // The CLI also wants a closing brace, but then malformed JSON, secrets included, would
1621+ // become the file path in the error message.
1622+ if (trimmed.startsWith("{")) {
1623+ return (yield* decodeClaudeLaunchArgSettings(trimmed).pipe(
1624+ Effect.mapError((cause) => new ClaudeSettingsLaunchArgError({ cause })),
1625+ )) as ClaudeSdkSettings;
1626+ }
1627+ const filePath = input.path.resolve(input.cwd ?? ".", trimmed);
1628+ return (yield* input.fileSystem.readFileString(filePath).pipe(
1629+ Effect.flatMap(decodeClaudeLaunchArgSettings),
1630+ Effect.mapError((cause) => new ClaudeSettingsLaunchArgError({ path: filePath, cause })),
1631+ )) as ClaudeSdkSettings;
1632+ },
1633+ );
1634+
15821635export const CLAUDE_T3_MCP_TOOL_WILDCARD = "mcp__t3-code__*";
15831636
15841637// Keep in sync with OrchestratorToolkit Tool.Readonly annotations; ClaudeAdapterV2.test.ts checks this.
@@ -2507,6 +2560,7 @@ const ClaudeBypassSettings = Schema.StructWithRest(
25072560const decodeClaudeBypassSettings = Schema.decodeUnknownEffect(
25082561 fromLenientJson(ClaudeBypassSettings),
25092562);
2563+ const decodeClaudeLaunchArgBypassSettings = Schema.decodeUnknownEffect(ClaudeBypassSettings);
25102564
25112565const ClaudePromptCacheTtl = Schema.Literals(["5m", "1h"]);
25122566const decodeClaudePromptCacheTtl = Schema.decodeUnknownOption(ClaudePromptCacheTtl);
@@ -4279,12 +4333,17 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
42794333 serverManagedSettings: remote,
42804334 }),
42814335 );
4282- const cascade = claudeBypassAvailability(resolved.effective);
4283- const user = claudeBypassAvailability(home);
4284- const cached = claudeBypassAvailability(remote);
4336+ const launchArgSettings = yield* readClaudeLaunchArgSettings({
4337+ settings: adapterOptions.settings,
4338+ cwd,
4339+ fileSystem,
4340+ path,
4341+ });
4342+ const launch = yield* decodeClaudeLaunchArgBypassSettings(launchArgSettings ?? {});
4343+ const sources = [resolved.effective, home, remote, launch].map(claudeBypassAvailability);
42854344 return {
4286- bypassDisabled: cascade.bypassDisabled || user .bypassDisabled || cached.bypassDisabled ,
4287- autoDisabled: cascade.autoDisabled || user .autoDisabled || cached.autoDisabled ,
4345+ bypassDisabled: sources.some((source) => source .bypassDisabled) ,
4346+ autoDisabled: sources.some((source) => source .autoDisabled) ,
42884347 };
42894348 },
42904349 );
@@ -4357,10 +4416,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
43574416 if (path.dirname(directory) === directory) return cwd;
43584417 }
43594418 });
4360- // Settings env beats the process env, local over project over user, and a local file an older
4361- // Claude Code left in cwd applies under the root one. resolveSettings reads local from cwd only.
4419+ // Settings env beats the process env, --settings over local over project over user, and a local
4420+ // file an older Claude Code left in cwd applies under the root one. resolveSettings reads local
4421+ // from cwd only.
43624422 const resolveToolSearchOverride = Effect.fn("ClaudeAdapterV2.resolveToolSearchOverride")(
4363- function* (cwd: string | null) {
4423+ function* (cwd: string | null, launchArgSettings: ClaudeSdkSettings | undefined) {
4424+ const launchValue = launchArgSettings?.env?.ENABLE_TOOL_SEARCH;
4425+ if (typeof launchValue === "string") return claudeToolSearchOverride(launchValue);
43644426 const localDirectory = cwd === null ? null : yield* localSettingsDirectory(cwd);
43654427 const settingsFiles = [
43664428 ...(cwd === null || localDirectory === null
@@ -9711,6 +9773,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
97119773 fileSystem,
97129774 path,
97139775 });
9776+ const launchArgSettings = yield* readClaudeLaunchArgSettings({
9777+ settings: adapterOptions.settings,
9778+ cwd: turnInput.runtimePolicy.cwd,
9779+ fileSystem,
9780+ path,
9781+ });
97149782 const closedExistingNativeThreadId = existing !== null ? existing.nativeThreadId : null;
97159783 if (existing !== null) {
97169784 yield* existing.query.close.pipe(Effect.ignore);
@@ -9728,7 +9796,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
97289796 turnInput.nativeThreadHasTurns ?? turnInput.providerTurnOrdinal > 1;
97299797 const shouldResume =
97309798 resumeSessionAt !== undefined || openedWithResume || hasPersistedProviderTurn;
9731- const toolSearchOverride = yield* resolveToolSearchOverride(turnInput.runtimePolicy.cwd);
9799+ const toolSearchOverride = yield* resolveToolSearchOverride(
9800+ turnInput.runtimePolicy.cwd,
9801+ launchArgSettings,
9802+ );
97329803 const queryOptions = makeClaudeQueryOptions({
97339804 modelSelection: turnInput.modelSelection,
97349805 nativeThreadId,
@@ -9737,6 +9808,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
97379808 cwd: turnInput.runtimePolicy.cwd,
97389809 attachmentsDir,
97399810 settings: adapterOptions.settings,
9811+ ...(launchArgSettings === undefined ? {} : { sdkSettings: launchArgSettings }),
97409812 environment: claudeQueryEnvironment(
97419813 adapterOptions.environment,
97429814 turnInput.appThread,
0 commit comments