MCPcopy
hub / github.com/claude-code-best/claude-code / getAutoCompactThreshold

Function getAutoCompactThreshold

src/services/compact/autoCompact.ts:101–120  ·  view source on GitHub ↗
(model: string)

Source from the content-addressed store, hash-verified

99const MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3
100
101export function getAutoCompactThreshold(model: string): number {
102 const effectiveContextWindow = getEffectiveContextWindowSize(model)
103
104 const autocompactThreshold =
105 effectiveContextWindow - getAutocompactBufferTokens(model)
106
107 // Override for easier testing of autocompact
108 const envPercent = process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
109 if (envPercent) {
110 const parsed = parseFloat(envPercent)
111 if (!isNaN(parsed) && parsed > 0 && parsed <= 100) {
112 const percentageThreshold = Math.floor(
113 effectiveContextWindow * (parsed / 100),
114 )
115 return Math.min(percentageThreshold, autocompactThreshold)
116 }
117 }
118
119 return autocompactThreshold
120}
121
122export function calculateTokenWarningState(
123 tokenUsage: number,

Callers 4

runInProcessTeammateFunction · 0.85
shouldAutoCompactFunction · 0.85
autoCompactIfNeededFunction · 0.85

Calls 2

Tested by

no test coverage detected