(model: string)
| 34 | // Managed models use separate input/output token budgets, so no output reserve |
| 35 | // is subtracted from the prompt budget. |
| 36 | export function getEffectiveContextWindowSize(model: string): number { |
| 37 | let contextWindow = getContextWindowForModel(model, getSdkBetas()) |
| 38 | |
| 39 | const autoCompactWindow = process.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW |
| 40 | if (autoCompactWindow) { |
| 41 | const parsed = parseInt(autoCompactWindow, 10) |
| 42 | if (!isNaN(parsed) && parsed > 0) { |
| 43 | contextWindow = Math.min(contextWindow, parsed) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (resolveNCodeManagedModel(model) !== undefined) { |
| 48 | return contextWindow |
| 49 | } |
| 50 | |
| 51 | const reservedTokensForSummary = Math.min( |
| 52 | getMaxOutputTokensForModel(model), |
| 53 | MAX_OUTPUT_TOKENS_FOR_SUMMARY, |
| 54 | ) |
| 55 | |
| 56 | return contextWindow - reservedTokensForSummary |
| 57 | } |
| 58 | |
| 59 | export type AutoCompactTrackingState = { |
| 60 | compacted: boolean |
no test coverage detected