CLAUDE_AUTOCOMPACT_PCT_OVERRIDE not honored on Opus 4.7 (1M) — auto-compact fires at ~195k preTokens regardless of override value

Resolved 💬 3 comments Opened Apr 27, 2026 by ziyilam3999 Closed Apr 30, 2026

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) | Trigger | preTokens | postTokens | % of 1M used |
|-------------------------|---------|-----------|------------|--------------|
| 2026-04-27T01:33:48.851Z | auto | 196,512 | 32,761 | 19.65% |
| 2026-04-27T02:59:51.495Z | manual | 192,535 | 31,116 | 19.25% |
| 2026-04-27T03:41:16.640Z | auto | 194,360 | 30,263 | 19.44% |
| 2026-04-27T04:16:00.021Z | auto | 194,159 | 32,743 | 19.42% |
| 2026-04-27T06:34:07.657Z | auto | 195,854 | 32,588 | 19.59% |
| 2026-04-27T06:58:30.364Z | auto | 194,591 | 32,866 | 19.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.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗