VS Code extension

The PostHog VS Code extension brings feature flags, experiments, event analytics, and session replay data directly into your editor. It works with JavaScript, TypeScript, Go and Ruby files (.js, .jsx, .ts, .tsx, .go, .rb).

With it, you can see live analytics data inline in your code, manage feature flags without leaving your editor, clean up stale flags with AST-based refactoring, and jump to session replays for events in your codebase.

Note: This extension is different from the PostHog MCP server for VS Code, which enables AI agents and Copilot to interact with PostHog. The VS Code extension provides direct, visual tooling for developers in the editor. They complement each other.

Installation

Install directly from your editor:

Or install manually:

  1. Open the Extensions panel (Cmd+Shift+X on Mac, Ctrl+Shift+X on Windows/Linux)
  2. Search for "PostHog"
  3. Click Install

The extension is also available on the VS Code Marketplace and the Open VSX Registry.

PostHog VS Code extension in the marketplace

Requirements:

  • VS Code 1.109.0 or later
  • A PostHog account

Authentication

Once installed, authenticate the extension with your PostHog account:

  1. Open the command palette (Cmd+Shift+P / Ctrl+Shift+P)
  2. Run PostHog: Sign In
  3. Click the sign-in button — this opens PostHog in your browser where you authenticate via OAuth
  4. Once authenticated, run PostHog: Select Project to choose which project to connect to

After authenticating, the status bar at the bottom of VS Code shows your active project and last sync time.

PostHog VS Code extension sign-in flow

Quick start

Once connected, the extension immediately starts analyzing your code:

  • SDK initialization diagnostics help you verify that your PostHog init() calls are configured correctly, surfacing warnings if something looks off
  • Inline decorations appear next to posthog.capture() calls showing 7-day event volume sparklines
  • Feature flag status indicators show next to posthog.isFeatureEnabled() and posthog.getFeatureFlag() calls
  • CodeLens actions appear above flag and capture calls with contextual links
  • The sidebar populates with your feature flags, experiments, and saved insights
PostHog VS Code extension quick start

For details on each feature, see:

FeatureDescription
Inline code intelligenceSparklines, flag status, autocomplete, and more
Sidebar dashboardFlags, experiments, analytics, and X-ray tabs
Flag managementToggle, edit, create, and generate types for flags
Stale flag cleanupFind and remove outdated flag checks
Session replaySee session and user counts, jump to replays

Team configuration

Share extension settings across your team by committing a .posthog.json file to your repository root:

JSON
{
"projectId": 12345,
"additionalClientNames": ["analytics"],
"additionalFlagFunctions": ["useMyFlag"]
}

This ensures everyone on the team connects to the correct project and the extension recognizes your custom PostHog client variable names and flag wrapper functions.

Multi-project workspaces

If your VS Code workspace contains multiple folders connected to different PostHog projects, the extension detects this automatically. Each folder can have its own .posthog.json with a different projectId. The extension switches context as you navigate between files in different folders.

Set posthog.multiProjectNotifications to true (default) to get notified when the active project changes.

Automatic sync

The extension periodically refreshes its cache of feature flags, experiments, and event data from PostHog. The status bar shows when the last sync occurred. You can also manually refresh with the PostHog: Refresh Feature Flags command.

Configuration reference

SettingDescriptionDefault
posthog.additionalClientNamesAdditional variable names the extension should recognize as instances of PostHog clients (e.g., ["analytics", "ph"])[]
posthog.additionalFlagFunctionsAdditional bare function names that accept a flag key as the first argument (e.g., ["useMyFlag"])[]
posthog.detectNestedClientsDetect PostHog clients accessed via nested member expressions like window.posthog?.capture()true
posthog.showInlineDecorationsShow inline annotations (sparklines, flag status) in the editortrue
posthog.inlineHintsModeWhen to show inline hints: always or currentLinealways
posthog.staleFlagAgeDaysMinimum number of days before a fully rolled out flag is considered stale30
posthog.staleFlagExcludePatternsGlob patterns for files and directories to exclude from stale flag scanning[]
posthog.useWorkspaceConfigLoad configuration from a .posthog.json file in the workspace roottrue
posthog.multiProjectNotificationsShow notifications when switching between projects in a multi-project workspacetrue

Commands reference

Open the command palette (Cmd+Shift+P / Ctrl+Shift+P) and type "PostHog" to see all available commands.

Authentication and setup

CommandDescription
PostHog: Sign InAuthenticate with your PostHog personal API key
PostHog: Sign OutDisconnect from PostHog
PostHog: Select ProjectChoose which PostHog project to use
PostHog: Run Setup WizardGuided setup for first-time configuration

Feature flags

CommandDescription
PostHog: Refresh Feature FlagsFetch the latest flags from PostHog
PostHog: Create Feature FlagCreate a new flag in PostHog
PostHog: Copy Flag KeyCopy a flag key to the clipboard
PostHog: Show Flag DetailOpen the detail panel for a flag
PostHog: Open in PostHogOpen the flag or experiment in your browser
PostHog: Find Flag ReferencesSearch the workspace for all usages of a flag key
PostHog: Generate Flag TypesGenerate TypeScript types for all flag payloads
PostHog: Generate TypeGenerate a TypeScript type for a single flag (context menu)

Experiments

CommandDescription
PostHog: Show Experiment DetailOpen the detail panel for an experiment

Session replay

CommandDescription
PostHog: Watch SessionsView sessions for an event in your browser

Stale flags

CommandDescription
PostHog: Scan for Stale FlagsScan the workspace for stale feature flag references
PostHog: Clean Up Stale FlagRemove a stale flag check from the code

Further reading

Community questions

Was this page useful?

Questions about this page? or post a community question.