Skip to content

Commit 52c5195

Browse files
committed
fix(server): Claude "Auto-compact after" overrides CLAUDE_CODE_AUTO_COMPACT_WINDOW
1 parent 587deab commit 52c5195

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,23 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
395395
});
396396
});
397397

398+
it("makes Auto-compact after beat CLAUDE_CODE_AUTO_COMPACT_WINDOW from settings env", () => {
399+
const options = ClaudeAdapterV2.makeClaudeQueryOptions({
400+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
401+
nativeThreadId: "native-auto-compact-env",
402+
resume: false,
403+
cwd: "/workspace",
404+
settings: AUTO_COMPACT_CLAUDE_SETTINGS,
405+
sdkSettings: { env: { CLAUDE_CODE_AUTO_COMPACT_WINDOW: "1000000", OTHER: "kept" } },
406+
});
407+
const settings = options.settings as {
408+
autoCompactWindow?: number;
409+
env?: Record<string, string>;
410+
};
411+
assert.equal(settings.autoCompactWindow, 300_000);
412+
assert.deepEqual(settings.env, { CLAUDE_CODE_AUTO_COMPACT_WINDOW: "300000", OTHER: "kept" });
413+
});
414+
398415
it("sends a custom model named like a Claude Code alias to the API unchanged", () => {
399416
const options = ClaudeAdapterV2.makeClaudeQueryOptions({
400417
modelSelection: { instanceId: CLAUDE_TEST_MODEL_SELECTION.instanceId, model: "opus" },

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,16 +2024,25 @@ export function makeClaudeQueryOptions(input: {
20242024
compiledSelection.apiModelId,
20252025
}
20262026
: undefined;
2027+
// Claude Code prefers CLAUDE_CODE_AUTO_COMPACT_WINDOW from any settings env over
2028+
// autoCompactWindow, and flag settings env beats the settings files.
2029+
const autoCompactEnv =
2030+
input.settings?.autoCompactWindow === undefined || input.settings.autoCompactWindow.length === 0
2031+
? undefined
2032+
: { CLAUDE_CODE_AUTO_COMPACT_WINDOW: input.settings.autoCompactWindow };
20272033
// A settings file path cannot take extra keys, so it goes through unchanged.
20282034
const effectiveQuerySettings =
2029-
(input.toolSearchOverride === undefined && aliasOverrideEnv === undefined) ||
2035+
(input.toolSearchOverride === undefined &&
2036+
aliasOverrideEnv === undefined &&
2037+
autoCompactEnv === undefined) ||
20302038
typeof compactQuerySettings === "string"
20312039
? compactQuerySettings
20322040
: ({
20332041
...compactQuerySettings,
20342042
env: {
20352043
...compactQuerySettings?.env,
20362044
...aliasOverrideEnv,
2045+
...autoCompactEnv,
20372046
...(input.toolSearchOverride === undefined
20382047
? {}
20392048
: { ENABLE_TOOL_SEARCH: input.toolSearchOverride }),

0 commit comments

Comments
 (0)