MCPcopy Index your code
hub / github.com/codeaashu/claude-code / handleModelChange

Function handleModelChange

src/commands/model/model.tsx:143–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141 const model = args === 'default' ? null : args;
142 React.useEffect(() => {
143 async function handleModelChange(): Promise<void> {
144 if (model && !isModelAllowed(model)) {
145 onDone(`Model '${model}' is not available. Your organization restricts model selection.`, {
146 display: 'system'
147 });
148 return;
149 }
150
151 // @[MODEL LAUNCH]: Update check for 1M access.
152 if (model && isOpus1mUnavailable(model)) {
153 onDone(`Opus 4.6 with 1M context is not available for your account. Learn more: https://code.claude.com/docs/en/model-config#extended-context-with-1m`, {
154 display: 'system'
155 });
156 return;
157 }
158 if (model && isSonnet1mUnavailable(model)) {
159 onDone(`Sonnet 4.6 with 1M context is not available for your account. Learn more: https://code.claude.com/docs/en/model-config#extended-context-with-1m`, {
160 display: 'system'
161 });
162 return;
163 }
164
165 // Skip validation for default model
166 if (!model) {
167 setModel(null);
168 return;
169 }
170
171 // Skip validation for known aliases - they're predefined and should work
172 if (isKnownAlias(model)) {
173 setModel(model);
174 return;
175 }
176
177 // Validate and set custom model
178 try {
179 // Don't use parseUserSpecifiedModel for non-aliases since it lowercases the input
180 // and model names are case-sensitive
181 const {
182 valid,
183 error: error_0
184 } = await validateModel(model);
185 if (valid) {
186 setModel(model);
187 } else {
188 onDone(error_0 || `Model '${model}' not found`, {
189 display: 'system'
190 });
191 }
192 } catch (error) {
193 onDone(`Failed to validate model: ${(error as Error).message}`, {
194 display: 'system'
195 });
196 }
197 }
198 function setModel(modelValue: string | null): void {
199 setAppState(prev => ({
200 ...prev,

Callers 1

SetModelAndCloseFunction · 0.85

Calls 7

isModelAllowedFunction · 0.85
isOpus1mUnavailableFunction · 0.85
isSonnet1mUnavailableFunction · 0.85
setModelFunction · 0.85
isKnownAliasFunction · 0.85
validateModelFunction · 0.85
onDoneFunction · 0.50

Tested by

no test coverage detected