agent-posthog

PostHog analytics CLI for AI agents

Language
Go
Version
0.13.2
License
PolyForm Perimeter 1.0.0
Category
CLI Tool

A PostHog CLI for read-heavy investigation: persons, events, event and property schema, HogQL, feature flags, dashboards, insights, session recordings and experiments. Named investigations answer a question directly — why is this user in this state, what is this flag actually doing — and the personal API key stays out of the agent's context.

Features

01

Named investigations — investigate user, investigate event and investigate flag return a worked answer rather than a pile of endpoint output

02

HogQL first-class — write and run queries directly, with async query submission you can wait on or cancel

03

Schema discovery — event definitions and property definitions, searchable, so a query can be written against what actually exists

04

The full read surface — persons, events, feature flags, dashboards, insights, session recordings and experiments

05

Keychain-first credentials — personal API keys are never printed back

06

LLM-safe setup — auth add --form opens a native OS dialog and returns only a redacted receipt

07

Sensible scoping — a profile carries host plus default org, project and environment; environment defaults to the project, so most setups only ever set --project

08

Multi-id gets do not lose the batch — an unresolvable id becomes an @unresolved line with exit 0; only command-level failures exit non-zero

09

Structured errors — fixable_by, a hint, and retry_after_seconds when PostHog rate-limits you

10

Raw API escape hatch for anything not yet wrapped

11

Mock server — mockposthog gives deterministic E2E fixtures, including invalid keys, missing scopes, rate limits and ambiguous flags

12

Single compiled Go binary — no runtime dependencies

Install

Homebrew

>_
$ brew install shhac/tap/agent-posthog

AI Agent Skill

>_
$ npx skills add shhac/agent-skills --skill agent-posthog --global

GitHub Release (macOS)

>_
$ curl -L https://github.com/shhac/agent-posthog/releases/latest/download/agent-posthog-darwin-arm64.tar.gz | tar xz

Go Install

>_
$ go install github.com/shhac/agent-posthog/cmd/agent-posthog@latest

Build from Source

>_
$ git clone https://github.com/shhac/agent-posthog.git && cd agent-posthog && make build

Getting Started

agent-posthog needs a PostHog personal API key, stored in a named profile with its host and default scope. When an LLM is guiding setup, prefer --form over --api-key: a native OS dialog asks for the key and the CLI returns only a redacted receipt.

01 · Add a profile without the key passing through chat

>_
$ agent-posthog auth add prod --form --host https://us.posthog.com

Then agent-posthog auth check prod to confirm it works.

02 · Discover your scope

>_
$ agent-posthog orgs list

Then projects list --org <org-id>. You rarely need environments list — a project's default environment shares the project's id.

03 · Set the defaults on the profile

>_
$ agent-posthog auth update prod --org <org-id> --project <project-id> --default

Override --env only when targeting a non-default environment.

04 · Find out what events exist before querying them

>_
$ agent-posthog schema events list --search signup

Schema first, then HogQL — writing a query against guessed event names is the usual way to get an empty result.

Usage

>_ Why is this user in this state?
$ agent-posthog investigate user user_123
>_ What is this flag actually doing?
$ agent-posthog investigate flag checkout-v2
>_ Find the events you can query
$ agent-posthog schema events list --search signup
>_ Run HogQL
$ agent-posthog query hogql "select event, count() from events group by event order by count() desc limit 20"
>_ Look up a person
$ agent-posthog persons list --search alice@example.com
>_ Inspect a feature flag
$ agent-posthog flags get checkout-v2
>_ Find a session recording
$ agent-posthog recordings list --limit 10
>_ Check an experiment
$ agent-posthog experiments list