Auto-compact stopped working for third-party API providers since v2.1.161

Status Open
Reported on v2.1.150
Maintainer reply None cached
Activity 8 comments · opened Jun 5, 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?

Auto-compact (automatic context compaction) stopped triggering for users of third-party Anthropic-compatible API providers (e.g., Zhipu AI, Azure Bedrock, Google Vertex, any ANTHROPIC_BASE_URL pointing to a non-Anthropic endpoint). Manual /compact still works fine.

This is a regression — auto-compact worked perfectly in v2.1.150 and earlier.

Regression Window

| Version | Auto-compact | Evidence |
|---------|-------------|----------|
| v2.1.117 (May 7-14) | ✅ Works | Triggers at ~167k tokens consistently |
| v2.1.140 (May 14-24) | ✅ Works | Triggers at ~153k tokens, many sessions verified |
| v2.1.150 (May 24 - Jun 3) | ✅ Works | Last working version |
| v2.1.161 (Jun 3) | ❌ Broken | 0 auto-compacts, all manual or hard-limit crashes |
| v2.1.162+ (Jun 4-5) | ❌ Broken | Same — zero auto-compacts |

Regression introduced between v2.1.150 and v2.1.161.

Root Cause Analysis

Through binary reverse-engineering of the Claude Code executable, I traced the complete call chain for auto-compact and identified the exact gate that changed.

v2.1.150 — Auto-compact gate (xU_):

// v2.1.150: feature flag resolver does NOT require Anthropic auth
function xU_() {
  if (!AT()) return false;                    // env/config check (passes)
  if (G28()) return false;                    // other check (passes)
  return V6("tengu_sepia_moth", false);       // feature flag → can resolve
}

// V6() → we() = !process.env.DISABLE_GROWTHBOOK && !OS()
// Does NOT check for Anthropic first-party authentication
// → GrowthBook is available, flag can be fetched/cached
// → tengu_sepia_moth resolves correctly → auto-compact works

v2.1.161+ — New auto-compact gate (_Y8):

// v2.1.161+: NEW auth gate added, blocks third-party users
function _Y8() {
  if (!AT()) return false;                    // env/config check (passes)
  if (!Os()) return false;                    // NEW: remote env check
  if (vl()) return false;                     // NEW: another feature flag check
  return D6("tengu_sepia_moth", false);       // feature flag → CANNOT resolve
}

// D6() → qu() → Au() → !LC() → !(dGL() || ...)
// dGL() = !Z7() where Z7() = (XA() === "firstParty")
// → Z7() returns false for third-party API users
// → dGL() returns true
// → LC() returns true
// → Au() returns false (GrowthBook "unavailable")
// → qu() returns false
// → D6("tengu_sepia_moth", false) returns the DEFAULT value: false
// → _Y8() returns false → Auto-compact NEVER triggers

The complete blocking chain for third-party API users:

ANTHROPIC_BASE_URL != api.anthropic.com
  → Z7() = false                    (not first-party auth)
    → dGL() = true                  (!Z7())
      → LC() = true                 (dGL() || ...)
        → Au() = false              (!LC())
          → qu() = false            (!DISABLE_GROWTHBOOK && Au())
            → D6("tengu_sepia_moth", false) returns false (default, GrowthBook unreachable)
              → _Y8() = false
                → SC_() = false     (auto-compact trigger check)
                  → Auto-compact NEVER fires ❌

Key functions extracted from v2.1.163 binary:

// Anthropic first-party auth check
function Z7() { return XA() === "firstParty"; }

// GrowthBook availability - now gated on Anthropic auth
function dGL() {
  if (eH(process.env.CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST)) return false;
  return !Z7();  // true when NOT first-party → blocks GrowthBook
}

// GrowthBook connectivity
function LC() { return dGL() || H3() !== null || wM6(); }
function Au() { return !LC(); }
function qu() { return !T6.DISABLE_GROWTHBOOK && Au(); }

// Feature flag resolver - returns default when GrowthBook unavailable
function D6(H, _) {
  let A = Hj6();              // local config override
  if (A && H in A) return A[H];
  let q = _j6();              // another config
  if (q && H in q) return q[H];
  if (!qu()) return _;        // ← BLOCKED HERE: returns default (false)
  // ... GrowthBook lookup (never reached)
}

// Auto-compact gate
function _Y8() {
  if (!AT()) return false;
  if (!Os()) return false;
  if (vl()) return false;
  return D6("tengu_sepia_moth", false);  // false = auto-compact disabled
}

// Should auto-compact trigger?
function SC_(H) {
  if (H.compactionResult !== undefined) return false;
  if (H.isPreFirstCompactFork) return false;
  if (H.consecutiveFailures !== undefined) return false;
  if (H.hasAttemptedReactiveCompact) return false;
  if (H.lastTransitionReason === "precomputed_compact_swap") return false;
  if (!_Y8()) return false;                                    // ← always false for 3rd party
  return ix9(H.contextTokens, H.model, H.autoCompactWindow);  // ← never reached
}

What Should Happen?

Auto-compact should trigger automatically when context grows past 85% of the model's context window, regardless of whether the user is authenticated with Anthropic directly or using a third-party API provider.

For third-party API users, auto-compact should work identically to how it worked in v2.1.150 and earlier — triggering at ~153k tokens for a 200k context window model.

Error Messages/Logs

## Evidence from Session Transcripts

Analyzed 500+ session transcripts. The `compact_boundary` system events with `compactMetadata` clearly show the regression:

### All sessions with auto-compact (chronological):


v2.1.117 (May 7-14):   auto=38, manual=12  ✅ Working
v2.1.140 (May 14-24):  auto=89, manual=18  ✅ Working
v2.1.150 (May 24-Jun 3): auto=55, manual=14  ✅ Working
v2.1.161 (Jun 3):      auto=0,  manual=3   ❌ BROKEN
v2.1.162 (Jun 4-5):    auto=0,  manual=1   ❌ BROKEN


### Example: 20MB session (v2.1.140, May 22-23) — auto-compact worked:
14 auto-compactions, all `trigger: "auto"`, each with full metadata:

{"trigger": "auto", "preTokens": 153018, "postTokens": 9231, "durationMs": 57363}
{"trigger": "auto", "preTokens": 153032, "postTokens": 9150, "durationMs": 45430}
// ... 12 more, all auto-triggered at ~153k tokens


### Example: Recent sessions (v2.1.162, June 4) — auto-compact broken:

Session 60faa9d3: auto=0, manual=2, hard_limit_hits=5
  → User had to manually /compact, or hit "ran out of context" emergency recovery

Session 4daf00de: auto=0, manual=1, hard_limit_hits=1
  → Same pattern


After upgrade to v2.1.161+: zero auto-compacts. Sessions grow until API returns an error, then emergency recovery kicks in.

Steps to Reproduce

  1. Configure Claude Code to use a third-party Anthropic-compatible API:

``json
// .claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic",
"ANTHROPIC_AUTH_TOKEN": "<third-party-token>",
"ANTHROPIC_MODEL": "glm-5.1"
}
}
``

  1. Start a Claude Code session and work long enough for context to grow past 85% of the model's context window
  2. Expected: Auto-compact triggers automatically, context is summarized
  3. Actual: Context grows until it hits the API's hard limit → emergency "ran out of context" crash recovery

Note: This reproduces with ANY third-party API provider, not just Zhipu AI. Azure Bedrock, Google Vertex, AWS Foundry, Mantle, and any custom ANTHROPIC_BASE_URL are all affected.

Claude Model

Other

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.150

Claude Code Version

2.1.163

Platform

Other

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Impact

This affects all users of third-party Anthropic-compatible API providers:

  • Zhipu AI (智谱, open.bigmodel.cn)
  • Azure Bedrock (via CLAUDE_CODE_USE_BEDROCK)
  • Google Vertex (via CLAUDE_CODE_USE_VERTEX)
  • AWS Foundry (via CLAUDE_CODE_USE_FOUNDRY)
  • Mantle (via CLAUDE_CODE_USE_MANTLE)
  • Any custom ANTHROPIC_BASE_URL

For these users, every long session will eventually crash with "ran out of context" instead of gracefully auto-compacting.

Workaround

Option 1: Downgrade to v2.1.150 (verified working)
Option 2: Manual /compact — remember to type /compact periodically during long sessions.

Environment Details

  • API provider: Zhipu AI (open.bigmodel.cn/api/anthropic)
  • Model: glm-5.1 (200k context window)
  • OS: macOS 12.7.6 (Monterey), x86_64
  • Relevant config:
  • CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=85
  • CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
  • ANTHROPIC_SMALL_FAST_MODEL=glm-5.1

Related Issues

  • #46416 — Context window detection fails for third-party providers (same class of issue)
  • #58383 — DISABLE_TELEMETRY silently disables GrowthBook, which also disables feature flags (same flag-defaults-to-false mechanism, different trigger)
  • #58284 — Agent View hard-disabled for third-party backends via first-party-auth gating (identical pattern, different feature)
  • #6012 — Auto-compact not triggering with AWS Bedrock backend (older report, same symptom)
  • #63197 — Compaction regression in v2.1.153 on Zhipu (likely same root cause, attributed to context window misreporting)

Suggested Fixes

  1. Remove the Z7() first-party check from the GrowthBook availability chain for core functionality flags like tengu_sepia_moth. GrowthBook should be accessible to all users regardless of authentication method.
  1. Change the default value of tengu_sepia_moth from false to true — auto-compact is a core feature that should be enabled by default, not a premium feature locked behind Anthropic auth.
  1. Add a CLAUDE_CODE_ENABLE_AUTO_COMPACT environment variable override that bypasses the feature flag entirely, giving third-party users explicit control:

``js
function _Y8() {
if (eH(process.env.CLAUDE_CODE_ENABLE_AUTO_COMPACT)) return true; // explicit override
if (!AT()) return false;
if (!Os()) return false;
if (vl()) return false;
return D6("tengu_sepia_moth", true); // default true instead of false
}
``

Any of these would fix the regression. Option 2 is the simplest and safest.

View original on GitHub ↗

8 Comments

junaidtitan · 2 months ago

Nice binary-level detective work tracing the GrowthBook gate regression — the v2.1.150 vs v2.1.161 diff makes it very clear what changed.

While this is something Anthropic needs to fix at the source, we've been using cozempic (github.com/Ruya-AI/cozempic) as a full workaround in the interim. It's a standalone JSONL pruner that operates completely outside CC's auto-compact mechanism — no GrowthBook, no feature flags, no auth gating. cozempic guard runs as a watchdog alongside your session and prunes the .jsonl at configurable thresholds, then resumes the session cleanly. Third-party API or not, it doesn't care.

pip install cozempic / pipx install cozempic — it auto-runs. cozempic current --diagnose will show your real context footprint, and cozempic treat current does a dry-run prune so you can see what it would reclaim before committing.

Curious if it helps bridge the gap for third-party setups until the regression is fixed — feedback welcome.

veZuk · 2 months ago

Can confirm this regression. Auto-compact stopped triggering after v2.1.150 — same behaviour as described: it simply never fires, while manual /compact works as expected. Still present on v2.1.168.

This is a core feature for any long-running session. Without it, you either have to remember to run /compact manually or risk hitting the hard context limit and losing the entire session.

Fully support the proposed fixes — especially changing the tengu_sepia_moth default to true. Auto-compact is essential enough that it should be enabled by default, regardless of how the client is configured.

Excellent root cause analysis, by the way. The binary-level tracing is impressive and should really help the team narrow this down quickly.

indradeep · 2 months ago

Amazing work @deity-z 👏

I can also confirm the same behavior. The work-around that I have found is to pin claude code to 2.1.150:

npm install -g @anthropic-ai/claude-code@2.1.150

To prevent auto-update to the future broken versions, you need to add the following to the env section of the ~/.claude/settings.json:

"DISABLE_AUTOUPDATER": "1"

Hope this helps!

taicilang-lcy · 2 months ago

Likely Fixed in v2.1.177

Based on my observation during a session today, auto-compact appears to be working with third-party API provider in v2.1.177.

Setup:

  • Version: v2.1.177 (Claude Code)
  • API: Tencent Cloud Coding Plan (ANTHROPIC_BASE_URL=https://api.lkeap.cloud.tencent.com/coding/anthropic)
  • Model: glm-5

Observation:
During a long session, the context was automatically compressed (I received a summary at the start of the continued session). I did NOT manually execute /compact command before this happened.

This suggests that the auto-compact feature, which was broken for third-party APIs since v2.1.161, may have been fixed in v2.1.177.

Note: I haven't repeatedly tested this behavior multiple times, so I can't 100% confirm it's fixed. But based on this single observation, it looks promising.

Would appreciate if others can also verify or if the team can confirm the fix.

Suaig · 2 months ago

Could I consider this as Anthropic intentionally restricting users from using third-party models?

wuruofan · 2 months ago

+1 from a MiniMax (minimax) user.

Hit this exact regression on v2.1.186 with MiniMax-M3 (advertised as 1M context):

  • ANTHROPIC_BASE_URL=https://api.minimaxi.com/anthropic (third-party provider)
  • CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set but ignored
  • Long session → conversation grew to ~2.4M input tokens on a single request
  • Account quota was exceeded, session was cut off

Confirmed the workaround — pinning to v2.1.150 + DISABLE_AUTOUPDATER=1 is the plan.

wuruofan · 2 months ago

Adding more evidence from reverse-engineering the v2.1.159 binary.

I ran strings on the 2.1.159 executable and found:

What EXISTS in 2.1.159:

  • "Autocompact buffer" — the auto-compact feature itself is present
  • Full GrowthBook system ("isGrowthBookEnabled", "initializeGrowthBook", "refreshGrowthBookFeatures", etc.)
  • First/third-party auth distinction ("isLegacyOpusFirstParty", "firstPartyNameToCanonical", "preferThirdPartyAuthentication", "logGrowthBookExperimentTo1P")

What DOES NOT EXIST in 2.1.159:

  • "tengu_sepia_moth" — this feature flag is completely absent

The binary contains many other "tengu_*" flags (e.g. "tengu_velvet_moth", "tengu_dunwich_bell"), but "tengu_sepia_moth" is nowhere to be found.

This suggests that in 2.1.159, auto-compact was NOT controlled by the "tengu_sepia_moth" feature flag. It likely triggered directly based on token count without going through GrowthBook flag resolution.

The regression introduced in 2.1.161 appears to be the migration of auto-compact into the "tengu_sepia_moth" feature flag system, which is gated on first-party authentication. This would explain why third-party API users lost auto-compact starting exactly at 2.1.161.

cc @deity-z

Ishannaik · 1 month ago

Still broken on v2.1.220 (current latest), and worth flagging the cost side because it turns a quality-of-life bug into a billing one.

Setup: ANTHROPIC_BASE_URL pointed at Alibaba Bailian (Anthropic-compatible), model qwen3.8-max-preview, subscription-free API key. Auto-compact never fires. CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set and ignored, matching the earlier reports here. Sessions run to 100% context and then hit the "autocompact is thrashing" safety stop, which is now the only thing preventing an unbounded request.

I confirmed the root cause locally on 2.1.220: ~/.claude.json caches 441 GrowthBook flags and tengu_sepia_moth is false. Setting it to true by hand and restarting reverts it to false on the next launch, because third-party auth cannot resolve the flag and it falls back to the default. There is no supported override: featureFlagOverrides, growthbookOverrides, forceFeatureFlags, and statsigOverrides all have zero occurrences in the binary.

Why this matters more than it looks: on a prepaid third-party plan there is no per-request spend cap. A single un-compacted request growing to seven figures of input tokens (the ~2.4M MiniMax report above) drains a plan in one shot. Manual /compact still works, so the feature itself is intact; only the automatic trigger is gated.

The two fixes proposed earlier both look right: drop the first-party auth check from the flag-resolution path for core-functionality flags, or default tengu_sepia_moth to true. Either restores auto-compact as a core feature rather than a first-party-only one.

@bcherny @ThariqS could this get a look? It is a small gate with an outsized failure mode for anyone on a metered non-Anthropic endpoint.