[FEATURE] `get_context_usage` should report the auto-compact point that `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` sets

Status Open
Reported on v2.1.282
Maintainer reply None cached
Activity 1 comment · opened Sep 27, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

get_context_usage.autoCompactThreshold does not match the point where auto-compact actually runs once CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set. It returns the effective window minus the 13,000-token summary buffer, while the trigger uses min(floor(effective × pct / 100), effective − 13,000).

Measured on 2.1.282 in one process, no turn: with CLAUDE_CODE_AUTO_COMPACT_WINDOW=150000 and CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=30, get_context_usage reports autoCompactThreshold: 117000, while the same process's own autocompact_state frame reports {effective_window: 130000, threshold: 39000, enforced: true, source: "env"}. That frame is only emitted when CLAUDE_CODE_REMOTE is set, so an SDK client on a normal install cannot read it. 2.1.283 still reports 117000 for the same keys.

Proposed Solution

Make autoCompactThreshold return the same value the trigger uses (the value autocompact_state.threshold already carries), or emit autocompact_state in every SDK session.

Alternative Solutions

A client that sets the percentage today has to derive the point itself: two get_context_usage reads with CLAUDE_CODE_MAX_OUTPUT_TOKENS changed between them (via apply_flag_settings) to recover the reply reserve and the 13,000 buffer, then the formula above. That breaks the moment the buffer or the formula changes.

Priority

Medium - Would be very helpful

Feature Category

Developer tools/SDK

Additional Context

Related: #96467 asks for the effective window in the status line JSON; this is the same value on the SDK control request.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗