Skip to content

Commit f5d9f83

Browse files
committed
fix(claude): compact at the same point Codex does, not at 350k
The auto-context compact window was 350,000, chosen when the widest native row advertised 372,000. It now sits at 829,800 — the exact auto-compaction limit the Codex catalog ships for the same models (922,000 window, clamped to the measured input ceiling). Leaving the two apart meant one model compacting at 350k under Claude Code and at 829,800 under Codex. The new value still clears the measured 922,000 ceiling by ~92k, so compaction has room to run before the upstream refuses. This value is also the floor shouldMarkOneMillion uses, so a model must be able to host the window to carry the [1m] marker. Raising it drops the marker from routed 500k rows (grok-4.6) — correct, since a 500k model could never host a 1M accounting anyway. The 922k natives clear it and keep the marker. The GUI's manual-env fallback and the type comment move with it: a pasted export that disagrees with what the runtime injects is its own bug.
1 parent fd4d5f9 commit f5d9f83

5 files changed

Lines changed: 35 additions & 12 deletions

File tree

‎gui/src/pages/claude-manual-env.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export function buildManualEnv(state: ClaudeManualEnvState): string {
5353
...(marker === "proxy"
5454
? ['[ -z "${CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST+x}" ] && export CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1']
5555
: []),
56-
...(autoCompactActive ? [`export CLAUDE_CODE_AUTO_COMPACT_WINDOW=${state.autoCompactWindow ?? 350000}`] : []),
56+
// Mirrors AUTO_COMPACT_WINDOW_DEFAULT in src/claude/context-windows.ts — the copy a user
57+
// pastes has to match what the runtime injects, or the manual path compacts elsewhere.
58+
...(autoCompactActive ? [`export CLAUDE_CODE_AUTO_COMPACT_WINDOW=${state.autoCompactWindow ?? 829800}`] : []),
5759
...modelEnvExports,
5860
"claude",
5961
].join("\n");

‎src/claude/context-windows.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,20 @@ import { nativeOpenAiContextWindow, type CatalogModel } from "../codex/catalog";
1414

1515
const ONE_MILLION = 1_000_000;
1616

17-
/** Auto-context defaults (devlog 260712 020, user-approved). */
18-
export const AUTO_COMPACT_WINDOW_DEFAULT = 350_000;
17+
/**
18+
* Auto-context defaults (devlog 260712 020, user-approved).
19+
*
20+
* The compact window is the token count at which Claude Code starts compacting, and it is
21+
* also the floor `shouldMarkOneMillion` uses — a model may only carry the marker if it can
22+
* host this window. 350,000 was chosen when the widest native row advertised 372,000.
23+
*
24+
* It now matches the auto-compaction limit the Codex catalog ships for the same models
25+
* (`nativeAutoCompactLimit`: 829,800 against the 922,000 native window). Leaving the two
26+
* apart meant one model compacting at 350k under Claude Code and at 829,800 under Codex.
27+
* The value stays clear of the measured 922,000 ceiling by ~92k, so compaction still has
28+
* room to run before the upstream refuses.
29+
*/
30+
export const AUTO_COMPACT_WINDOW_DEFAULT = 829_800;
1931
export const AUTO_CONTEXT_FLOOR = 200_000;
2032
/** Binary-verified accepted range for CLAUDE_CODE_AUTO_COMPACT_WINDOW (2.1.207: pSo=1e5, yDs=1e6). */
2133
export const AUTO_COMPACT_WINDOW_MIN = 100_000;

‎src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ export interface OcxClaudeCodeConfig {
525525
* (the legacy DISABLE_COMPACT pair takes rule-1 precedence in the CLI).
526526
*/
527527
autoContext?: boolean;
528-
/** Compact-window tokens for auto-context. Default 350_000. */
528+
/** Compact-window tokens for auto-context. Default 829_800 (AUTO_COMPACT_WINDOW_DEFAULT). */
529529
autoCompactWindow?: number;
530530
/**
531531
* Bundled-skill content elision for ROUTED (non-Anthropic) models (devlog 260712

‎tests/claude-cli.test.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ describe("ocx claude env assembly", () => {
9696
expect(env.CLAUDE_CODE_ALWAYS_ENABLE_EFFORT).toBeUndefined();
9797
expect(env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBeUndefined();
9898
expect(env.DISABLE_COMPACT).toBeUndefined();
99-
// Auto-context IS on by default (devlog 020): compact window injected at 350k.
100-
expect(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("350000");
99+
// Auto-context IS on by default (devlog 020). The window now matches the auto-compaction
100+
// limit the Codex catalog ships for the same native rows (829,800 under a 922,000 window),
101+
// so one model does not compact at two different points depending on the client.
102+
expect(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("829800");
101103
});
102104

103105
test("opt-in levers: alwaysEnableEffort=1, maxContextTokens injects the official pair", () => {
@@ -165,14 +167,21 @@ describe("ocx claude env assembly", () => {
165167
expect(env.ANTHROPIC_MODEL).toBe("cursor/gpt-5.6-luna");
166168
});
167169

168-
test("auto-context: 372k slot gets [1m] + compact window rides along (devlog 020)", () => {
169-
const windows = { "mock/big": 372_000, "mock/small": 128_000 };
170+
test("auto-context: a slot wide enough for the compact window gets [1m], and the window rides along (devlog 020)", () => {
171+
// The fixture has to clear the default compact window (829,800) — marking a model that
172+
// cannot host it is the #854 defect the predicate exists to prevent.
173+
const windows = { "mock/big": 900_000, "mock/small": 128_000 };
170174
const env = buildClaudeEnv(cfg({
171175
claudeCode: { model: "mock/big", smallFastModel: "mock/small" },
172176
}), 10100, {}, windows);
173177
expect(env.ANTHROPIC_MODEL).toBe("mock/big[1m]");
174178
expect(env.ANTHROPIC_DEFAULT_HAIKU_MODEL).toBe("mock/small"); // below floor, unmarked
175-
expect(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("350000");
179+
expect(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("829800");
180+
// And a real native row at 922,000 clears it too — that is the model this default tracks.
181+
const native = buildClaudeEnv(cfg({
182+
claudeCode: { model: "gpt-5.6-sol" },
183+
}), 10100, {}, { "gpt-5.6-sol": 922_000 });
184+
expect(native.ANTHROPIC_MODEL).toBe("gpt-5.6-sol[1m]");
176185
});
177186

178187
test("auto-context: custom window moves both the env and the marking threshold", () => {

‎tests/system-env.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ describe("systemEnv lever keys (devlog 136 B6)", () => {
336336
expect(shellWrite!.data).not.toContain("DISABLE_COMPACT");
337337
});
338338

339-
test("auto-context default lever: AUTO_COMPACT_WINDOW 350000 injected, tracked, conditionally exported (devlog 020)", async () => {
339+
test("auto-context default lever: AUTO_COMPACT_WINDOW 829800 injected, tracked, conditionally exported (devlog 020)", async () => {
340340
const writes = capturedWrites();
341341
expect(await injectSystemEnv(4096, baseConfig)).toEqual({ injected: true });
342342
const setCalls = launchctlCommands();
343-
expect(setCalls).toContain("launchctl setenv CLAUDE_CODE_AUTO_COMPACT_WINDOW 350000");
343+
expect(setCalls).toContain("launchctl setenv CLAUDE_CODE_AUTO_COMPACT_WINDOW 829800");
344344
const trackingWrite = writes.filter(w => w.path.includes("system-env-port")).at(-1);
345345
expect(JSON.parse(trackingWrite!.data).injectedKeys).toContain("CLAUDE_CODE_AUTO_COMPACT_WINDOW");
346346
const shellWrite = writes.find(w => w.path.includes("claude-env.sh"));
347-
expect(shellWrite!.data).toContain(`[ -z "\${CLAUDE_CODE_AUTO_COMPACT_WINDOW+x}" ] && export CLAUDE_CODE_AUTO_COMPACT_WINDOW='350000'`);
347+
expect(shellWrite!.data).toContain(`[ -z "\${CLAUDE_CODE_AUTO_COMPACT_WINDOW+x}" ] && export CLAUDE_CODE_AUTO_COMPACT_WINDOW='829800'`);
348348
});
349349

350350
test("auto-context: user-preset launchctl value is respected and untracked (audit 021 #2)", async () => {

0 commit comments

Comments
 (0)