@devries-cameron20 / t3code-1 / commits / 066c8fc0cd
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): delegated Claude children follow your subagent cache TTL setting (#22841)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 04:49 UTC 066c8fc0cd04c97988ff8892e440189545ac6994
2 files changed +82 -1
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+22
@@ -249,6 +249,28 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
249 assert.isUndefined(options.extraArgs?.["dangerously-skip-permissions"]);
250 });
251
252 + it("gives delegated children Claude's subagent prompt cache TTL", () => {
253 + const lineage = (relationshipToParent: "fork" | "subagent" | null) => ({
254 + lineage: {
255 + parentThreadId: null,
256 + relationshipToParent,
257 + rootThreadId: ThreadId.make("thread-root"),
258 + },
259 + });
260 + const env = { PATH: "/bin" };
261 + const ttl = (environment: NodeJS.ProcessEnv, ...args: Parameters<typeof lineage>) =>
262 + ClaudeAdapterV2.claudeQueryEnvironment(environment, lineage(...args), "5m")
263 + .CLAUDE_CODE_PROMPT_CACHE_TTL;
264 + assert.equal(ttl(env, "subagent"), "5m");
265 + assert.isUndefined(ttl(env, null));
266 + assert.isUndefined(ttl(env, "fork"));
267 + assert.equal(ttl({ ...env, CLAUDE_CODE_PROMPT_CACHE_TTL: "1h" }, "subagent"), "1h");
268 + assert.strictEqual(
269 + ClaudeAdapterV2.claudeQueryEnvironment(env, lineage("subagent"), undefined),
270 + env,
271 + );
272 + });
273 +
274 it("projects AskUserQuestion input with question text as the answer key", () => {
275 const preview = "\n **Proposed change**\n\n```ts\n\tconst enabled = true;\n```\n ";
276 assert.deepEqual(
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+60 -1
@@ -1244,6 +1244,24 @@ function claudeLiveSelectionFlagSettings(
1244 };
1245 }
1246
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 +
1265 export function makeClaudeQueryOptions(input: {
1266 readonly modelSelection: ModelSelection;
1267 readonly nativeThreadId: string;
@@ -2128,6 +2146,17 @@ const decodeClaudeBypassSettings = Schema.decodeUnknownEffect(
2146 fromLenientJson(ClaudeBypassSettings),
2147 );
2148
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 +
2160 function claudeBypassAvailability(
2161 settings: typeof ClaudeBypassSettings.Type,
2162 ): ClaudeBypassAvailability {
@@ -3862,6 +3891,30 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
3891 },
3892 );
3893
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 +
3918 const userInvocableSkills = (cwd: string | null) =>
3919 discoverClaudeSkills(
3920 adapterOptions.settings,
@@ -9154,7 +9207,13 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9207 cwd: turnInput.runtimePolicy.cwd,
9208 attachmentsDir,
9209 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 + ),
9217 tools: queryPolicy.tools ?? CLAUDE_CODE_PRESET_TOOLS,
9218 ...(mcpOverrides.allowedTools === undefined
9219 ? {}