Repository navigation
Description
Summary
GrowthBook experiment tengu_amber_redwood silently reduces the autocompact window on Sonnet 4.6 (200k context) to an effective ~80k tokens, causing compaction at ~23-25% context usage. This is the same class of bug as #43989 (Opus 1M → 400k) but affecting standard 200k context models — a much wider user base.
The built-in notification jz7() that should warn users about experiment-driven compaction ("compacted at {X} · override with CLAUDE_CODE_AUTO_COMPACT_WINDOW=...") does not appear to fire or render visibly.
Evidence
Measured compaction events from JSONL session transcripts (v2.1.100)
| Session | Model | preTokens |
% of native window | Expected threshold |
|---|---|---|---|---|
| bb7608fc | sonnet-4-6 | 48,275 | 24.1% of 200k | 167k |
| bb7608fc | sonnet-4-6 | 45,281 | 22.6% of 200k | 167k |
| bb7608fc | sonnet-4-6 | 46,771 | 23.4% of 200k | 167k |
| 02395a86 | sonnet-4-6 | 50,206 | 25.1% of 200k | 167k |
| 904ab744 | opus-4-6 | 75,414 | 7.5% of 1M | 967k |
| 904ab744 | opus-4-6 | 47,353 | 4.7% of 1M | 967k |
| 904ab744 | opus-4-6 | 50,231 | 5.0% of 1M | 967k |
Cluster: 6/7 events trigger at 45,281–50,231 tokens (mean: 47,886). All well below the expected threshold.
Reverse-engineering the experiment value
From the source code (deobfuscated from v2.1.100 binary):
autoCompactThreshold = contextWindow - maxOutputTokens(20k) - buffer(13k)
If threshold ≈ 47k → effectiveWindow ≈ 60k → experiment is setting window ≈ 80k.
For Sonnet 200k: 80k is a 60% reduction of the native context window.
For Opus 1M: the 400k reported in #43989 is also a 60% reduction — consistent ratio.
Window resolution priority (from binary)
function vt(model, settingsWindow) {
let nativeWindow = getModelWindow(model);
// 1. env var CLAUDE_CODE_AUTO_COMPACT_WINDOW → highest priority
// 2. user settings (autoCompactWindow)
// 3. GrowthBook "tengu_amber_redwood" ← the problem
// 4. model native window ← never reached when enrolled
}Notification that should fire but doesn't
function jz7(app, model, window) {
let {source, configured} = vt(model, window);
if (source !== "experiment") return;
app.addNotification?.({
key: "autocompact-experiment-hint",
text: `compacted at ${configured} · override with CLAUDE_CODE_AUTO_COMPACT_WINDOW=1000000`,
priority: "medium"
});
}This notification exists specifically for experiment-enrolled users but either doesn't render or is dismissed before it can be seen.
Steps to Reproduce
- Install Claude Code v2.1.100 on macOS arm64
- Use model
sonnet-4-6(standard 200k context, NOT the 1M variant) - Have a conversation with 3-5 turns involving tool use (file reads, bash commands)
- Observe compaction triggers at ~45-50k tokens (~23% of 200k)
- Check JSONL transcript:
compact_boundaryevents showpreTokens≈ 47-50k
Expected Behavior
Sonnet 4.6 with 200k context should compact at:
200k - 20k(output) - 13k(buffer) = 167k tokens(~83.5% usage)
Actual Behavior
Compaction triggers at ~47-50k tokens (23-25% usage), wasting 75% of the context window.
Sessions become unusable: after compaction reduces to ~20-30k tokens, only 2-4 tool-use turns fit before the next compaction — creating a thrashing loop. In one session, 3 compactions occurred within 6 minutes.
Additional issues
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEcannot raise the threshold — the code usesMath.min(userPct, defaultThreshold), silently ignoring any value above default (CLAUDE_AUTOCOMPACT_PCT_OVERRIDE cannot raise threshold above default (~83%) #31806)DISABLE_AUTO_COMPACT=1does not affect microcompacts — three additional silent compaction mechanisms (time-based microcompact, cached microcompact, tool-result budget viatengu_hawthorn_window) run independently- No opt-out for experiments — users cannot inspect or disable GrowthBook flags without reverse-engineering the binary. The experiment silently overrides model capabilities that users are paying for.
Workaround
Add to ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000"
}
}This takes priority position 1 in vt(), overriding the experiment. Note: reportedly does not work on all arm64 native builds (#43989 comment by @creatornader).
Environment
- Claude Code version: 2.1.100
- Model: claude-sonnet-4-6 (200k) and claude-opus-4-6 (opusplan mode)
- Platform: macOS Darwin 25.4.0 (Apple Silicon arm64)
- Terminal: iTerm2 / zsh
- Regression since: v2.1.92 (confirmed by v2.1.92 regression: autocompact threshold reduced to 400k on Opus 4.6 (1M context) #43989)
Related issues
- v2.1.92 regression: autocompact threshold reduced to 400k on Opus 4.6 (1M context) #43989 — same experiment, Opus 1M → 400k
- Auto-compaction triggers at ~6% context usage on Opus 4.6 (1M context) #42375 — same class of bug, Opus 1M at 6%
- Auto-compact cannot be disabled — consolidated report with measurements #42817 — consolidated report: multiple disable methods silently ignored
- CLAUDE_AUTOCOMPACT_PCT_OVERRIDE cannot raise threshold above default (~83%) #31806 —
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEcapped byMath.min - Auto-compaction triggers at 3% context usage despite DISABLE_AUTO_COMPACT=1 #45977 —
DISABLE_AUTO_COMPACT=1bypassed on session resume - [BUG] Silent context degradation — tool results cleared without notification on 1M context sessions this issue documents three separate mechanisms (microcompact, cached microcompact, session memory compact) #42542 — silent microcompacts not affected by any user override
Activity
github-actions commentedon Apr 10, 2026
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
tavaresgmg commentedon Apr 10, 2026
Update: env var workaround is insufficient — two additional findings
Finding 1:
CLAUDE_CODE_AUTO_COMPACT_WINDOWin theenvblock does not survive compaction cyclesAfter applying the workaround (
CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000insettings.jsonenvblock), compaction still reverted to the ~47k threshold within the same session.Observed from JSONL (session bb7608fc):
Compaction 4 shows the env var working (121k instead of ~47k). But 4 minutes later, compaction 5 triggered at 45k — back to the experiment threshold.
Root cause hypothesis: The
envblock insettings.jsonis injected into the process environment at startup only. When a compaction event triggers an internal context/sub-session reset, the new context re-evaluates GrowthBook from scratch without the env var in scope — because the env injection happened in the parent process, not re-read from the JSON at runtime.Finding 2: Top-level
autoCompactWindowfield is the correct fixThe window resolution chain in the binary (priority order):
CLAUDE_CODE_AUTO_COMPACT_WINDOWenv var — injected at process startup onlyautoCompactWindow(top-level insettings.json) — read directly from JSON at runtimetengu_amber_redwoodThe top-level
autoCompactWindowfield bypasses the startup-injection problem because it's parsed from the settings file on each read, not from the process environment.Correct workaround (updated)
Add both to
~/.claude/settings.json:{ "autoCompactWindow": 200000, "env": { "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "200000" } }The
autoCompactWindowtop-level field (priority 2) is the reliable fix. Theenvblock entry alone (priority 1 in theory, but startup-only in practice) is insufficient for sessions that involve multiple compaction cycles.After applying this, restart Claude Code completely (Cmd+Q + reopen) — not just a new tab or session.
Note: this issue may still close as a duplicate of #43989 — thumbed-down the bot comment to prevent auto-close.
junaidtitan commentedon Apr 23, 2026
A silent experiment reducing your effective compaction window to 80k is especially painful because you lose context you thought you had. Cozempic's guard daemon prunes session bloat continuously at 4 configurable thresholds, so even if the internal autocompact window is artificially low, your actual useful context stays high. It also detects 1M context automatically for supported models.
pip install cozempic && cozempic inithttps://github.com/Ruya-AI/cozempicgithub-actions commentedon May 29, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Jul 28, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.