Loading Priority
Environment variables are loaded in the following order (highest to lowest priority):- CLI flags (highest priority)
- System/Shell environment variables (
exportor inline) .envfiles (searched from current directory upward)settings.json→envfield (lowest priority)
.env Files
Qwen Code automatically searches for.env files in the following order:
.qwen/.envin current directory (searched upward to home).envin current directory (searched upward to home)~/.qwen/.env(user-level fallback)~/.env(home directory fallback)
Example .env File
.env
API Key Variables
Model Providers
string
API key for Alibaba Cloud DashScope (Qwen models).Get your key at: Alibaba Cloud ModelStudio
string
API key for Alibaba Cloud Bailian Coding Plan subscription.Get your key at: Bailian Coding Plan
string
API key for OpenAI models.Get your key at: OpenAI API Keys
string
API key for Anthropic Claude models.Get your key at: Anthropic Console
string
API key for Google Gemini models (via Google AI Studio).Get your key at: Google AI Studio
string
API key for Google services (Vertex AI, Custom Search).
Custom Environment Variables
You can define custom environment variable names inmodelProviders:
Base URL Variables
string
Custom base URL for OpenAI-compatible APIs.Example:
https://api.openai.com/v1string
Custom base URL for Anthropic API.Example:
https://api.anthropic.comWeb Search Variables
string
Google Custom Search Engine ID.Set up at: Google Custom Search
Proxy Variables
string
HTTPS proxy server URL.Example:
http://proxy.example.com:8080string
HTTP proxy server URL.Example:
http://proxy.example.com:8080string
Comma-separated list of hosts to bypass proxy.Example:
localhost,127.0.0.1,.localGoogle Cloud Variables
string
Path to Google Cloud service account key file (for Vertex AI).Example:
/path/to/service-account-key.jsonstring
Google Cloud project ID (for Vertex AI).
string
Set to
true to use Vertex AI instead of Google AI.System Variables
string
Enable debug mode. Set to
true or 1.string
Alternative to
DEBUG. Set to true or 1.string
Disable browser opening for OAuth flows. Set to
true or 1.string
Force Qwen OAuth authentication.
string
Indicates running in Google Cloud Shell (set automatically).
Path Overrides
string
Override system settings file path.
string
Override system defaults file path.
string
Override trusted folders file path.
Sandbox Variables
string
Sandbox execution environment identifier.
string
Set UID/GID in sandbox. Set to
true or false.string
Comma-separated list of ports to expose in sandbox.Example:
8080,3000,5000string
Comma-separated list of volume mounts for sandbox.Example:
/host/path:/container/path,/another:/pathstring
Enable sandbox build mode.
string
Custom proxy command for sandbox.
Testing Variables
string
Enable integration test mode. Set to
true.string
Node.js environment. Set to
development, production, or test.Usage Examples
Setting Variables via Export
Setting Variables Inline
Using .env File
Create~/.qwen/.env:
Project-Specific .env
Create.qwen/.env in your project:
Fallback in settings.json
For non-sensitive variables or defaults:Excluded Variables
Some environment variables are excluded from project context by default:DEBUGDEBUG_MODE
Workspace Trust
When folder trust is enabled, project-level.env files are only loaded from trusted workspaces. User-level .env files (~/.qwen/.env, ~/.env) are always loaded.
See Trusted Folders for more information.
Security Best Practices
-
Never commit
.envfiles - Add to.gitignore: -
Use user-level
.envfor personal keys - Store in~/.qwen/.env -
Use project
.envfor team settings - Document required variables without including actual keys - Rotate keys regularly - Update API keys periodically
-
Use environment-specific files - Consider
.env.development,.env.productionpatterns -
Set file permissions - Restrict access to
.envfiles:
Troubleshooting
Variable Not Loading
-
Check the file location:
-
Verify file syntax (no quotes around values unless needed):
- Check for typos in variable names (case-sensitive)
- Ensure no trailing whitespace
Priority Issues
If a variable isn’t using the expected value:- Check system environment:
echo $VARIABLE_NAME - Check
.envfile in current directory - Check
~/.qwen/.env - Check
settings.json→env
Workspace Trust Issues
If project.env isn’t loading:
-
Check if folder trust is enabled:
-
Trust the workspace or move variables to
~/.qwen/.env
