[BUG] Autocompact buffer (232.9k) exceeds 200k context window (116.5%) on Max plan — instant compaction loop after upgrading from 2.1.74

Status Fixed / completed
Reported on v2.1.76
Maintainer reply None cached
Activity 4 comments · opened Mar 14, 2026 · closed Mar 17, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Description

After upgrading from v2.1.74 to v2.1.76, Claude Code enters an infinite compaction loop immediately on session start. The session becomes completely unusable — "context limit reached" appears before any user input.

## Root Cause

Running /status on 2.1.76 reveals the problem:

  • Context window: 200k tokens
  • Autocompact buffer: 232.9k tokens (116.5%)

The autocompact buffer is larger than the entire context window. It appears the buffer is calculated for a 1M window (~23% of 1M = 232.9k) but applied against a 200k window. This leaves zero usable space, triggering immediate and infinite compaction.

## Screenshot

[attach the screenshot here]

## Environment

  • Plan: Max ($100/mo)
  • Working version: 2.1.74 (200k window, no issue)
  • Broken version: 2.1.76
  • Model: claude-opus-4-6
  • Platform: macOS (Darwin 25.2.0, arm64)
  • Setup: Multiple plugins enabled, 2 MCP servers, custom skills

## Workaround

Downgrade to 2.1.74:
```bash
ln -sf ~/.local/share/claude/versions/2.1.74 ~/.local/bin/claude

Notes

  • CLAUDE_CODE_DISABLE_1M_CONTEXT=1 env variable did NOT fix the issue
  • autoUpdates is set to false in settings
  • The bug appears related to the 1M context feature added in 2.1.75 for Max plans — the buffer calculation seems to assume 1M even when the window is 200k

<img width="638" height="353" alt="Image" src="https://github.com/user-attachments/assets/e28fdfd4-d202-46c3-92e0-4b53588f1f5e" />

What Should Happen?

Of course, it should not behave like this, feels like a virus

Autocompact buffer should be sized relative to the actual context window (200k), not the 1M window.

Error Messages/Logs

Steps to Reproduce

  1. Be on Max $100/mo plan
  2. Have a working setup on v2.1.74
  3. Upgrade to v2.1.76
  4. Start a new session
  5. Immediately hits "context limit reached" and enters compaction loop

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.74

Claude Code Version

2.1.76

Platform

Other

Operating System

macOS

Terminal/Shell

Warp

Additional Information

_No response_

View original on GitHub ↗

4 Comments

yurukusa · 7 months ago

Your diagnosis looks correct — the buffer is calculated for 1M but applied against 200k.

A few additional things to try beyond the 2.1.74 downgrade:

1. Check for stale config

The 1M context feature may have persisted a setting that 2.1.74 ignores:

# Check if there's a contextWindow or autocompact config
cat ~/.claude/settings.json | grep -i "context\|compact\|buffer"
cat ~/.claude/projects/*/settings.json | grep -i "context\|compact\|buffer" 2>/dev/null

If you see anything context-related, try removing it and restarting.

2. Try a fresh session

If settings look clean, the buffer calculation might be cached in the session state:

# Start a completely fresh session (no resume)
claude --no-resume

Then immediately run /status to see if the buffer is still miscalculated.

3. Model-specific test

Since the 1M context is tied to Opus, try starting with a different model to confirm it's model-specific:

claude --model sonnet

If Sonnet works normally on 2.1.76, it confirms the buffer calc is leaking from the 1M Opus path into sessions that should use 200k.

4. The CLAUDE_CODE_DISABLE_1M_CONTEXT=1 failure

The fact that this env var didn't fix it suggests the buffer is calculated before the flag is checked, or the flag only affects context window display but not the autocompact threshold calculation. Worth mentioning this specifically in the bug report — it narrows down where in the code the miscalculation happens.

azizabbas · 7 months ago

Thanks for your reply @yurukusa but unfortunately nothing works:

  1. No context, compact, or buffer settings found in any config file. The only matches are the statusLine display command and a plugin name (context7). No persisted 1M or autocompact configuration exists.
  1. claude --no-resume doesn't exist (unknown option), and starting a fresh session on 2.1.76 still produces the same 232.9k/200k autocompact buffer (116.5%) immediately.
  1. Same issue with Sonnet
azizabbas · 7 months ago

I manage to resolve this issue, no further action required from Anthropic

Root Cause Found

After 3 days of debugging, the issue was caused by two environment variables that Claude Code itself added to my ~/.zshrc:

export CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=90
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=90

These were injected by Claude Code during a session (I did not add them manually). After the v2.1.76 upgrade, these values conflict with the new 1M context window calculations, causing the autocompact buffer (232.9k) to exceed the 200k window — triggering an infinite compaction loop on every session start.

Fix

Remove both lines from ~/.zshrc (or wherever your shell config lives), quit Terminal completely, and reopen.

Recommendation to Anthropic

  1. Claude Code should never write environment variables into user shell configs without explicit user consent and clear warnings
  2. These undocumented env vars should be validated against the actual context window size on startup
  3. If invalid values are detected, Claude Code should warn the user instead of entering an infinite loop

I install claude on Windows PC and another Macbook I have and only then I manage to figure out that this is local issue and found it eventually.

github-actions[bot] · 6 months ago

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.