claude-code - 💡(How to fix) Fix GrowthBook experiment tengu_amber_redwood silently reduces autocompact window to ~80k on Sonnet 200k (v2.1.92+ regression) [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46331Fetched 2026-04-11 06:23:06
View on GitHub
Comments
2
Participants
2
Timeline
9
Reactions
0
Timeline (top)
labeled ×5commented ×2mentioned ×1subscribed ×1

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.

Error Message

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.

Root Cause

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.

Fix Action

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).

Code Example

autoCompactThreshold = contextWindow - maxOutputTokens(20k) - buffer(13k)

---

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
}

---

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"
    });
}

---

{
  "env": {
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000"
  }
}
RAW_BUFFERClick to expand / collapse

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)

SessionModelpreTokens% of native windowExpected threshold
bb7608fcsonnet-4-648,27524.1% of 200k167k
bb7608fcsonnet-4-645,28122.6% of 200k167k
bb7608fcsonnet-4-646,77123.4% of 200k167k
02395a86sonnet-4-650,20625.1% of 200k167k
904ab744opus-4-675,4147.5% of 1M967k
904ab744opus-4-647,3534.7% of 1M967k
904ab744opus-4-650,2315.0% of 1M967k

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

  1. Install Claude Code v2.1.100 on macOS arm64
  2. Use model sonnet-4-6 (standard 200k context, NOT the 1M variant)
  3. Have a conversation with 3-5 turns involving tool use (file reads, bash commands)
  4. Observe compaction triggers at ~45-50k tokens (~23% of 200k)
  5. Check JSONL transcript: compact_boundary events show preTokens ≈ 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

  1. CLAUDE_AUTOCOMPACT_PCT_OVERRIDE cannot raise the threshold — the code uses Math.min(userPct, defaultThreshold), silently ignoring any value above default (#31806)
  2. DISABLE_AUTO_COMPACT=1 does not affect microcompacts — three additional silent compaction mechanisms (time-based microcompact, cached microcompact, tool-result budget via tengu_hawthorn_window) run independently
  3. 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 #43989)

Related issues

  • #43989 — same experiment, Opus 1M → 400k
  • #42375 — same class of bug, Opus 1M at 6%
  • #42817 — consolidated report: multiple disable methods silently ignored
  • #31806 — CLAUDE_AUTOCOMPACT_PCT_OVERRIDE capped by Math.min
  • #45977 — DISABLE_AUTO_COMPACT=1 bypassed on session resume
  • #42542 — silent microcompacts not affected by any user override

extent analysis

TL;DR

Setting the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable to a higher value, such as 1000000, may override the experiment-driven compaction and prevent premature compaction.

Guidance

  1. Verify the issue: Check if the compaction is indeed triggered at ~45-50k tokens by analyzing the JSONL session transcripts.
  2. Apply the workaround: Add the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable to ~/.claude/settings.json with a value of 1000000 to override the experiment.
  3. Monitor the behavior: Observe if the compaction threshold changes after applying the workaround and if the sessions become more stable.
  4. Check for related issues: Be aware of other related issues, such as #43989, #42375, #42817, #31806, #45977, and #42542, which may affect the behavior of the compaction mechanism.

Example

To apply the workaround, add the following to ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_AUTO_COMPACT_WINDOW": "1000000"
  }
}

Note that this workaround may not work on all arm64 native builds, as reported in #43989.

Notes

The issue seems to be related to the GrowthBook experiment "tengu_amber_redwood" silently reducing the autocompact window. The provided workaround may help override this experiment, but it may not be a permanent fix. Additionally, there are other related issues that may affect the behavior of the compaction mechanism.

Recommendation

Apply the workaround by setting the CLAUDE_CODE_AUTO_COMPACT_WINDOW environment variable to a higher value, as it may help prevent premature compaction and improve the stability of the sessions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING