Skip to main content

VS Code Extension API Overview

The Visual Studio Code Extension API allows you to extend and customize VS Code. This comprehensive API provides access to the editor’s core functionality, enabling you to create powerful extensions.

API Namespaces

The VS Code API is organized into several namespaces, each providing specific functionality:

Core Namespaces

commands

Register and execute commands

window

Interact with the editor window and UI

workspace

Access workspace folders and files

languages

Provide language features like IntelliSense

debug

Integrate debugging capabilities

authentication

Implement authentication providers

webview

Create custom webview panels

env

Access environment information

Getting Started

Every VS Code extension exports an activate function that receives an ExtensionContext object:

Extension Manifest

Extensions are defined by a package.json file that specifies activation events, contributions, and dependencies:
package.json

Core Concepts

Disposables

Many VS Code APIs return Disposable objects that must be disposed to prevent memory leaks:
Always add disposables to context.subscriptions to ensure they’re properly cleaned up when your extension is deactivated.

Promises and Thenables

Most async operations return Thenable<T> (Promise-compatible):

Events

The API uses an event-driven model. Subscribe to events using the Event<T> interface:

API Versioning

The API version is specified in your package.json:
string
required
Minimum VS Code version required (semver format)
This ensures your extension only runs on compatible VS Code versions.

Common Patterns

Configuration Settings

Access and modify settings through the workspace configuration:

Status Bar Items

Create status bar items to display information:

Output Channels

Create output channels for logging:

Best Practices

  • Lazy load modules and activate only when needed
  • Use activation events to delay extension loading
  • Dispose of resources properly to prevent memory leaks
  • Avoid synchronous operations that block the UI
  • Provide clear progress indicators for long operations
  • Use appropriate notification severity (info, warning, error)
  • Support keyboard shortcuts and accessibility
  • Follow VS Code’s UI guidelines and conventions
  • Validate user input and external data
  • Use secure protocols for network requests
  • Don’t store secrets in plain text
  • Request minimal permissions

Resources

Next Steps

Explore specific API areas: