The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Claude's auto-compact setting now wins over CLAUDE_CODE_AUTO_COMPACT_WINDOW (#35737)
Julius Marminge committed
Nov 12, 2026 at 16:49 UTC
b54dad1032bdfd596fb55ffc7081e6c41b5a68f1
2 files changed
+27
-3
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+14
@@ -395,6 +395,20 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
395
});
396
});
397
398
+ it("sends the auto-compact window as the env var Claude Code prefers", () => {
399
+ const options = ClaudeAdapterV2.makeClaudeQueryOptions({
400
+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
401
+ nativeThreadId: "native-auto-compact",
402
+ resume: false,
403
+ cwd: "/workspace",
404
+ settings: { ...DEFAULT_CLAUDE_SETTINGS, autoCompactWindow: "400000" },
405
+ });
406
+ assert.equal(
407
+ (options.settings as { env?: Record<string, string> }).env?.CLAUDE_CODE_AUTO_COMPACT_WINDOW,
408
+ "400000",
409
+ );
410
+ });
411
+
412
it("sends a custom model named like a Claude Code alias to the API unchanged", () => {
413
const options = ClaudeAdapterV2.makeClaudeQueryOptions({
414
modelSelection: { instanceId: CLAUDE_TEST_MODEL_SELECTION.instanceId, model: "opus" },
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+13
-3
@@ -2009,12 +2009,16 @@ export function makeClaudeQueryOptions(input: {
2009
: typeof input.sdkSettings === "object" && input.sdkSettings !== null
2010
? ({ ...input.sdkSettings, ...selectionSettings } as ClaudeSdkSettings)
2011
: selectionSettings;
2012
- const compactQuerySettings =
2012
+ const autoCompactWindow =
2013
input.settings?.autoCompactWindow === undefined || input.settings.autoCompactWindow.length === 0
2014
+ ? undefined
2015
+ : input.settings.autoCompactWindow;
2016
+ const compactQuerySettings =
2017
+ autoCompactWindow === undefined
2018
? querySettings
2019
: ({
2020
...(typeof querySettings === "object" && querySettings !== null ? querySettings : {}),
2017
- autoCompactWindow: Number(input.settings.autoCompactWindow),
2021
+ autoCompactWindow: Number(autoCompactWindow),
2022
} as ClaudeSdkSettings);
2023
// Claude Code expands a bare alias to its own model, so a custom model with an alias's name
2024
// pins the alias to itself.
@@ -2026,7 +2030,9 @@ export function makeClaudeQueryOptions(input: {
2030
: undefined;
2031
// A settings file path cannot take extra keys, so it goes through unchanged.
2032
const effectiveQuerySettings =
2029
- (input.toolSearchOverride === undefined && aliasOverrideEnv === undefined) ||
2033
+ (input.toolSearchOverride === undefined &&
2034
+ aliasOverrideEnv === undefined &&
2035
+ autoCompactWindow === undefined) ||
2036
typeof compactQuerySettings === "string"
2037
? compactQuerySettings
2038
: ({
@@ -2034,6 +2040,10 @@ export function makeClaudeQueryOptions(input: {
2040
env: {
2041
...compactQuerySettings?.env,
2042
...aliasOverrideEnv,
2043
+ // Claude Code ranks this env var above the autoCompactWindow setting.
2044
+ ...(autoCompactWindow === undefined
2045
+ ? {}
2046
+ : { CLAUDE_CODE_AUTO_COMPACT_WINDOW: autoCompactWindow }),
2047
...(input.toolSearchOverride === undefined
2048
? {}
2049
: { ENABLE_TOOL_SEARCH: input.toolSearchOverride }),