mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-05 00:18:05 +00:00
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:
+10
-1
@@ -2,7 +2,7 @@ import { spawn, ChildProcess } from 'child_process';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { detectClaudeCli } from './utils/claude-detector';
|
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 { ErrorManager } from './utils/error-manager';
|
||||||
import { execClaudeWithCLIProxy, CLIProxyProvider } from './cliproxy';
|
import { execClaudeWithCLIProxy, CLIProxyProvider } from './cliproxy';
|
||||||
import {
|
import {
|
||||||
@@ -498,8 +498,17 @@ async function main(): Promise<void> {
|
|||||||
// Get global env vars (DISABLE_TELEMETRY, etc.) for third-party profiles
|
// Get global env vars (DISABLE_TELEMETRY, etc.) for third-party profiles
|
||||||
const globalEnvConfig = getGlobalEnvConfig();
|
const globalEnvConfig = getGlobalEnvConfig();
|
||||||
const globalEnv = globalEnvConfig.enabled ? globalEnvConfig.env : {};
|
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 = {
|
const envVars: NodeJS.ProcessEnv = {
|
||||||
...globalEnv,
|
...globalEnv,
|
||||||
|
...settingsEnv, // Explicitly inject all settings env vars
|
||||||
...webSearchEnv,
|
...webSearchEnv,
|
||||||
CCS_PROFILE_TYPE: 'settings', // Signal to WebSearch hook this is a third-party provider
|
CCS_PROFILE_TYPE: 'settings', // Signal to WebSearch hook this is a third-party provider
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user