PostHog integration for PostHog Code

PostHog Code brings your PostHog context into the agent in real time, including product data, flags, experiments, and errors. If you don't use PostHog, PostHog Code still works as a general-purpose coding agent. The integration adds context, it isn't a hard dependency.

Built-in PostHog skills

PostHog Code ships a curated set of skills that the agent loads automatically. They update independently of the desktop app, so you get new skills without waiting for a release.

Wire up PostHog SDKs in any supported language with these skills:

SkillWhat it does
instrument-product-analyticsSet up event capture
instrument-feature-flagsAdd flag checks and rollouts
instrument-error-trackingHook up error capture
instrument-llm-analyticsInstrument LLM calls
instrument-logsSend logs to PostHog

Run A/B tests end to end with these skills:

SkillWhat it does
creating-experimentsScaffold new experiments
configuring-experiment-analyticsDefine metrics and goals
managing-experiment-lifecycleLaunch, monitor, and ship results

Work with HogQL and LLM analytics data with these skills:

SkillWhat it does
query-examplesWrite HogQL queries from worked examples
exploring-llm-tracesInspect individual LLM traces
exploring-llm-clustersFind patterns across LLM traffic

Manage data pipelines with these skills:

SkillWhat it does
setting-up-a-data-warehouse-sourceConnect a new warehouse source
diagnosing-failed-warehouse-syncsDebug sync failures
auditing-warehouse-data-healthCheck freshness and integrity

Built-in PostHog MCP

PostHog's MCP server is wired up out of the box. Once you sign in, the agent can query your project for insights, dashboards, flags, experiments, and errors. This is useful for prompts like "did my last deploy regress conversion?" or "build me a dashboard for the new checkout flow".

You don't need to install or configure the MCP server separately. It's authenticated with the same session you use to sign in.

Enricher

The enricher detects PostHog SDK calls in your source and pulls live context from your PostHog project so the agent (and you) can reason about real impact, not just code.

When you open a file or stage a diff, PostHog Code parses it and finds:

  • capture() calls and the events they emit
  • Feature flag checks (isFeatureEnabled, getFeatureFlag, etc.)
  • init() calls and SDK configuration
  • Variant branches based on flag values

For each detection, it fetches the matching record from PostHog, then surfaces it inline. This can include flag rollout and staleness, experiment status, event volume, unique users, and last-seen timestamps.

TypeScript
// [PostHog] Event: "purchase" (verified), 12,500 events, 3,200 users
posthog.capture("purchase", { amount: 99 });
// [PostHog] Flag: "new-checkout", boolean, 100% rolled out, STALE (fully_rolled_out)
const flag = posthog.getFeatureFlag("new-checkout");

That context goes into the agent's working memory, so when you ask it to clean up a stale flag or change an event payload, it knows the actual usage and consequences.

Supported languages

LanguageCaptureFlagsInitVariants
JavaScript / TypeScript
JSX / TSX
Python
Go
Ruby

Detection runs locally via tree-sitter. Source code is not sent anywhere. Enrichment fetches metadata from your PostHog project using your existing API credentials.

Switching projects

PostHog Code is signed in to your PostHog organization out of the box. To change which project the integration points at, use the project switcher in the bottom-left corner of the app and pick a different project from the list.

The selected project is the one used by:

  • The PostHog MCP server when the agent queries insights, dashboards, flags, experiments, and errors
  • The enricher when it fetches flag and event metadata
  • Cloud tasks launched from your machine

Community questions

Was this page useful?

Questions about this page? or post a community question.