| name | posthog-cli |
| description | Manage PostHog via CLI - dashboards, insights, events, persons, feature-flags, queries, annotations, actions, cohorts, exports. Use when user mentions 'posthog', 'analytics dashboard', 'pageviews', 'feature flags', 'HogQL query', 'event tracking', 'funnel analysis', 'cohort', 'insight', or wants to interact with PostHog analytics data. |
| category | analytics |
posthog-cli
Manage PostHog analytics via CLI. Supports dashboards, insights, events, persons, feature flags, HogQL queries, annotations, actions, cohorts, and exports.
Auth
posthog-cli auth set "<personal-api-key>"
posthog-cli auth set "<key>" --env 24134
posthog-cli auth test
posthog-cli config list-projects --json
posthog-cli config set-env <id>
Resources
dashboards
| Command | Description |
|---|
posthog-cli dashboards list --json | List all dashboards |
posthog-cli dashboards list --limit 5 --json | List with limit |
posthog-cli dashboards get <id> --json | Get a dashboard by ID |
posthog-cli dashboards create --name "My Dashboard" --json | Create a dashboard |
posthog-cli dashboards create --name "Tagged" --tags "marketing,ads" --pinned --json | Create with tags and pin |
posthog-cli dashboards update <id> --name "New Name" --json | Update a dashboard |
posthog-cli dashboards delete <id> --json | Soft-delete a dashboard |
posthog-cli dashboards sharing <id> --json | Get sharing config |
posthog-cli dashboards copy-tile <target-id> --from <source-id> --tile <tile-id> --json | Copy tile between dashboards |
insights
| Command | Description |
|---|
posthog-cli insights list --json | List all insights |
posthog-cli insights list --search "pageview" --json | Search insights by name |
posthog-cli insights list --saved --json | List saved insights only |
posthog-cli insights get <id> --json | Get an insight by ID |
posthog-cli insights create --name "My Insight" --json | Create an insight |
posthog-cli insights create --name "Trends" --query '{"kind":"InsightVizNode","source":{"kind":"TrendsQuery","series":[{"kind":"EventsNode","event":"$pageview"}]}}' --json | Create with query |
posthog-cli insights update <id> --name "Updated" --json | Update an insight |
posthog-cli insights delete <id> --json | Soft-delete an insight |
posthog-cli insights activity <id> --json | Get activity log |
events
| Command | Description |
|---|
posthog-cli events list --json | List recent events |
posthog-cli events list --event "\$pageview" --limit 10 --json | List pageview events |
posthog-cli events list --person-id <id> --json | List events for a person |
posthog-cli events list --after "2024-01-01" --json | List events after date |
posthog-cli events get <id> --json | Get a single event |
posthog-cli events values --event "\$pageview" --property "\$browser" --json | Get property values |
persons
| Command | Description |
|---|
posthog-cli persons list --json | List persons |
posthog-cli persons list --search "user@email.com" --json | Search persons |
posthog-cli persons get <uuid> --json | Get a person by UUID |
posthog-cli persons delete <uuid> --json | Delete a person |
posthog-cli persons properties --json | List all person property keys |
feature-flags
| Command | Description |
|---|
posthog-cli feature-flags list --json | List all feature flags |
posthog-cli feature-flags list --active --json | List active flags only |
posthog-cli feature-flags list --search "beta" --json | Search flags |
posthog-cli feature-flags get <id> --json | Get a flag by ID |
posthog-cli feature-flags create --key "new-feature" --name "New Feature" --active --json | Create a flag |
posthog-cli feature-flags create --key "gradual" --name "Gradual Rollout" --rollout-percentage 50 --json | Create with rollout % |
posthog-cli feature-flags update <id> --active true --json | Enable a flag |
posthog-cli feature-flags update <id> --rollout-percentage 100 --json | Set rollout to 100% |
posthog-cli feature-flags delete <id> --json | Delete a flag |
queries
| Command | Description |
|---|
posthog-cli queries run --query "SELECT event, count() FROM events GROUP BY event ORDER BY count() DESC LIMIT 10" --json | Run a HogQL query |
posthog-cli queries run --query "SELECT properties.\$browser, count() FROM events WHERE event='\$pageview' GROUP BY 1" --json | Query by browser |
posthog-cli queries events --event "\$pageview" --limit 50 --json | Quick event query |
posthog-cli queries trends --event "\$pageview" --interval day --date-from "-30d" --json | Trends query |
posthog-cli queries trends --event "\$pageview" --math dau --json | DAU trends |
posthog-cli queries funnels --events "\$pageview,sign_up,purchase" --json | Funnel analysis |
annotations
| Command | Description |
|---|
posthog-cli annotations list --json | List all annotations |
posthog-cli annotations get <id> --json | Get an annotation |
posthog-cli annotations create --content "Deploy v2.0" --date "2024-03-15T00:00:00Z" --json | Create annotation |
posthog-cli annotations update <id> --content "Updated note" --json | Update annotation |
posthog-cli annotations delete <id> --json | Delete annotation |
actions
| Command | Description |
|---|
posthog-cli actions list --json | List all actions |
posthog-cli actions get <id> --json | Get an action |
posthog-cli actions create --name "Sign Up Click" --json | Create an action |
posthog-cli actions update <id> --name "Updated Action" --json | Update an action |
posthog-cli actions delete <id> --json | Delete an action |
cohorts
| Command | Description |
|---|
posthog-cli cohorts list --json | List all cohorts |
posthog-cli cohorts get <id> --json | Get a cohort |
posthog-cli cohorts create --name "Power Users" --json | Create a cohort |
posthog-cli cohorts create --name "Static List" --is-static --json | Create static cohort |
posthog-cli cohorts delete <id> --json | Delete a cohort |
exports
| Command | Description |
|---|
posthog-cli exports list --json | List all exports |
posthog-cli exports create --dashboard <id> --format-type "image/png" --json | Export dashboard as PNG |
posthog-cli exports create --insight <id> --format-type "text/csv" --json | Export insight as CSV |
Quick Reference
posthog-cli --help
posthog-cli <resource> --help
posthog-cli <resource> <action> --help
Global flags: --json, --format <text|json|csv|yaml>, --verbose, --no-color, --no-header, --env <id>
Output Format
--json returns a standardized envelope:
{ "ok": true, "data": { ... }, "meta": { "total": 42 } }
On error: { "ok": false, "error": { "message": "...", "status": 401 } }