Skip to content

Opus 4.6 (1M context): autocompact triggers at ~76K tokens — 92% of context window wasted #34332

Open

Description

@mackmother

Summary

Claude Code's automatic context compaction fires at approximately 76K tokens even when using Opus 4.6 with a 1M context window. This discards valuable conversation history with 924K tokens of headroom remaining (92% unused). This is a regression compared to 200K model behavior.

Environment

  • Claude Code CLI (latest)
  • Model: Opus 4.6 (1M context) — confirmed via /model command
  • macOS Darwin 24.6.0, zsh

What happened

  1. Started a session on Opus 4.6 (1M context window)
  2. Had a rich multi-step conversation: RFP analysis, 4 research subagents, design spec, 2 council review subagents, code review subagent, implementation, testing, 2 production deploys
  3. At approximately 76,144 input tokens (7.6% of 1M), Claude Code automatically compacted/compressed earlier messages
  4. Lost the entire first half of the conversation — detailed analysis, research findings, and design decisions that were actively being referenced
  5. Our context monitoring script confirmed actual usage at session end: 138,280 / 1,000,000 tokens = 13.8%

The problem

The autocompact threshold appears to use a hardcoded absolute token count calibrated for 200K windows, regardless of the model's actual context window size.

Window Compaction at 76K Headroom wasted
200K 38% — aggressive but defensible 124K
1M 7.6% — absurd 924K

This means the 1M upgrade actively provides worse conversation retention than 200K — same compaction trigger, 5x the wasted headroom. The entire value proposition of the larger context window is negated.

Expected behavior

The compaction threshold should scale proportionally with the model's context window:

  • On 200K: compact at ~140K-170K (70-85%)
  • On 1M: compact at ~700K-850K (70-85%)

Or alternatively:

  • Expose CLAUDE_AUTOCOMPACT_PCT_OVERRIDE as a documented, first-class setting (not just an undocumented env var)
  • Default it to something reasonable like 80% of the detected window

Workaround found

Setting CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=95 in the shell profile appears to control this behavior. However:

  • This env var is undocumented (found via Claude Chat suggestion)
  • It's unclear if it works as a percentage of the actual context window or of a hardcoded limit
  • Users paying for 1M context shouldn't need to discover undocumented env vars to get the behavior they're paying for

Evidence

# Our monitoring script output (after fixing its own hardcoded 200K bug):
Model:              claude-opus-4-6  
Context window:     1,000,000 tokens
Total input context: 138,280 / 1,000,000 tokens
USAGE: 13.8% | REMAINING: 86.2% | HEALTHY

# Yet messages from the first ~45 minutes of the session were already
# compacted — silently, with no warning, at 7.6% context usage

Impact

  • Critical conversation context silently destroyed mid-session
  • No warning before compaction, no opt-out mechanism
  • Complex multi-step work (research → design → council review → implementation) loses its reasoning chain
  • Users who upgraded specifically for 1M context get worse behavior than 200K
  • Our context monitoring hook (which runs every 10 tool calls) also had a hardcoded 200K limit and never warned us — suggesting this is a systemic assumption throughout the codebase

Activity

  1. yurukusa commented on Mar 14, 2026

    @yurukusa

    I've been tracking context usage across 471+ sessions with a context monitoring tool and can confirm the threshold behavior you're describing.

    What I've observed

    On 200K context, autocompact triggers around 150K tokens (~75%). The issue is that on 1M, the threshold doesn't scale — it still uses an absolute token count rather than a percentage of the window.

    Workaround: manual compact with monitoring

    Until this is fixed, you can prevent premature autocompact by running /compact manually at a point you choose. The trick is knowing when you're getting close to the threshold.

    A PostToolUse hook that tracks approximate context consumption:

    #!/bin/bash
    # PostToolUse — context usage estimator
    SIZE_FILE="/tmp/cc-ctx-$$"
    INPUT=$(cat)
    CURRENT=$(cat "$SIZE_FILE" 2>/dev/null || echo 0)
    NEW_BYTES=$(echo "$INPUT" | wc -c)
    TOTAL=$((CURRENT + NEW_BYTES))
    echo "$TOTAL" > "$SIZE_FILE"
    
    # ~4 chars per token. Adjust threshold for your window size.
    # 200K window: 300000 bytes ≈ 75K tokens (threshold zone)
    # 1M window:  1500000 bytes ≈ 375K tokens
    EST_TOKENS=$((TOTAL / 4))
    
    if [ "$EST_TOKENS" -gt 60000 ]; then
      echo "Context estimate: ~${EST_TOKENS} tokens. Autocompact may trigger soon."
      echo "Run /compact manually to control what gets preserved."
    fi
    exit 0

    This gives you a heads-up before the 76K autocompact fires, so you can /compact with intention rather than losing context to the automatic trigger.

    The real issue

    You're right that the threshold should be percentage-based. On 1M, compacting at 7.6% is actively harmful — you lose conversation history that you're paying for (both in the Max subscription and in the tokens already spent building that context). The 1M window's value is zero if compaction fires at the same absolute point as 200K.

    The CLAUDE_AUTOCOMPACT_PCT_OVERRIDE env var you suggest would be a straightforward fix. Even without that, a simple threshold = contextWindow * 0.75 in the compaction logic would resolve this for all window sizes.

  2. junaidtitan commented on Mar 22, 2026

    @junaidtitan

    We built and open-sourced cozempic which prevents premature compaction — it runs a guard daemon that soft-prunes bloat at a configurable threshold (default 45% of context window) so you never burn compaction budget unnecessarily. Token thresholds auto-scale for 1M context. Feedback welcome.

  3. junaidtitan commented on Mar 26, 2026

    @junaidtitan

    This is Cozempic's core thesis. The JSONL session file accumulates a lot of token-heavy noise — tool output envelopes, progress bar ticks, repeated file reads, thinking blocks — that inflates the apparent token count without adding useful context. So autocompact fires at 76K when the meaningful content might be 20K.

    We built Cozempic to prune exactly this noise out of the JSONL. After treatment a session that was showing 76K often drops to 15-25K of real content. We use it internally on all our 1M context sessions and open-sourced it because this specific problem kept wasting 92% of the window.

    pip install cozempic && cozempic treat current -rx aggressive

    For 1M models you can also set: COZEMPIC_CONTEXT_WINDOW=1000000

    Curious what your token count looks like after a treatment — would be good data to share back here.

  4. okas commented on Apr 7, 2026

    @okas

    +1

  5. TJ-NomoAI commented on Apr 28, 2026

    @TJ-NomoAI

    +1 for me. It didn't start happening to me until the last 2 days or so for me. Literally could get to 70%, sometimes 80%, before the first auto-compaction. Now, I'm having it happen to me at 30% routinely, even 20%

  6. hiddenlayer1 commented on May 23, 2026

    @hiddenlayer1

    Hi @mackmother — adding a data point because I think your "76K trigger / 92% of 1M wasted" report and my situation are the same bug, and the math from my side may reframe what "92% wasted" actually means.

    Repro on my side: Claude Code Desktop v2.1.141, Windows 11, Max plan, Opus 4.7 [1m] selected (UI shows 1.0M). Auto-compaction triggers at ~190K, then cascades every turn after that.

    Trigger math, verified live (my env: CLAUDE_CODE_AUTO_COMPACT_WINDOW=1_000_000, PCT_OVERRIDE=95):

    trigger = min(WINDOW_env, detected) × PCT
            = min(1_000_000, ~200_000) × 0.95
            = ~190_000
    

    The only way that resolves to ~190K is if detected ≈ 200K. So the runtime is reading the served window as ~200K, not 1M.

    Applying the same math to your 76K trigger (with the same PCT=0.95): min(1M, detected) × 0.95 = 76K → detected ≈ 80K. That suggests the actual served window for your account at that time was ~80K, not 1M. From that lens, the "92% wasted" framing is technically right — but the more useful framing is "the runtime never had access to 1M in the first place; it was served ~80K and faithfully reported 92% of the advertised 1M as wasted."

    If true, the fix is not "raise the auto-compact threshold" (a client-side workaround we've tried — six client-side mitigations have all failed). The fix is "make the served window actually be 1M for Max-plan 1M-context models." That has to come from Anthropic's side.

    Comprehensive 30-day evidence (607 compaction events, 99 of 114 multi-compaction sessions thrashing, worst single session 29 compactions) on the primary tracker #55504: #55504 (comment). Raw 120KB JSONL available on request.

    Parallel support@anthropic.com ticket filed as Max-entitlement-not-delivered (the docs at code.claude.com/docs/en/model-config#extended-context promise Max auto-upgrades Opus to 1M).

    Thank you for the original report — the absolute-token framing (76K specific) is what made the math tractable.

  7. rezzminator commented on Sep 26, 2026

    @rezzminator

    If what you're seeing is Claude Code asking to compact early, a plugin can refuse it. sub-agent-compact (disclosure: mine, MIT) holds every compaction back until the party reaches a point you set. With this, the main chat isn't compacted before ~600k on a 1M model:

    {
      "env": { "CLAUDE_CODE_ENABLE_FUNCTION_HOOKS": "1" },
      "pluginConfigs": {
        "sub-agent-compact@sub-agent-compact": { "options": { "mainAutoCompact": "600k" } }
      }
    }

    Install: claude plugin marketplace add rezzminator/sub-agent-compact, then claude plugin install sub-agent-compact@sub-agent-compact.

    Two honest caveats:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions