MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / getContextWindowForModel

Function getContextWindowForModel

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

Source from the content-addressed store, hash-verified

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

Callers 11

getStoredSessionCostsFunction · 0.85
addToTotalModelUsageFunction · 0.85
logSessionTelemetryFunction · 0.85
StatusLineInnerFunction · 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