> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudthinker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# PostHog

> Connect PostHog so CloudThinker can triage tracked errors, read flags and insights, and answer usage questions with HogQL

Connect a PostHog project so [CloudThinker](https://docs.cloudthinker.io/guide/agents/overview.md) can rank the errors hurting users, report on feature flags, insights, dashboards, and surveys, and answer usage questions with HogQL (PostHog's SQL-like query language). The connection uses a PostHog personal API key, and the key's scopes decide what CloudThinker can reach.

## Prerequisites

* A PostHog Cloud account (US or EU) with access to the project you want CloudThinker to read. Self-hosted PostHog isn't supported: the connection only reaches PostHog's US and EU clouds.
* Permission to create a personal API key in that account.
* A project that is receiving events. A project with no events gives empty answers, not a broken connection.

## Setup

**1. Create a personal API key in PostHog**

In PostHog, open your account settings (personal API keys belong to your user, not to the project settings), go to **Personal API keys**, and click **+ Create a personal API Key**. Label it `CloudThinker`.

**2. Choose the MCP Server preset**

Select the **MCP Server** preset. It scopes the key to one project. Before you create the key, review the scopes the preset selects, and clear any write scopes you don't want CloudThinker to have. If you pick scopes by hand, choose only the areas in [Required permissions](#required-permissions).

**3. Copy the key**

Copy the key value (it starts with `phx_`). PostHog shows it once and hides it after you refresh the page.

**4. Connect in CloudThinker**

In the sidebar, click **More → Workspace settings → Connections**, stay on the **Builtin Connections** tab, and select **PostHog**. Paste the key into **POSTHOG\_PERSONAL\_API\_KEY**, pick your **POSTHOG\_REGION**, and click **Connect**. CloudThinker tests the connection by opening a session with PostHog's MCP server for that region.

**Success state:** the PostHog connection shows a **Connected** status. Run the verify prompt below to confirm the key reads your project.

## Verify the connection

> [!WARNING]
>
> Your first PostHog prompt may pause for approval, even though it only reads. CloudThinker treats every PostHog call as a write. See [Write access](#write-access).

```text theme={null}
Show my PostHog organization, the active project, and how many feature flags and insights it has
```

**Success state:** CloudThinker names your organization and active project and lists its flags, insights, dashboards, surveys, and tracked errors. A project with no flags or insights returns empty lists, not an error. An invalid-key error means the key or region is wrong; see [Troubleshooting](#troubleshooting).

## Connection details

| Field | What to enter |
| - | - |
| **Alias** | A short name for this connection, like `web-app`. Agents and [Rules](https://docs.cloudthinker.io/guide/approvals/rules.md) use it to tell connections apart |
| **Description** | What this connection's project covers, like `Product analytics for the web app`. Agents read it to pick the right connection |
| **POSTHOG\_PERSONAL\_API\_KEY** | The personal API key you created, starting with `phx_` |
| **POSTHOG\_REGION** | Pick **US** if you sign in at `us.posthog.com`, or **EU** if you sign in at `eu.posthog.com`. The options also show PostHog's server address for that region. Defaults to US. |

A key belongs to one PostHog cloud. Sent to the other region, it fails with an invalid-key error. One connection works with one active project; to cover a second project, add a second PostHog connection with its own key.

## Required permissions

A personal API key carries per-resource scopes, such as `insight:read`. CloudThinker can't reach anything the scopes leave out.

| Area | Why CloudThinker needs it |
| - | - |
| **Organizations and projects** | Name the organization and confirm the active project |
| **Feature flags** | Report which flags exist, their rollout, and status |
| **Insights and dashboards** | Read saved insights and the dashboards that hold them |
| **Surveys** | Report which surveys run and what they ask |
| **Error tracking** | Rank issues, group them by status, and open issue details |
| **Query** | Run HogQL and read the event schema |

> [!TIP]
>
> Start with read scopes only. Add write scopes, for example for feature flags, only if you want CloudThinker to propose changes there.

## Agent capabilities

| Capability | What CloudThinker does |
| - | - |
| **Project discovery** | Names the organization and active project, then lists flags, insights, dashboards, surveys, and tracked errors |
| **Error triage** | Ranks error issues by occurrence, groups them by status, and opens the worst ones |
| **Usage trends** | Summarizes event volume over a period (up to 90 days) and names the top events |
| **Event schema** | Reports which events and properties the project actually records, before querying them |
| **HogQL queries** | Answers a question with a query that carries its own row limit |
| **Changes** | Creates or updates a feature flag, insight, dashboard, experiment, survey, annotation, cohort, or alert. Each change goes through your Approvals, and a person who approves sees the exact inputs first |

## Example prompts

```text theme={null}
Which PostHog errors are hurting the most users right now?
Show signup event volume for the last 7 days
Which feature flags are rolled out to more than half of users?
```

## Write access

PostHog serves its whole tool surface through one command tool, and that tool can reach every change PostHog allows. CloudThinker therefore treats every PostHog call as a write, including calls that only read.

Every change an agent makes goes through your workspace's [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md) first. On the default **Auto · Rules + AI · Ask me** mode, AI judgment can let a safe change run without asking — and an Allow Rule can too, once CloudThinker turns on [Rule enforcement](https://docs.cloudthinker.io/guide/approvals/rules.md#troubleshooting) for your workspace. Choose **Manual** to approve every change yourself.

Choose **Manual** so a person approves every PostHog call, read or write. Because PostHog has one command tool, no Rule can tell a PostHog read from a write — so once CloudThinker turns on [Rule enforcement](https://docs.cloudthinker.io/guide/approvals/rules.md#troubleshooting) for your workspace, an **Allow** Rule for PostHog calls would let feature flag changes through as well.

> [!WARNING]
>
> A feature flag change affects real users as soon as it runs, and switching the active project changes which project the rest of the conversation reads. Check the exact inputs in the approval prompt before you approve.

## Troubleshooting

> [accordion] Every call fails with an invalid-key error
>
> The key comes from the other PostHog cloud, or it was revoked. Set **POSTHOG\_REGION** to match the host you sign in to. If that's already right, create a new key and update the connection.

> [accordion] CloudThinker says a capability is unavailable, or the project looks empty
>
> The key is missing that scope. PostHog hides tools the key can't reach, which can look like a project with no flags or no errors. Open the key in PostHog, add the scope or create a new key with the **MCP Server** preset, then update the connection.

> [accordion] CloudThinker reads the wrong project
>
> One connection has one active project. Ask `Which PostHog project is active?` to check. To change it, ask CloudThinker to switch projects: the switch shows up as an approval prompt. Or add a second PostHog connection with a key for the other project.

> [accordion] A read paused for approval
>
> Expected. CloudThinker treats every PostHog call as a write, so reads can pause too. See [Write access](#write-access) for what each Approval mode does with PostHog calls.

> [accordion] Calls fail with 429 after heavy use
>
> PostHog returned a 429 rate-limit error. PostHog rate limits are shared across all users and keys in your organization. Wait for the limit to reset, then ask a narrower question so CloudThinker reads less.

> [accordion] I lost the key value
>
> PostHog shows a personal API key once. Create a new key and update the connection.

## Security

* **Least privilege** — grant only the permissions the agents need for your use case; start read-only and widen later.
* **Read-only by default** — use read-only credentials unless you want agents to make changes through this connection.
* **Rotate credentials** — rotate keys and tokens on your normal schedule; CloudThinker picks up the new value when you update the connection.
* **Revoke on offboarding** — remove the credential at the provider when you delete a connection or a teammate leaves.

- **Treat the key like a password**: a personal API key can act as your PostHog user within its scopes. Use the **MCP Server** preset and keep the key for CloudThinker only, so you can revoke it alone.
- **Project token stays out of chat**: CloudThinker reads project details through a path that drops the project's ingestion token, so the token never appears in a conversation.

## Related

> [card] [Sentry Connection](https://docs.cloudthinker.io/guide/connections/sentry.md)
>
> Investigate application errors and performance in Sentry

> [card] [Approvals](https://docs.cloudthinker.io/guide/approvals/overview.md)
>
> Decide which connection writes run without asking you


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.