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
This commit is contained in:
kaitranntt
2025-12-19 02:40:29 -05:00
parent eaa7d0f526
commit 903bc10fea
+10 -1
View File
@@ -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<void> {
// 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
};