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

Function getAutoCompactThreshold

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

Source from the content-addressed store, hash-verified

70const MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES = 3
71
72export function getAutoCompactThreshold(model: string): number {
73 const effectiveContextWindow = getEffectiveContextWindowSize(model)
74
75 const autocompactThreshold =
76 effectiveContextWindow - AUTOCOMPACT_BUFFER_TOKENS
77
78 // Override for easier testing of autocompact
79 const envPercent = process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
80 if (envPercent) {
81 const parsed = parseFloat(envPercent)
82 if (!isNaN(parsed) && parsed > 0 && parsed <= 100) {
83 const percentageThreshold = Math.floor(
84 effectiveContextWindow * (parsed / 100),
85 )
86 return Math.min(percentageThreshold, autocompactThreshold)
87 }
88 }
89
90 return autocompactThreshold
91}
92
93export function calculateTokenWarningState(
94 tokenUsage: number,

Callers 4

runInProcessTeammateFunction · 0.85
shouldAutoCompactFunction · 0.85
autoCompactIfNeededFunction · 0.85

Calls 1

Tested by

no test coverage detected