Pi extension for querying PostHog from the pi coding agent.
This is the complement to @posthog/pi: that package sends pi agent telemetry to PostHog, while this package gives pi read-only tools for asking questions of PostHog.
posthog_query_hogql— run HogQL against a project.posthog_list— list projects, dashboards, insights, feature flags, experiments, annotations, cohorts, or persons.posthog_api_get— call a read-only PostHog APIGETpath that begins with/api/.
It also registers /posthog-status to show whether required environment variables are present without printing secrets.
pi install npm:@trycedar/pi-posthogOr install directly from GitHub before a release:
pi install git:github.com/trycedar0x/pi-posthogOr during local development:
pi -e ../pi-posthog/src/index.tsSet these environment variables before launching pi:
export POSTHOG_PERSONAL_API_KEY="phx_..." # required; personal API key, not project ingestion key
export POSTHOG_PROJECT_ID="12345" # required for project-scoped tools
export POSTHOG_HOST="https://us.posthog.com" # optional; use https://eu.posthog.com for EU CloudOptional:
export POSTHOG_MAX_RESPONSE_BYTES=40000POSTHOG_PERSONAL_API_KEY is preferred. POSTHOG_API_KEY is accepted as a fallback for convenience, but a project ingestion key (phc_...) cannot query the PostHog API.
What PostHog projects can I access?
Run a HogQL query for signups in the last 7 days.
List feature flags in PostHog.
Show dashboards in my PostHog project.
GET /api/projects/123/insights/?limit=5 from PostHog.
- The extension only performs
GETAPI requests plusPOST /api/projects/:id/query/for HogQL queries. posthog_api_getrejects paths that do not start with/api/.- Tool output is truncated to avoid flooding the model context.
- Do not put PostHog keys in source files; pass them through environment variables.
npm install
npm test
npm run typecheck
npm run release:dryMIT