claude-code - 💡(How to fix) Fix CLAUDE_AUTOCOMPACT_PCT_OVERRIDE not honored on Opus 4.7 (1M) — auto-compact fires at ~195k preTokens regardless of override value [1 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#53801Fetched 2026-04-28 06:46:59
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×4commented ×1cross-referenced ×1subscribed ×1

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set to "40" in ~/.claude/settings.json (under the env block), expecting auto-compact to fire at 40% of the model's context (= 400,000 tokens for the 1M Opus 4.7 context). In practice, every auto-compaction fires within an extremely tight ~2.5k token band centered on ~195k preTokens, which equals 19.5% of 1M — half the configured threshold. This matches a 200k-internal-limit hardcoding rather than the model's actual capacity.

This is a clean reproduction adding evidence to existing issues #36381 and #52519. Possibly a regression of, or an incomplete fix for, those.

Root Cause

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set to "40" in ~/.claude/settings.json (under the env block), expecting auto-compact to fire at 40% of the model's context (= 400,000 tokens for the 1M Opus 4.7 context). In practice, every auto-compaction fires within an extremely tight ~2.5k token band centered on ~195k preTokens, which equals 19.5% of 1M — half the configured threshold. This matches a 200k-internal-limit hardcoding rather than the model's actual capacity.

This is a clean reproduction adding evidence to existing issues #36381 and #52519. Possibly a regression of, or an incomplete fix for, those.

RAW_BUFFERClick to expand / collapse

Summary

CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set to "40" in ~/.claude/settings.json (under the env block), expecting auto-compact to fire at 40% of the model's context (= 400,000 tokens for the 1M Opus 4.7 context). In practice, every auto-compaction fires within an extremely tight ~2.5k token band centered on ~195k preTokens, which equals 19.5% of 1M — half the configured threshold. This matches a 200k-internal-limit hardcoding rather than the model's actual capacity.

This is a clean reproduction adding evidence to existing issues #36381 and #52519. Possibly a regression of, or an incomplete fix for, those.

Environment

  • Claude Code version: 2.1.120 (this is past v2.1.117 referenced in #52519 as the "Opus 4.7 auto-compact threshold change" fix)
  • Model: Opus 4.7 (1M context) — model ID claude-opus-4-7[1m]
  • OS: Windows 11 Home, MSYS2 Git Bash
  • Setting: ~/.claude/settings.jsonenv.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: "40" (verified exported into session via echo $CLAUDE_AUTOCOMPACT_PCT_OVERRIDE returning 40)

Observed: 6 consecutive auto-compactions in one session

Extracted from ~/.claude/projects/<project>/<sessionId>.jsonl by parsing compact_boundary records' compactMetadata:

Timestamp (UTC)TriggerpreTokenspostTokens% of 1M used
2026-04-27T01:33:48.851Zauto196,51232,76119.65%
2026-04-27T02:59:51.495Zmanual192,53531,11619.25%
2026-04-27T03:41:16.640Zauto194,36030,26319.44%
2026-04-27T04:16:00.021Zauto194,15932,74319.42%
2026-04-27T06:34:07.657Zauto195,85432,58819.59%
2026-04-27T06:58:30.364Zauto194,59132,86619.46%

Tightness of the band (preTokens range = 4,353 tokens, ~2.2% spread) tells us the trigger threshold is deterministic — Claude Code IS computing a fixed threshold; it's just not the one configured. The override either isn't being read for this code path, or is being applied against a 200k base (~195k / 200k = ~97.5% used, which lines up with the historical default ~95-98% trigger).

Expected

With CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=40 and a 1M-context model, auto-compact should NOT fire until preTokens ≥ ~400,000 (40% of 1M).

Actual

Auto-compact fires at preTokens ≈ 195,000 — half the configured threshold when interpreted against the model's actual 1M capacity, OR equivalent to the hardcoded ~95% default behavior when interpreted against an internal 200k limit.

Reproduction steps

  1. Run Claude Code 2.1.120 with model claude-opus-4-7[1m].
  2. Set ~/.claude/settings.jsonenv.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: "40".
  3. Verify the env var is exported in-session: echo $CLAUDE_AUTOCOMPACT_PCT_OVERRIDE40.
  4. Have a long-running session (heavy tool use, large file reads).
  5. Observe the JSONL transcript at ~/.claude/projects/<project>/<sessionId>.jsonl — every compact_boundary event with trigger: "auto" will have preTokens in the 190,000–200,000 range, regardless of the override value.

User-visible consequence

On 1M-context models, the user sees the context-usage indicator at ~19% used and is surprised when auto-compact fires. The override they configured to extend useful context is silently ignored. Sessions that should run for hours of work with 1M context cap out and compact at 19% used — effectively rendering 80% of the 1M model's capacity unreachable via auto-compact.

Cross-references

  • #36381 — CLAUDE_AUTOCOMPACT_PCT_OVERRIDE not triggering
  • #52519 — Opus 4.7 Auto-Compact Threshold Change (referenced as "fixed in v2.1.117", but reproduction here on v2.1.120 still shows the 200k-base behavior)

Happy to provide additional JSONL excerpts or session metadata on request.

extent analysis

TL;DR

The issue can be temporarily worked around by manually adjusting the auto-compact threshold or waiting for a fix that correctly applies the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE setting.

Guidance

  • Verify that the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE setting is correctly exported and applied in the session by checking the environment variable and the Claude Code configuration.
  • Check the Claude Code version and ensure it is up-to-date, as the issue may have been fixed in a later version.
  • Consider manually adjusting the auto-compact threshold to a higher value to avoid premature compaction, although this may not be a scalable solution.
  • Review the cross-referenced issues (#36381 and #52519) for any updates or workarounds that may apply to this scenario.

Example

No code snippet is provided as the issue is related to configuration and environment variables.

Notes

The issue appears to be related to a hardcoded internal limit of 200k tokens, which is not being overridden by the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE setting. The root cause is likely a regression or incomplete fix in the Claude Code.

Recommendation

Apply a workaround by manually adjusting the auto-compact threshold or waiting for a fix that correctly applies the CLAUDE_AUTOCOMPACT_PCT_OVERRIDE setting, as upgrading to a fixed version is not currently an option.

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