Documentation Index Fetch the complete documentation index at: https://mintlify.com/Microsoft/vscode/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The vscode.env namespace provides access to environment information about the editor and the system.
Properties
appName
The application name of the editor.
Example:
import * as vscode from 'vscode' ;
console . log ( `Running in: ${ vscode . env . appName } ` );
// Output: "Running in: VS Code"
appRoot
The application root folder from which the editor is running.
appHost
The hosted location of the application.
On desktop this is 'desktop'. In the web this is the embedder (e.g., 'github.dev', 'codespaces', or 'web').
language
The preferred user language.
Example:
console . log ( `User language: ${ vscode . env . language } ` );
// Output: "User language: en-US"
machineId
A unique identifier for the computer.
sessionId
A unique identifier for the current session. Changes each time the editor is started.
clipboard
The system clipboard.
const clipboard : Clipboard
Example:
// Read from clipboard
const text = await vscode . env . clipboard . readText ();
console . log ( `Clipboard content: ${ text } ` );
// Write to clipboard
await vscode . env . clipboard . writeText ( 'Hello from VS Code!' );
vscode . window . showInformationMessage ( 'Text copied to clipboard' );
uriScheme
The custom URI scheme the editor registers to in the operating system.
isTelemetryEnabled
Indicates whether the user has telemetry enabled.
const isTelemetryEnabled : boolean
Example:
if ( vscode . env . isTelemetryEnabled ) {
// Send telemetry
console . log ( 'Telemetry is enabled' );
}
isNewAppInstall
Indicates whether this is a fresh install (true if within the first day of installation).
const isNewAppInstall : boolean
Methods
openExternal
Opens a URI externally using the default application.
function openExternal ( target : Uri ) : Thenable < boolean >
Example:
// Open URL in default browser
const uri = vscode . Uri . parse ( 'https://code.visualstudio.com' );
await vscode . env . openExternal ( uri );
// Open mailto link
const mailto = vscode . Uri . parse ( 'mailto:user@example.com' );
await vscode . env . openExternal ( mailto );
asExternalUri
Resolves a URI as if it was being opened externally.
function asExternalUri ( target : Uri ) : Thenable < Uri >
This is useful when working with remote workspaces and port forwarding.
Events
onDidChangeTelemetryEnabled
Fires when the user enables or disables telemetry.
const onDidChangeTelemetryEnabled : Event < boolean >
Example:
vscode . env . onDidChangeTelemetryEnabled ( enabled => {
if ( enabled ) {
console . log ( 'Telemetry was enabled' );
} else {
console . log ( 'Telemetry was disabled' );
}
});
Common Use Cases
Check Running Environment
if ( vscode . env . appHost === 'desktop' ) {
console . log ( 'Running on desktop' );
} else {
console . log ( `Running in: ${ vscode . env . appHost } ` );
}
Localization
const userLanguage = vscode . env . language ;
if ( userLanguage . startsWith ( 'de' )) {
// Show German UI
} else {
// Show English UI
}
Clipboard Integration
// Copy current selection to clipboard
const editor = vscode . window . activeTextEditor ;
if ( editor ) {
const selection = editor . document . getText ( editor . selection );
await vscode . env . clipboard . writeText ( selection );
}
Window API Learn about window-level operations