# PostHog integration for PostHog Code - Docs

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](/docs/posthog-code/skills.md) 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:

| Skill | What it does |
| --- | --- |
| instrument-product-analytics | Set up event capture |
| instrument-feature-flags | Add flag checks and rollouts |
| instrument-error-tracking | Hook up error capture |
| instrument-llm-analytics | Instrument LLM calls |
| instrument-logs | Send logs to PostHog |

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

| Skill | What it does |
| --- | --- |
| creating-experiments | Scaffold new experiments |
| configuring-experiment-analytics | Define metrics and goals |
| managing-experiment-lifecycle | Launch, monitor, and ship results |

Work with HogQL and LLM analytics data with these skills:

| Skill | What it does |
| --- | --- |
| query-examples | Write HogQL queries from worked examples |
| exploring-llm-traces | Inspect individual LLM traces |
| exploring-llm-clusters | Find patterns across LLM traffic |

Manage data pipelines with these skills:

| Skill | What it does |
| --- | --- |
| setting-up-a-data-warehouse-source | Connect a new warehouse source |
| diagnosing-failed-warehouse-syncs | Debug sync failures |
| auditing-warehouse-data-health | Check freshness and integrity |

## Built-in PostHog MCP

PostHog's [MCP server](/docs/model-context-protocol.md) 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 AI

```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

| Language | Capture | Flags | Init | Variants |
| --- | --- | --- | --- | --- |
| 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](/docs/model-context-protocol.md) when the agent queries insights, dashboards, flags, experiments, and errors
-   The enricher when it fetches flag and event metadata
-   [Cloud tasks](/docs/posthog-code/cloud-runs.md) launched from your machine

### Community questions

Ask a question

### Was this page useful?

HelpfulCould be better