feat: replace hardcoded 80% usable context ratio with autocompact formula#319
Draft
Koriit wants to merge 1 commit intosirmalloc:mainfrom
Draft
feat: replace hardcoded 80% usable context ratio with autocompact formula#319Koriit wants to merge 1 commit intosirmalloc:mainfrom
Koriit wants to merge 1 commit intosirmalloc:mainfrom
Conversation
…mula Replace the flat 0.8 ratio used to estimate usable context tokens with Claude Code's actual autocompact threshold formula: effectiveWindow = contextWindow - 20,000 (reserved for summary output) threshold = effectiveWindow - 13,000 (buffer) This changes usable tokens from 160k to 167k (for 200k windows) and from 800k to 967k (for 1M windows), matching what Claude Code actually triggers autocompact at. Add support for CLAUDE_AUTOCOMPACT_PCT_OVERRIDE which allows users to lower the threshold via a percentage of the effective window. The value is resolved from the shell environment first, then Claude Code's settings.json env block, with invalid values silently ignored. - New src/utils/autocompact.ts resolver with env > settings.json cascade - computeUsableTokens() with Math.max(1, ...) floor guard for small windows - Updated CLAUDE.md documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
effectiveWindow - bufferTokensCLAUDE_AUTOCOMPACT_PCT_OVERRIDEresolved from shell env → Claude Codesettings.jsonenv block → nullTest plan
bun test)bun run lint)CLAUDE_AUTOCOMPACT_PCT_OVERRIDEset in environmentCLAUDE_AUTOCOMPACT_PCT_OVERRIDEset in~/.claude/settings.jsonenv block🤖 Generated with Claude Code