PostHog is where your product analytics live. Events, funnels, retention, cohorts, the lot. Claude Code is Anthropic's AI coding CLI that runs in your terminal. Sequel's MCP server connects the two, so you can ask about user behavior while you're still in the codebase that produced it.
This guide walks you through the full setup in four steps.
What You'll Accomplish
By the end of this guide, you'll be able to open a terminal, run Claude Code, and ask questions like:
- "How many unique users hit the checkout flow yesterday, by country?"
- "Show me the signup to activation funnel for users created in the last 30 days."
- "What's the 7-day retention of the Power Users cohort?"
Claude Code will use Sequel's MCP server to write HogQL, run it against your PostHog project, and return the results in your terminal.
Prerequisites
- A Sequel account: Sign up free at sequel.sh
- A PostHog account on US Cloud, EU Cloud, or self-hosted
- Your numeric project ID, from your PostHog URL:
app.posthog.com/project/<id> - Claude Code installed: run
npm install -g @anthropic-ai/claude-codeif you haven't already
Step 1: Connect PostHog to Sequel
Sign in to sequel.sh and click Data Sources in the left sidebar.
![]()
Click New Connection. On the "Choose a connector" page, select PostHog.
![]()
Now create the key in PostHog. Go to Settings → Personal API Keys → Create personal API key and grant these six read-only scopes:
query:readevent_definitions:readproperty_definitions:readinsight:readcohort:readproject:read
Copy the key immediately. PostHog shows it exactly once.
Back in Sequel, fill in three fields:
- API key: the personal API key you just copied
- Host:
https://us.posthog.comfor US Cloud,https://eu.posthog.comfor EU Cloud, or your self-hosted base URL with no trailing slash - Project ID: the number from your PostHog URL
Click Connect. Sequel verifies the credentials against your project and confirms it by name.
Tip: grant read scopes only. The connector has no write tools, so a read-only key means Claude Code cannot touch your insights, dashboards, cohorts, or feature flags even by accident.
Step 2: Get Your Sequel API Key
Click Settings in the left sidebar, then select API Keys.
![]()
Click New key, name it claude-code-posthog, and copy the key. It starts with sql_. Treat it like a password.
Shortcut: if you have the Sequel CLI installed,
sequel install claude-codecreates the key and writes the Claude Code config for you. That covers Steps 2 and 3 in one command.
Step 3: Configure Claude Code to Use Sequel MCP
In your terminal:
claude mcp add --transport http sequel https://api.sequel.sh/mcp \
--header "Authorization: Bearer sql_your_api_key"Replace sql_your_api_key with the key from Step 2. Add --scope user before --transport to install it globally for every project. Verify with:
claude mcp listYou should see sequel in the list of configured MCP servers.
Step 4: Query Your PostHog Data
Start a Claude Code session and try these:
How many unique users triggered a pageview yesterday, broken down by country?
Build the signup to first-query funnel for users who signed up in the last 30 days, and tell me where the biggest drop-off is.
What's the week-over-week trend in daily active users for the last 8 weeks?
Claude Code calls the Sequel MCP server, which writes the HogQL, runs it against your project, and returns the results inline.
What You Can Do Now
- Ship-and-check loops: after deploying a feature, ask "How many users have triggered the new export event since yesterday?" without leaving the terminal.
- Funnel debugging: ask "Which step of the onboarding funnel lost the most users last week compared to the week before?"
- Cohort analysis: ask "Compare 30-day retention between users who connected a data source in week one and those who didn't."
- Event hygiene: ask "Which tracked events have had zero volume in the last 30 days?" to find dead instrumentation before it rots.
- Cross-source analysis: with Postgres or Stripe also connected, ask "For accounts on the Pro plan in Stripe, what's their 30-day active usage in PostHog?" That join is the part PostHog cannot answer on its own.

