@@ -1244,20 +1244,22 @@ function claudeLiveSelectionFlagSettings(
12441244 } ;
12451245}
12461246
1247- // Claude Code gives SDK sessions a 1h prompt cache on subscriptions, but a delegated child runs a
1248- // tight tool loop like a native subagent, which gets 5m. A 1h write costs 2x base input and a 5m
1249- // write 1.25x, so children use 5m unless the provider instance sets its own TTL .
1247+ // A delegated child is its own SDK session, so Claude Code gives it the main-conversation cache
1248+ // TTL. When the user sets Claude's subagentPromptCacheTtl, the child follows it like a native
1249+ // subagent would. An explicit CLAUDE_CODE_PROMPT_CACHE_TTL on the instance still wins .
12501250export function claudeQueryEnvironment (
12511251 environment : NodeJS . ProcessEnv ,
12521252 appThread : Pick < OrchestrationV2AppThread , "lineage" > ,
1253+ subagentPromptCacheTtl : "5m" | "1h" | undefined ,
12531254) : NodeJS . ProcessEnv {
12541255 if (
12551256 appThread . lineage . relationshipToParent !== "subagent" ||
1257+ subagentPromptCacheTtl === undefined ||
12561258 environment . CLAUDE_CODE_PROMPT_CACHE_TTL !== undefined
12571259 ) {
12581260 return environment ;
12591261 }
1260- return { ...environment , CLAUDE_CODE_PROMPT_CACHE_TTL : "5m" } ;
1262+ return { ...environment , CLAUDE_CODE_PROMPT_CACHE_TTL : subagentPromptCacheTtl } ;
12611263}
12621264
12631265export function makeClaudeQueryOptions ( input : {
@@ -2144,6 +2146,17 @@ const decodeClaudeBypassSettings = Schema.decodeUnknownEffect(
21442146 fromLenientJson ( ClaudeBypassSettings ) ,
21452147) ;
21462148
2149+ const ClaudePromptCacheTtl = Schema . Literals ( [ "5m" , "1h" ] ) ;
2150+ const decodeClaudePromptCacheTtl = Schema . decodeUnknownOption ( ClaudePromptCacheTtl ) ;
2151+ const decodeClaudeSubagentCacheSettings = Schema . decodeUnknownEffect (
2152+ fromLenientJson (
2153+ Schema . StructWithRest (
2154+ Schema . Struct ( { subagentPromptCacheTtl : Schema . optionalKey ( ClaudePromptCacheTtl ) } ) ,
2155+ [ Schema . Record ( Schema . String , Schema . Unknown ) ] ,
2156+ ) ,
2157+ ) ,
2158+ ) ;
2159+
21472160function claudeBypassAvailability (
21482161 settings : typeof ClaudeBypassSettings . Type ,
21492162) : ClaudeBypassAvailability {
@@ -3878,6 +3891,30 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
38783891 } ,
38793892 ) ;
38803893
3894+ // Claude Code's own subagent TTL setting, in its precedence order. Unset or unreadable means
3895+ // Anthropic's default applies.
3896+ const resolveSubagentPromptCacheTtl = Effect . fn ( "ClaudeAdapterV2.resolveSubagentPromptCacheTtl" ) (
3897+ function * ( cwd : string | null ) {
3898+ const fromEnvironment = decodeClaudePromptCacheTtl (
3899+ adapterOptions . environment . CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL ,
3900+ ) ;
3901+ if ( Option . isSome ( fromEnvironment ) ) return fromEnvironment . value ;
3902+ const resolved = yield * Effect . tryPromise ( ( ) =>
3903+ resolveClaudeSettings ( {
3904+ ...( cwd === null ? { } : { cwd } ) ,
3905+ settingSources : customHome ? [ "project" , "local" ] : [ "user" , "project" , "local" ] ,
3906+ } ) ,
3907+ ) . pipe ( Effect . orElseSucceed ( ( ) => undefined ) ) ;
3908+ const home = customHome
3909+ ? yield * fileSystem . readFileString ( path . join ( homePath , "settings.json" ) ) . pipe (
3910+ Effect . flatMap ( decodeClaudeSubagentCacheSettings ) ,
3911+ Effect . orElseSucceed ( ( ) => ( { subagentPromptCacheTtl : undefined } ) ) ,
3912+ )
3913+ : undefined ;
3914+ return resolved ?. effective . subagentPromptCacheTtl ?? home ?. subagentPromptCacheTtl ;
3915+ } ,
3916+ ) ;
3917+
38813918 const userInvocableSkills = ( cwd : string | null ) =>
38823919 discoverClaudeSkills (
38833920 adapterOptions . settings ,
@@ -9170,7 +9207,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
91709207 cwd : turnInput . runtimePolicy . cwd ,
91719208 attachmentsDir,
91729209 settings : adapterOptions . settings ,
9173- environment : claudeQueryEnvironment ( adapterOptions . environment , turnInput . appThread ) ,
9210+ environment : claudeQueryEnvironment (
9211+ adapterOptions . environment ,
9212+ turnInput . appThread ,
9213+ turnInput . appThread . lineage . relationshipToParent === "subagent"
9214+ ? yield * resolveSubagentPromptCacheTtl ( turnInput . runtimePolicy . cwd )
9215+ : undefined ,
9216+ ) ,
91749217 tools : queryPolicy . tools ?? CLAUDE_CODE_PRESET_TOOLS ,
91759218 ...( mcpOverrides . allowedTools === undefined
91769219 ? { }
0 commit comments