|
| 1 | +--- |
| 2 | +title: VS Code extension |
| 3 | +sidebar: Docs |
| 4 | +showTitle: true |
| 5 | +--- |
| 6 | + |
| 7 | +import Tab from "components/Tab" |
| 8 | +import ConfigurationReference from "./_snippets/configuration-reference.mdx" |
| 9 | + |
| 10 | +The [PostHog VS Code extension](https://marketplace.visualstudio.com/items?itemName=PostHog.posthog-vscode) 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`). |
| 11 | + |
| 12 | +With it, you can see live analytics data inline in your code, [manage feature flags](/docs/vscode-extension/flag-management) without leaving your editor, [clean up stale flags](/docs/vscode-extension/stale-flag-cleanup) with AST-based refactoring, and [jump to session replays](/docs/vscode-extension/session-replay) for events in your codebase. |
| 13 | + |
| 14 | +> **Note:** This extension is different from the [PostHog MCP server for VS Code](/docs/model-context-protocol/vscode), 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. |
| 15 | +
|
| 16 | +## Installation |
| 17 | + |
| 18 | +Install directly from your editor: |
| 19 | + |
| 20 | +<Tab.Group tabs={['VS Code', 'Cursor']}> |
| 21 | +<Tab.List> |
| 22 | +<Tab>VS Code</Tab> |
| 23 | +<Tab>Cursor</Tab> |
| 24 | +</Tab.List> |
| 25 | +<Tab.Panels> |
| 26 | +<Tab.Panel> |
| 27 | + |
| 28 | +[Install in VS Code](vscode:extension/PostHog.posthog-vscode) |
| 29 | + |
| 30 | +</Tab.Panel> |
| 31 | +<Tab.Panel> |
| 32 | + |
| 33 | +[Install in Cursor](cursor:extension/PostHog.posthog-vscode) |
| 34 | + |
| 35 | +</Tab.Panel> |
| 36 | +</Tab.Panels> |
| 37 | +</Tab.Group> |
| 38 | + |
| 39 | +Or install manually: |
| 40 | + |
| 41 | +1. Open the Extensions panel (`Cmd+Shift+X` on Mac, `Ctrl+Shift+X` on Windows/Linux) |
| 42 | +2. Search for **"PostHog"** |
| 43 | +3. Click **Install** |
| 44 | + |
| 45 | +The extension is also available on the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=PostHog.posthog-vscode) and the [Open VSX Registry](https://open-vsx.org/extension/PostHog/posthog-vscode). |
| 46 | + |
| 47 | +<ProductScreenshot |
| 48 | + imageLight="https://res.cloudinary.com/dmukukwp6/image/upload/q_auto,f_auto/pasted_image_2026_04_07_T17_17_54_254_Z_0a1811dac8.png" |
| 49 | + alt="PostHog VS Code extension in the marketplace" |
| 50 | + classes="rounded" |
| 51 | +/> |
| 52 | + |
| 53 | +> **Requirements:** |
| 54 | +> - VS Code 1.109.0 or later |
| 55 | +> - A PostHog account |
| 56 | +
|
| 57 | +## Authentication |
| 58 | + |
| 59 | +Once installed, authenticate the extension with your PostHog account: |
| 60 | + |
| 61 | +1. Open the command palette (`Cmd+Shift+P` / `Ctrl+Shift+P`) |
| 62 | +2. Run `PostHog: Sign In` |
| 63 | +3. Click the sign-in button — this opens PostHog in your browser where you authenticate via OAuth |
| 64 | +4. Once authenticated, run **PostHog: Select Project** to choose which project to connect to |
| 65 | + |
| 66 | +After authenticating, the status bar at the bottom of VS Code shows your active project and last sync time. |
| 67 | + |
| 68 | +<ProductScreenshot |
| 69 | + imageLight="https://res.cloudinary.com/dmukukwp6/image/upload/w_500,c_limit,q_auto,f_auto/pasted_image_2026_04_07_T17_30_26_682_Z_279700c593.png" |
| 70 | + alt="PostHog VS Code extension sign-in flow" |
| 71 | + classes="rounded max-w-md" |
| 72 | +/> |
| 73 | + |
| 74 | +## Quick start |
| 75 | + |
| 76 | +Once connected, the extension immediately starts analyzing your code: |
| 77 | + |
| 78 | +- **SDK initialization diagnostics** help you verify that your PostHog `init()` calls are configured correctly, surfacing warnings if something looks off |
| 79 | +- **Inline decorations** appear next to `posthog.capture()` calls showing 7-day event volume sparklines |
| 80 | +- **Feature flag status** indicators show next to `posthog.isFeatureEnabled()` and `posthog.getFeatureFlag()` calls |
| 81 | +- **CodeLens** actions appear above flag and capture calls with contextual links |
| 82 | +- The **sidebar** populates with your feature flags, experiments, and saved insights |
| 83 | + |
| 84 | +<ProductScreenshot |
| 85 | + imageLight="https://res.cloudinary.com/dmukukwp6/image/upload/w_1000,c_limit,q_auto,f_auto/pasted_image_2026_04_07_T17_48_06_446_Z_3ff1a0d2aa.png" |
| 86 | + alt="PostHog VS Code extension quick start" |
| 87 | + classes="rounded" |
| 88 | +/> |
| 89 | + |
| 90 | +For details on each feature, see: |
| 91 | + |
| 92 | +| Feature | Description | |
| 93 | +|---|---| |
| 94 | +| [Inline code intelligence](/docs/vscode-extension/inline-code-intelligence) | Sparklines, flag status, autocomplete, and more | |
| 95 | +| [Sidebar dashboard](/docs/vscode-extension/sidebar-dashboard) | Flags, experiments, analytics, and X-ray tabs | |
| 96 | +| [Flag management](/docs/vscode-extension/flag-management) | Toggle, edit, create, and generate types for flags | |
| 97 | +| [Stale flag cleanup](/docs/vscode-extension/stale-flag-cleanup) | Find and remove outdated flag checks | |
| 98 | +| [Session replay](/docs/vscode-extension/session-replay) | See session and user counts, jump to replays | |
| 99 | + |
| 100 | +## Team configuration |
| 101 | + |
| 102 | +Share extension settings across your team by committing a `.posthog.json` file to your repository root: |
| 103 | + |
| 104 | +```json |
| 105 | +{ |
| 106 | + "projectId": 12345, |
| 107 | + "additionalClientNames": ["analytics"], |
| 108 | + "additionalFlagFunctions": ["useMyFlag"] |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +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. |
| 113 | + |
| 114 | +### Multi-project workspaces |
| 115 | + |
| 116 | +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. |
| 117 | + |
| 118 | +Set `posthog.multiProjectNotifications` to `true` (default) to get notified when the active project changes. |
| 119 | + |
| 120 | +### Automatic sync |
| 121 | + |
| 122 | +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. |
| 123 | + |
| 124 | +<ConfigurationReference /> |
| 125 | + |
| 126 | +## Commands reference |
| 127 | + |
| 128 | +Open the command palette (`Cmd+Shift+P` / `Ctrl+Shift+P`) and type "PostHog" to see all available commands. |
| 129 | + |
| 130 | +### Authentication and setup |
| 131 | + |
| 132 | +| Command | Description | |
| 133 | +|---|---| |
| 134 | +| `PostHog: Sign In` | Authenticate with your PostHog personal API key | |
| 135 | +| `PostHog: Sign Out` | Disconnect from PostHog | |
| 136 | +| `PostHog: Select Project` | Choose which PostHog project to use | |
| 137 | +| `PostHog: Run Setup Wizard` | Guided setup for first-time configuration | |
| 138 | + |
| 139 | +### Feature flags |
| 140 | + |
| 141 | +| Command | Description | |
| 142 | +|---|---| |
| 143 | +| `PostHog: Refresh Feature Flags` | Fetch the latest flags from PostHog | |
| 144 | +| `PostHog: Create Feature Flag` | Create a new flag in PostHog | |
| 145 | +| `PostHog: Copy Flag Key` | Copy a flag key to the clipboard | |
| 146 | +| `PostHog: Show Flag Detail` | Open the detail panel for a flag | |
| 147 | +| `PostHog: Open in PostHog` | Open the flag or experiment in your browser | |
| 148 | +| `PostHog: Find Flag References` | Search the workspace for all usages of a flag key | |
| 149 | +| `PostHog: Generate Flag Types` | Generate TypeScript types for all flag payloads | |
| 150 | +| `PostHog: Generate Type` | Generate a TypeScript type for a single flag (context menu) | |
| 151 | + |
| 152 | +### Experiments |
| 153 | + |
| 154 | +| Command | Description | |
| 155 | +|---|---| |
| 156 | +| `PostHog: Show Experiment Detail` | Open the detail panel for an experiment | |
| 157 | + |
| 158 | +### Session replay |
| 159 | + |
| 160 | +| Command | Description | |
| 161 | +|---|---| |
| 162 | +| `PostHog: Watch Sessions` | View sessions for an event in your browser | |
| 163 | + |
| 164 | +### Stale flags |
| 165 | + |
| 166 | +| Command | Description | |
| 167 | +|---|---| |
| 168 | +| `PostHog: Scan for Stale Flags` | Scan the workspace for stale feature flag references | |
| 169 | +| `PostHog: Clean Up Stale Flag` | Remove a stale flag check from the code | |
| 170 | + |
| 171 | +## Further reading |
| 172 | + |
| 173 | +- [PostHog VS Code extension on GitHub](https://github.com/PostHog/posthog-vscode) |
| 174 | +- [PostHog MCP server for VS Code](/docs/model-context-protocol/vscode) — AI agent integration |
| 175 | +- [Feature flags documentation](/docs/feature-flags) |
0 commit comments