PostHog MCP for
Claude Code在 Claude Code 中
接入 PostHog MCP
Connect product analytics to the code that generates it, then investigate events, flags, experiments, and errors with explicit project and privacy boundaries.
把产品分析数据与产生它的代码连接起来,
在明确项目与隐私边界下调查事件、功能开关、实验和错误。
What PostHog MCP changes inside Claude CodePostHog MCP 如何改变 Claude Code 的调查方式
PostHog MCP lets Claude Code connect product behavior with implementation context in one investigation. Instead of copying a chart into a prompt, the agent can inspect approved PostHog resources, locate the event capture or feature-flag code that produced them, test a hypothesis, and propose a bounded patch. The connection does not make an analytics conclusion automatically correct. Project selection, event definitions, identity rules, timezone, filters, and query windows still determine what the numbers mean.
PostHog MCP 让 Claude Code 在同一次调查中把产品行为与实现上下文联系起来。与其把一张图表复制进提示词,智能体可以读取获准的 PostHog 资源,定位产生这些数据的事件上报或功能开关代码,检验假设,再提出范围明确的补丁。但连接成功并不代表分析结论自动正确;项目选择、事件定义、身份归并、时区、筛选条件和查询周期,仍然决定数字应该如何解释。
Name the behavior, population, time window, comparison, and decision. “Why is activation down?” is a topic; a segmented week-over-week funnel question is testable.
Record the PostHog host, organization, project, timezone, and environment before querying. Similar project names can silently produce credible but wrong results.
Move from events to capture code and from capture code back to observed events. This reveals naming drift, missing properties, and duplicate instrumentation.
Explore read-only. Treat changes to flags, experiments, annotations, dashboards, or project configuration as distinct actions requiring review.
写清行为、用户范围、时间窗口、对照组和要支持的决策。“激活率为什么下降”只是主题;按人群拆分的周同比漏斗问题才可检验。
查询前记录 PostHog 主机、组织、项目、时区和环境。相似项目名可能返回看起来可信、实际完全错误的结果。
既从事件找到上报代码,也从上报代码反查实际事件,才能发现命名漂移、属性缺失和重复埋点。
探索阶段保持只读。修改功能开关、实验、Annotation、Dashboard 或项目配置,应视为不同动作并分别审查。
Install the current PostHog MCP integration安装当前 PostHog MCP 集成
PostHog's earlier standalone MCP repository was archived after the server moved into the PostHog monorepo. Do not build a new setup around an old repository snippet. PostHog currently directs users to its product documentation and provides a wizard that can add the MCP integration to Claude Code and other supported clients.
PostHog 早期独立 MCP 仓库已经归档,因为服务器已迁入 PostHog 主仓库。新配置不要再照搬旧仓库片段。PostHog 目前把用户引导至产品文档,并提供向 Claude Code 等客户端添加 MCP 集成的安装向导。
Decide whether the workspace uses PostHog Cloud US, Cloud EU, or an approved self-hosted deployment. Authentication and project discovery must correspond to the same host.
PostHog documents npx @posthog/wizard@latest mcp add as the quick installation path. Select Claude Code, follow the generated setup, and inspect changes before accepting any project-level configuration.
Use an identity that has access to the required project and no unnecessary administrative role. If the browser already has multiple PostHog sessions, verify the selected account before granting consent.
Open Claude Code's MCP view, confirm PostHog is connected, and list the exposed tools without calling a mutation. Note whether the session can read or modify projects, flags, experiments, insights, or other resources.
Retrieve a known event or saved insight over a short, explicit period. Compare the project, timezone, filters, interval boundaries, and result with the PostHog interface.
先确定工作区使用 PostHog Cloud US、Cloud EU,还是获批的自托管部署。身份验证和项目发现必须指向同一主机。
PostHog 把 npx @posthog/wizard@latest mcp add 作为快速安装路径。选择 Claude Code,按向导生成配置;如果它准备修改项目级文件,应先检查内容再接受。
所选身份应能访问目标项目,但不应拥有无关的管理员角色。如果浏览器里登录了多个 PostHog 账号,授权前要再次确认当前身份。
打开 Claude Code 的 MCP 视图,确认 PostHog 已连接,并在不调用变更操作的前提下列出工具。记录当前会话对项目、开关、实验、洞察等资源是只读还是可写。
在明确且较短的周期内读取一个已知事件或已保存洞察,并与 PostHog 界面核对项目、时区、筛选器、区间边界和结果。
| Checkpoint检查点 | Passing evidence通过证据 | If it fails失败时 |
|---|---|---|
| Discovery发现 | PostHog appears connected in Claude Code.Claude Code 中显示 PostHog 已连接。 | Inspect wizard output, client config, restart, and server URL.检查向导输出、客户端配置、重启状态和服务器地址。 |
| Identity身份 | Expected organization and projects are visible—no more, no less.可见组织和项目与预期完全一致。 | Reauthorize the correct account and review role assignments.重新授权正确账号,并核对角色。 |
| Semantics语义 | A known query matches UI settings and results.已知查询的设置与结果和界面一致。 | Check project, event name, properties, timezone, filters, and date boundaries.检查项目、事件名、属性、时区、筛选器和日期边界。 |
| Boundary边界 | Only required tools and resources are exposed.只开放任务必需的工具和资源。 | Reduce account role, configuration, or available tool scope.缩减账号角色、配置或工具范围。 |
Run an evidence-backed analytics-to-code investigation从数据证据走到代码改动
The strongest workflow begins with a falsifiable statement, not a dashboard tour. Define the expected relationship and the evidence that would reject it. Then let Claude Code inspect the instrumentation and PostHog data separately before joining them. This prevents an implementation guess from contaminating the query and a noisy chart from dictating a premature code change.
最有效的流程不是先逛 Dashboard,而是先提出可证伪陈述:写清预期关系,以及什么证据会推翻它。随后让 Claude Code 分别检查埋点实现和 PostHog 数据,最后再把两边连接起来。这样可以避免“先猜代码问题,再按猜测查询”,也能防止一张噪声很大的图表直接驱动仓促改动。
| Stage阶段 | Question关键问题 | Claude Code taskClaude Code 任务 | Evidence证据 |
|---|---|---|---|
| Frame界定 | What behavior, population, period, and decision?研究什么行为、用户、周期和决策? | Write the hypothesis, exclusions, baseline, and success threshold.写出假设、排除条件、基线和成功阈值。 | Analysis contract.分析约定。 |
| Inspect code检查代码 | How should the behavior be captured?这个行为按设计应如何上报? | Locate capture calls, property construction, identity, flags, and recent changes.定位上报调用、属性构造、身份逻辑、开关和近期变更。 | Paths, lines, commits, tests.路径、代码行、提交和测试。 |
| Inspect data检查数据 | What was actually observed?实际观察到了什么? | Query the smallest event, funnel, trend, cohort, flag, or experiment slice that tests the claim.查询足以检验假设的最小事件、漏斗、趋势、群组、开关或实验切片。 | Project, query, filters, window, result.项目、查询、筛选、周期和结果。 |
| Reconcile对照 | Where do implementation and behavior diverge?实现与行为在哪里偏离? | Check event naming, missing or changed properties, duplicate capture, identity, and release timing.检查事件命名、属性缺失或变化、重复上报、身份归并和发布时间。 | Supported cause and alternatives.受证据支持的原因与备选解释。 |
| Change改动 | What is the smallest reversible fix?最小且可回退的修复是什么? | Propose code, schema, flag, migration, tests, rollout, and rollback separately.分别提出代码、数据结构、开关、迁移、测试、发布和回退方案。 | Patch and validation plan.补丁与验证计划。 |
| Measure复测 | Did behavior change as expected?行为是否按预期变化? | Repeat the saved query with a valid post-change window and guardrail metrics.在有效的改动后周期重新运行保存查询,并检查护栏指标。 | Comparable before/after record.可比较的前后记录。 |
Reusable investigation prompt: “In the named PostHog project, test whether new-user activation fell after release X. Use the project timezone, define activation explicitly, exclude internal users, segment by platform, and compare equal complete periods. Inspect the repository capture and identity code, but do not edit files or change PostHog resources. Return the query definition, evidence, limitations, likely causes, and smallest validation plan.”
可复用调查提示词:“在指定 PostHog 项目中,检验新用户激活是否在版本 X 发布后下降。使用项目时区,明确激活定义,排除内部用户,按平台拆分,并比较长度相同且已经结束的周期。检查仓库中的事件上报与身份代码,但不要修改文件或 PostHog 资源。返回查询定义、证据、局限、可能原因和最小验证方案。”
Useful starting investigations适合从哪里开始
- Instrumentation drift: compare event names and required properties in code with recently observed schema and volume.
- Feature-flag cleanup: find flag references in the repository, then verify rollout, exposure, experiment, and activity state before removing code.
- Funnel regression: identify the first changed step, segment the drop, and connect it to releases or capture changes instead of rewriting the full flow.
- Error prioritization: combine recurrence, affected users, route, release, and stack evidence with the local implementation before proposing a fix.
- 埋点定义漂移:对照代码中的事件名和必填属性,检查近期实际数据结构与数量是否发生变化。
- 功能开关清理:先找出仓库中的开关引用,再核对发布比例、曝光、实验和活跃状态,之后才能删除代码。
- 漏斗转化下降:找到第一个明显变化的步骤,按用户群拆分,再结合版本发布或埋点变更分析,不要直接重写整套流程。
- 错误优先级:综合复现频率、受影响用户、路由、版本和堆栈证据,再结合本地实现提出修复。
Protect privacy and analytical reproducibility同时保护隐私与分析可复现性
Product analytics can contain identifiers, URLs, text properties, recordings, error details, and organization-specific metadata. Give Claude Code only the minimum resources needed for the question, avoid requesting raw person-level data when aggregated evidence is enough, and never copy secrets or sensitive payloads into prompts. Read-only access should be the default, but it still deserves governance.
产品分析中可能包含用户标识、URL、文本属性、录屏、错误详情和组织元数据。Claude Code 只应读取当前问题必需的资源;汇总证据足够时,不要请求原始用户级数据;密钥或敏感载荷绝不能复制进提示词。只读应作为默认设置,但只读数据同样需要治理。
Prefer counts, grouped trends, funnels, and anonymous cohorts. Request individual events only when the diagnosis cannot be completed otherwise.
Retain project ID, timezone, event definitions, filters, breakdowns, date boundaries, sampling, and generated query—not only the final number.
Changing a flag or experiment can affect live users. Show current state, proposed state, rollout population, guardrails, owner, and rollback before approval.
Validate launch, rollback, pricing, privacy, or high-impact product decisions in the PostHog interface with an accountable reviewer.
优先使用计数、分组趋势、漏斗和匿名群组。只有无法通过汇总数据完成诊断时,才请求单条事件。
保留项目 ID、时区、事件定义、筛选器、拆分维度、日期边界、采样和生成查询,不要只保存最终数字。
修改开关或实验可能直接影响线上用户。批准前应展示当前状态、目标状态、发布人群、护栏、负责人和回退方案。
涉及发布、回滚、定价、隐私或高影响产品决策时,应由责任人在 PostHog 界面再次确认。
When two counts disagree, compare them systematically: host and project, timezone, inclusive versus exclusive date bounds, event versus unique-user aggregation, property type, test-account filters, identity merge behavior, ingestion delay, sessionization, sampling, and event-definition changes. Do not “fix” the code until the queries are actually equivalent.
两组数字不一致时,应系统对照:主机与项目、时区、日期边界是否含首尾、按事件还是按独立用户聚合、属性类型、测试账号过滤、身份合并逻辑、入库延迟、会话划分、采样和事件定义变化。在确认两条查询真正等价之前,不应贸然“修复”代码。
Use QVeris only when the investigation crosses systems只有跨系统调查时再接入 QVeris
PostHog MCP remains the direct supplier integration for PostHog product analytics. A live QVeris catalog search did not surface an exact PostHog Tool or Provider profile, so this page does not attach an unrelated result to the CTAs. When the investigation genuinely requires another API or live data source, review QVeris Docs and test the capability independently in the QVeris Playground.
PostHog 产品分析仍应通过 PostHog MCP 这一直接供应商集成完成。实时检索 QVeris 目录后,没有发现准确的 PostHog Tool 或 Provider 页面,因此本页不会把无关结果塞进 CTA。只有调查确实需要另一个 API 或实时数据源时,才应先阅读 QVeris 文档,再到 QVeris Playground 独立测试该能力。
- Keep PostHog as the provenance source for product behavior.
- Label every external dataset with its provider, timestamp, units, and join assumptions.
- Validate additional capabilities before combining their output with a PostHog conclusion or write action.
- 产品行为数据的来源继续以 PostHog 为准。
- 每个外部数据集都要标明供应商、时间、单位和连接假设。
- 把外部输出用于 PostHog 结论或写操作前,应先独立验证相应能力。
PostHog MCP for Claude Code FAQPostHog MCP 接入 Claude Code 常见问题
Use PostHog's current MCP documentation and official wizard. The former standalone PostHog/mcp repository is archived after the implementation moved into the monorepo.
No. MCP supports agent workflows; the UI remains important for visual exploration, sharing, permission checks, and confirmation of consequential decisions.
Start read-only. Add a specific write capability only when the workflow requires it, and approve the exact target and payload immediately before the call.
Check host, project, timezone, date boundaries, aggregation, filters, identity mode, ingestion delay, sampling, and event-definition drift.
Yes. It can compare repository references with PostHog flag state, but rollout, exposure, experiment status, dependencies, and rollback requirements need review before removal.
Yes. Trace the capture call, guards, consent, identity, property construction, network behavior, environment, and release timing, then test against a narrow PostHog query.
使用 PostHog 当前 MCP 文档与官方向导。原来的 PostHog/mcp 独立仓库在实现迁入主仓库后已经归档。
不会。MCP 服务于智能体流程;可视化探索、分享、权限核对和重大决策确认仍应使用 PostHog 界面。
应从只读开始。只有流程确实需要时才增加具体写能力,并在调用前核对准确目标与内容。
检查主机、项目、时区、日期边界、聚合方式、筛选器、身份模式、入库延迟、采样和事件定义漂移。
可以。它能把仓库引用与 PostHog 开关状态对照,但删除前仍要审查发布比例、曝光、实验状态、依赖和回退要求。
可以。依次追踪上报调用、条件判断、同意状态、身份、属性构造、网络、环境和发布时间,再用小范围 PostHog 查询核验。
References and next steps参考资料与下一步
PostHog MCP documentation
PostHog archived MCP repository
PostHog product analytics
PostHog feature flags
PostHog privacy guidance
Claude Code MCP documentation
QVeris Docs
QVeris Playground
PostHog MCP 文档
PostHog 已归档 MCP 仓库
PostHog 产品分析
PostHog 功能开关
PostHog 隐私指南
Claude Code MCP 文档
QVeris 文档
QVeris Playground
