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

Function getContextWindowForModel

src/utils/context.ts:51–98  ·  view source on GitHub ↗
(
  model: string,
  betas?: string[],
)

Source from the content-addressed store, hash-verified

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