From 903bc10fea11694474f772356f301b8e4b37298e Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Fri, 19 Dec 2025 02:40:29 -0500 Subject: [PATCH] fix(profiles): prevent env var inheritance for settings-based profiles - Load settings file and explicitly inject ANTHROPIC_* env vars - Prevents stale CLIProxy env vars from overriding settings file values - Fixes GLM/Kimi requests incorrectly routing through CLIProxyAPI --- src/ccs.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ccs.ts b/src/ccs.ts index d5c3cc68..894defab 100644 --- a/src/ccs.ts +++ b/src/ccs.ts @@ -2,7 +2,7 @@ import { spawn, ChildProcess } from 'child_process'; import * as path from 'path'; import * as fs from 'fs'; import { detectClaudeCli } from './utils/claude-detector'; -import { getSettingsPath } from './utils/config-manager'; +import { getSettingsPath, loadSettings } from './utils/config-manager'; import { ErrorManager } from './utils/error-manager'; import { execClaudeWithCLIProxy, CLIProxyProvider } from './cliproxy'; import { @@ -498,8 +498,17 @@ async function main(): Promise { // Get global env vars (DISABLE_TELEMETRY, etc.) for third-party profiles const globalEnvConfig = getGlobalEnvConfig(); const globalEnv = globalEnvConfig.enabled ? globalEnvConfig.env : {}; + + // CRITICAL: Load settings and explicitly set ANTHROPIC_* env vars + // to prevent inheriting stale values from previous CLIProxy sessions. + // Environment variables take precedence over --settings file values, + // so we must explicitly set them here to ensure correct routing. + const settings = loadSettings(expandedSettingsPath); + const settingsEnv = settings.env || {}; + const envVars: NodeJS.ProcessEnv = { ...globalEnv, + ...settingsEnv, // Explicitly inject all settings env vars ...webSearchEnv, CCS_PROFILE_TYPE: 'settings', // Signal to WebSearch hook this is a third-party provider };