(model: string)
| 31 | |
| 32 | // Returns the context window size minus the max output tokens for the model |
| 33 | export function getEffectiveContextWindowSize(model: string): number { |
| 34 | const reservedTokensForSummary = Math.min( |
| 35 | getMaxOutputTokensForModel(model), |
| 36 | MAX_OUTPUT_TOKENS_FOR_SUMMARY, |
| 37 | ) |
| 38 | let contextWindow = getContextWindowForModel(model, getSdkBetas()) |
| 39 | |
| 40 | const autoCompactWindow = process.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW |
| 41 | if (autoCompactWindow) { |
| 42 | const parsed = parseInt(autoCompactWindow, 10) |
| 43 | if (!isNaN(parsed) && parsed > 0) { |
| 44 | contextWindow = Math.min(contextWindow, parsed) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return contextWindow - reservedTokensForSummary |
| 49 | } |
| 50 | |
| 51 | export type AutoCompactTrackingState = { |
| 52 | compacted: boolean |
no test coverage detected