MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / getContextWindowForModel

Function getContextWindowForModel

source code/utils/context.ts:53–100  ·  view source on GitHub ↗
(
  model: string,
  betas?: string[],
)

Source from the content-addressed store, hash-verified

51}
52
53export function getContextWindowForModel(
54 model: string,
55 betas?: string[],
56): number {
57 // Allow override via environment variable (ant-only)
58 // This takes precedence over all other context window resolution, including 1M detection,
59 // so users can cap the effective context window for local decisions (auto-compact, etc.)
60 // while still using a 1M-capable endpoint.
61 if (
62 process.env.USER_TYPE === 'ant' &&
63 process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS
64 ) {
65 const override = parseInt(process.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS, 10)
66 if (!isNaN(override) && override > 0) {
67 return override
68 }
69 }
70
71 // [1m] suffix — explicit client-side opt-in, respected over all detection
72 if (has1mContext(model)) {
73 return 1_000_000
74 }
75
76 const cap = getModelCapability(model)
77 if (cap?.max_input_tokens && cap.max_input_tokens >= 100_000) {
78 if (
79 cap.max_input_tokens > MODEL_CONTEXT_WINDOW_DEFAULT &&
80 is1mContextDisabled()
81 ) {
82 return MODEL_CONTEXT_WINDOW_DEFAULT
83 }
84 return cap.max_input_tokens
85 }
86
87 if (betas?.includes(CONTEXT_1M_BETA_HEADER) && modelSupports1M(model)) {
88 return 1_000_000
89 }
90 if (getSonnet1mExpTreatmentEnabled(model)) {
91 return 1_000_000
92 }
93 if (process.env.USER_TYPE === 'ant') {
94 const antModel = resolveAntModel(model)
95 if (antModel?.contextWindow) {
96 return antModel.contextWindow
97 }
98 }
99 return MODEL_CONTEXT_WINDOW_DEFAULT
100}
101
102export function getSonnet1mExpTreatmentEnabled(model: string): boolean {
103 if (is1mContextDisabled()) {

Callers 10

getStoredSessionCostsFunction · 0.85
addToTotalModelUsageFunction · 0.85
logSessionTelemetryFunction · 0.85
getContextUsedPercentFunction · 0.85
analyzeContextUsageFunction · 0.85

Calls 6

has1mContextFunction · 0.85
getModelCapabilityFunction · 0.85
is1mContextDisabledFunction · 0.85
modelSupports1MFunction · 0.85
resolveAntModelFunction · 0.85

Tested by

no test coverage detected