You can use Environment variables
The syntax is like ${env:USERNAME}
Setting environment variable in VS Code debugger
Environmental variables for VS Code
Set environment variables in VSCode (Windows) - Node - Code with Mosh Forum
Is there any way to set environment variables in Visual Studio Code? - Stack Overflow
Videos
You can use Environment variables
The syntax is like ${env:USERNAME}
You can use the attribute "env" in settings.json. For example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
// ENVINRONMENT VARIABLES
"env": {
"VAR_A": "value_a",
"VAR_B": "value_b"
}
}
]
}
Anyone know how to set the environmental variables for the VS Code extension? The docs tell you where to set them, but not the syntax. VS Code seems to want claude-code.environmentVariables to be an array, but I have no idea of what.
Assuming you mean for a debugging session(?) then you can include a env property in your launch configuration.
If you open the .vscode/launch.json file in your workspace or select Debug > Open Configurations then you should see a set of launch configurations for debugging your code. You can then add to it an env property with a dictionary of string:string.
Here is an example for an ASP.NET Core app from their standard web template setting the ASPNETCORE_ENVIRONMENT to Development :
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/vscode-env.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
You can load an environment file by setting the envFile property like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env", // HERE
"args": [],
"showLog": true
}
]
}
Place the .env file in your folder and add vars like this:
KEY1="TEXT_VAL1"
KEY2='{"key1":val1","key2":"val2"}'
Further Reading: Debugging go in vscode with environment variables
Hi everyone,
I'm trying to understand how to use .env files to add extra environment variables to my python programs. Unfortunately, the documentation is quite terse and googling hasn't yielded many useful results.
I've figured a lot of things out, but my current problem is that I simply haven't been able to access the variables in .env within a program itself. I get the feeling that I'm just missing one or two pieces of the puzzle.
I'll try to include everything I think will be relevant.
I've set the IDE up in the following way:
Directory structure
├─ .vscode/ │ ├─ launch.json ├─ .env ├─ testenv.py
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"envFile": "${workspaceFolder}/.env"
}
]
}.env
test_environment_variable=64
testenv.py
import os
print(os.getenv("test_environment_variable"))In the global settings menu, I've also made sure that python.envFile is set how it should be
${workspaceFolder}/.envFinally, I should mention that I'm running python 3.11.3 in VSCode 1.78.2, on a 64-bit Windows 10 PC.
With this configuration, I would expect to print the value of test_envionment_variable, set in .env, when I run testenv.py. However, the only thing it prints is None, meaning of course that it wasn't found. I've also tried printing via os.environ["test_environment_variable"] with similar results (except that it raises KeyError as expected).
What am I missing? Like I mentioned, I suspect I've either got a couple steps wrong, or I'm just entirely misunderstanding how to use .env files.
Thanks in advance!
I'm successfully passing them using the env property in launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js",
"env": {
"TEST_VAR": "foo"
}
}
]
}
This is working

just add the following:
"env": {
"NODE_ENV": "development"
}
As shown below:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program", //TODO: cmd as launch program
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\index.js",
"env": {
"NODE_ENV": "development"
}
}
]
Here is an example, you set the value in the environment block.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - (GDB 9.2) Build and debug active file with RepoCodeInspection",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/bin/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"description": "same as commands below by using 'setenv ...",
"info": "cant debug b/c of libBase/libRecipe now requiring dependency to boost for stacktrace dumps",
"name": "LD_LIBRARY_PATH",
"value": "/libs/:./"
}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": {
"trace": false,
"traceResponse": false
},
"preLaunchTask": "RepoCodeInspection",
},
{
"name": "g++ - (GDB 9.2) Attach to a running process",
"type": "cppdbg",
"request": "attach",
"processId":"${command:pickProcess}",
"program": "${fileDirname}/bin/${fileBasenameNoExtension}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": {
"trace": false,
"traceResponse": false
},
"preLaunchTask": "RepoCodeInspection",
},
]
}
To set multiple environment variables, use comma-separated "name", "value" pairs.
Example:
"environment": [{"name": "LD_LIBRARY_PATH", "value": "/ld/library/path/"},
{"name": "CUDA_VISIBLE_DEVICES", "value": "0"}
]