@@ -1244,6 +1244,24 @@ function claudeLiveSelectionFlagSettings(
12441244 } ;
12451245}
12461246
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.
1250+ export function claudeQueryEnvironment (
1251+ environment : NodeJS . ProcessEnv ,
1252+ appThread : Pick < OrchestrationV2AppThread , "lineage" > ,
1253+ subagentPromptCacheTtl : "5m" | "1h" | undefined ,
1254+ ) : NodeJS . ProcessEnv {
1255+ if (
1256+ appThread . lineage . relationshipToParent !== "subagent" ||
1257+ subagentPromptCacheTtl === undefined ||
1258+ environment . CLAUDE_CODE_PROMPT_CACHE_TTL !== undefined
1259+ ) {
1260+ return environment ;
1261+ }
1262+ return { ...environment , CLAUDE_CODE_PROMPT_CACHE_TTL : subagentPromptCacheTtl } ;
1263+ }
1264+
12471265export function makeClaudeQueryOptions ( input : {
12481266 readonly modelSelection : ModelSelection ;
12491267 readonly nativeThreadId : string ;
@@ -2128,6 +2146,17 @@ const decodeClaudeBypassSettings = Schema.decodeUnknownEffect(
21282146 fromLenientJson ( ClaudeBypassSettings ) ,
21292147) ;
21302148
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+
21312160function claudeBypassAvailability (
21322161 settings : typeof ClaudeBypassSettings . Type ,
21332162) : ClaudeBypassAvailability {
@@ -3862,6 +3891,30 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
38623891 } ,
38633892 ) ;
38643893
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+
38653918 const userInvocableSkills = ( cwd : string | null ) =>
38663919 discoverClaudeSkills (
38673920 adapterOptions . settings ,
@@ -9154,7 +9207,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
91549207 cwd : turnInput . runtimePolicy . cwd ,
91559208 attachmentsDir,
91569209 settings : adapterOptions . settings ,
9157- environment : adapterOptions . environment ,
9210+ environment : claudeQueryEnvironment (
9211+ adapterOptions . environment ,
9212+ turnInput . appThread ,
9213+ turnInput . appThread . lineage . relationshipToParent === "subagent"
9214+ ? yield * resolveSubagentPromptCacheTtl ( turnInput . runtimePolicy . cwd )
9215+ : undefined ,
9216+ ) ,
91589217 tools : queryPolicy . tools ?? CLAUDE_CODE_PRESET_TOOLS ,
91599218 ...( mcpOverrides . allowedTools === undefined
91609219 ? { }
0 commit comments