Page summary

Troubleshoot routing or login issues caused by environment variable conflicts.

5.4 Environment Variable Conflicts

Overview

CC Switch automatically detects conflicts between system environment variables and app configurations, preventing configurations from being unexpectedly overridden.

Detected environment variables:

AppDetection ScopeCommon Variables
Claude CodeVariables starting with ANTHROPICANTHROPIC_API_KEY, ANTHROPIC_BASE_URL
CodexVariables starting with OPENAIOPENAI_API_KEY
Gemini CLIVariables starting with GEMINI or GOOGLE_GEMINIGEMINI_API_KEY
Grok BuildXAI_API_KEY, GROK_DEFAULT_MODEL—

Conflict Warning

When a conflict is detected, a yellow warning banner appears at the top of the interface:

⚠️ Environment Variable Conflicts Detected
Found X environment variables that may override your configuration
[View Details] [×]

View Conflict Details

Click the "View Details" button to see the details:

FieldDescription
Variable NameEnvironment variable name
Variable ValueCurrently set value
SourceWhere the variable originates from

Source Types

SourceDescription
User Environment Variable (Registry)Windows user-level environment variable
System Environment Variable (Registry)Windows system-level environment variable
System Environment VariablemacOS/Linux variable in the current process environment
Shell configuration filemacOS/Linux shell configuration file (such as ~/.zshrc), shown as a file path in the UI

Resolve Conflicts

Select Variables to Remove

  1. Check the environment variables you want to remove
  2. Or click "Select All" to select all conflicting variables

Remove Variables

  1. Click the "Delete Selected" button
  2. Click "Confirm Delete" in the "Confirm Delete Environment Variables" dialog
  3. CC Switch will automatically back up and remove the selected variables; after removal, restart the app or terminal for it to take effect

Automatic Backup

A backup is automatically created before removal:

Dismiss Warning

If you confirm the conflict does not affect usage, you can:

  1. Click the close button (×) on the right side of the warning banner
  2. The warning will be hidden for the current run
  3. Detection will run again on next launch

Manual Resolution

If you prefer not to use CC Switch to remove variables, you can handle them manually:

Windows

  1. Open "System Properties > Advanced > Environment Variables"
  2. Find the conflicting variable in User or System variables
  3. Delete or modify the variable

macOS / Linux

  1. Edit the shell configuration file (e.g., ~/.zshrc, ~/.bashrc)
  2. Delete or comment out the relevant export statements
  3. Reload the configuration: source ~/.zshrc

Why Do Conflicts Occur

Environment variables typically take priority over configuration files, which may cause:

Best Practices

  1. Use CC Switch to manage configurations: Avoid setting API keys in system environment variables
  2. Check regularly: Pay attention to conflict warnings and address them promptly
  3. Back up important variables: Confirm backups exist before removal

Restore Deleted Variables

If you accidentally deleted environment variables:

  1. Find the backup file: env-backup-<timestamp>.json under ~/.cc-switch/backups/
  2. Open the corresponding JSON file
  3. Manually restore the variable to the system environment