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
Named investigations — investigate user, investigate event and investigate flag return a worked answer rather than a pile of endpoint output
HogQL first-class — write and run queries directly, with async query submission you can wait on or cancel
Schema discovery — event definitions and property definitions, searchable, so a query can be written against what actually exists
The full read surface — persons, events, feature flags, dashboards, insights, session recordings and experiments
Keychain-first credentials — personal API keys are never printed back
LLM-safe setup — auth add --form opens a native OS dialog and returns only a redacted receipt
Sensible scoping — a profile carries host plus default org, project and environment; environment defaults to the project, so most setups only ever set --project
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
Structured errors — fixable_by, a hint, and retry_after_seconds when PostHog rate-limits you
Raw API escape hatch for anything not yet wrapped
Mock server — mockposthog gives deterministic E2E fixtures, including invalid keys, missing scopes, rate limits and ambiguous flags
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
$ agent-posthog investigate user user_123 $ agent-posthog investigate flag checkout-v2 $ agent-posthog schema events list --search signup $ agent-posthog query hogql "select event, count() from events group by event order by count() desc limit 20" $ agent-posthog persons list --search alice@example.com $ agent-posthog flags get checkout-v2 $ agent-posthog recordings list --limit 10 $ agent-posthog experiments list