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
API key for Alibaba Cloud DashScope (Qwen models).Get your key at: Alibaba Cloud ModelStudio
API key for Alibaba Cloud Bailian Coding Plan subscription.Get your key at: Bailian Coding Plan
API key for OpenAI models.Get your key at: OpenAI API Keys
API key for Anthropic Claude models.Get your key at: Anthropic Console
API key for Google Gemini models (via Google AI Studio).Get your key at: Google AI Studio
API key for Google services (Vertex AI, Custom Search).
Custom Environment Variables
You can define custom environment variable names inmodelProviders:
Base URL Variables
Custom base URL for OpenAI-compatible APIs.Example:
https://api.openai.com/v1Custom base URL for Anthropic API.Example:
https://api.anthropic.comWeb Search Variables
Google Custom Search Engine ID.Set up at: Google Custom Search
Proxy Variables
HTTPS proxy server URL.Example:
http://proxy.example.com:8080HTTP proxy server URL.Example:
http://proxy.example.com:8080Comma-separated list of hosts to bypass proxy.Example:
localhost,127.0.0.1,.localGoogle Cloud Variables
Path to Google Cloud service account key file (for Vertex AI).Example:
/path/to/service-account-key.jsonGoogle Cloud project ID (for Vertex AI).
Set to
true to use Vertex AI instead of Google AI.System Variables
Enable debug mode. Set to
true or 1.Alternative to
DEBUG. Set to true or 1.Disable browser opening for OAuth flows. Set to
true or 1.Force Qwen OAuth authentication.
Indicates running in Google Cloud Shell (set automatically).
Path Overrides
Override system settings file path.
Override system defaults file path.
Override trusted folders file path.
Sandbox Variables
Sandbox execution environment identifier.
Set UID/GID in sandbox. Set to
true or false.Comma-separated list of ports to expose in sandbox.Example:
8080,3000,5000Comma-separated list of volume mounts for sandbox.Example:
/host/path:/container/path,/another:/pathEnable sandbox build mode.
Custom proxy command for sandbox.
Testing Variables
Enable integration test mode. Set to
true.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
