From 7f369f75dce8dbb1d5dde9b63c51219e46614533 Mon Sep 17 00:00:00 2001 From: Kenneth Wong Date: Fri, 10 Jul 2026 00:39:19 +0800 Subject: [PATCH] fix: claude model no get the 1m tag --- .../config/extended-context-config.ts | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/cliproxy/config/extended-context-config.ts b/src/cliproxy/config/extended-context-config.ts index 7c63c68c..1b55b784 100644 --- a/src/cliproxy/config/extended-context-config.ts +++ b/src/cliproxy/config/extended-context-config.ts @@ -13,9 +13,12 @@ import type { CLIProxyProvider } from '../types'; import { supportsExtendedContext } from '../model-catalog'; import { warn } from '../../utils/ui'; import { + ANTHROPIC_MODEL_ENV_KEYS, applyExtendedContextPreferenceToAnthropicModels, applyExtendedContextSuffix as applyExtendedContextSuffixShared, + hasExtendedContextSuffix, isNativeGeminiModel, + stripExtendedContextSuffix, stripModelConfigurationSuffixes, } from '../../shared/extended-context-utils'; @@ -73,20 +76,41 @@ export function applyExtendedContextConfig( provider: CLIProxyProvider, extendedContextOverride?: boolean ): void { - if (extendedContextOverride === false) { - Object.assign(envVars, applyExtendedContextPreferenceToAnthropicModels(envVars, false)); + if (extendedContextOverride === true || extendedContextOverride === false) { + Object.assign( + envVars, + applyExtendedContextPreferenceToAnthropicModels(envVars, extendedContextOverride, { + supportsExtendedContext: (modelId) => + shouldApplyExtendedContext( + provider, + stripModelConfigurationSuffixes(modelId), + extendedContextOverride + ), + }) + ); return; } - Object.assign( - envVars, - applyExtendedContextPreferenceToAnthropicModels(envVars, true, { - supportsExtendedContext: (modelId) => - shouldApplyExtendedContext( - provider, - stripModelConfigurationSuffixes(modelId), - extendedContextOverride - ), - }) - ); + // Auto mode (no explicit --1m/--no-1m this launch): don't force-strip a + // previously saved [1m] preference just because the model is Claude — only + // strip when the model no longer supports extended context. Native Gemini + // models still get auto-toggled based on catalog support. + for (const key of ANTHROPIC_MODEL_ENV_KEYS) { + const value = envVars[key]; + if (typeof value !== 'string' || value.trim().length === 0) { + continue; + } + const modelId = stripModelConfigurationSuffixes(value); + + if (isNativeGeminiModel(modelId)) { + envVars[key] = supportsExtendedContext(provider, modelId) + ? applyExtendedContextSuffixShared(value) + : value; + continue; + } + + if (hasExtendedContextSuffix(value) && !supportsExtendedContext(provider, modelId)) { + envVars[key] = stripExtendedContextSuffix(value); + } + } }