claude-code - 💡(How to fix) Fix Auto-compact stopped working for third-party API providers since v2.1.161

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…

Error Message

Error Messages/Logs

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

Root Cause

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.

Fix Action

Workaround

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

Code Example

// 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 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

---

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 ❌

---

// 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
}

---

## 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=12Working
v2.1.140 (May 14-24):  auto=89, manual=18Working
v2.1.150 (May 24-Jun 3): auto=55, manual=14Working
v2.1.161 (Jun 3):      auto=0,  manual=3BROKEN
v2.1.162 (Jun 4-5):    auto=0,  manual=1BROKEN


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

---

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

---

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
   }
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

VersionAuto-compactEvidence
v2.1.117 (May 7-14)✅ WorksTriggers at ~167k tokens consistently
v2.1.140 (May 14-24)✅ WorksTriggers at ~153k tokens, many sessions verified
v2.1.150 (May 24 - Jun 3)✅ WorksLast working version
v2.1.161 (Jun 3)Broken0 auto-compacts, all manual or hard-limit crashes
v2.1.162+ (Jun 4-5)BrokenSame — 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:
    // .claude/settings.json
    {
      "env": {
        "ANTHROPIC_BASE_URL": "https://open.bigmodel.cn/api/anthropic",
        "ANTHROPIC_AUTH_TOKEN": "<third-party-token>",
        "ANTHROPIC_MODEL": "glm-5.1"
      }
    }
  2. Start a Claude Code session and work long enough for context to grow past 85% of the model's context window
  3. Expected: Auto-compact triggers automatically, context is summarized
  4. 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.

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

  3. Add a CLAUDE_CODE_ENABLE_AUTO_COMPACT environment variable override that bypasses the feature flag entirely, giving third-party users explicit control:

    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.

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