/context command ignores CLAUDE_AUTOCOMPACT_PCT_OVERRIDE when displaying buffer size
Bug Description
The /context command always displays the default autocompact buffer size (~33K tokens at 200K context), even when CLAUDE_AUTOCOMPACT_PCT_OVERRIDE is set. The env var correctly affects the actual autocompact trigger, but the display is wrong.
Environment
- Claude Code: v2.1.49
- Platform: macOS (Apple Silicon)
- Context window: 200K
Reproduction Steps
- Set
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70in settings or environment - Start a session
- Run
/context - Observe the "Autocompact buffer" shows ~33K (16.5%) — the default value
- Expected: should show ~74K (37%) reflecting the 70% override
Root Cause (from source analysis)
Two separate code paths calculate the autocompact threshold:
1. Actual trigger logic — CORRECT
The function that decides when to fire autocompact reads CLAUDE_AUTOCOMPACT_PCT_OVERRIDE and computes:
threshold = min(floor(effectiveWindow * PCT/100), effectiveWindow - 13000)
With PCT=70 and 200K context: min(floor(180,000 * 0.70), 167,000) = 126,000 tokens
2. /context display logic — BUG
The display function computes:
displayThreshold = effectiveWindow - 13000 // always uses default, ignores env var
buffer = maxContext - displayThreshold // = 33,000
This never calls the function that reads CLAUDE_AUTOCOMPACT_PCT_OVERRIDE. It hardcodes the default formula.
Impact
| Metric | /context shows | Actual behavior |
|---|---|---|
| Autocompact buffer | 33K (16.5%) | 74K (37%) |
| Trigger point | ~167K tokens | ~126K tokens |
| Free space | Inflated | Smaller than displayed |
Users relying on /context to judge remaining capacity will overestimate how much space they have before autocompact fires.
Suggested Fix
In the display function, replace the hardcoded default calculation with a call to the same threshold function used by the actual trigger logic, so both paths use the same formula that respects the env var override.
Related Issues
- #24828 — requests extending
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEto the main conversation (it may already work for the trigger; this issue is about the display) - #27037 — documents
CLAUDE_AUTOCOMPACT_PCT_OVERRIDEbehavior from reverse engineering
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗