Note: This is an independent, community-built project. It is not affiliated with, endorsed by, or maintained by PostHog Inc. For PostHog's official CLI, see posthog/posthog/cli.
A full-featured command-line interface for PostHog — the open-source product analytics platform. Manage feature flags, experiments, surveys, dashboards, insights, error tracking, logs, and more, all from your terminal.
Built with AI agents in mind: every command supports --json output, --yes for non-interactive use, and a raw posthog api escape hatch for anything the CLI doesn't cover yet.
PostHog's official CLI focuses on event capture, sourcemaps, and a handful of endpoints. This CLI covers the full product management surface — everything you can do in the PostHog UI, you can do here:
- Feature flags with rollout controls
- A/B experiments with results
- Surveys with response stats
- Dashboards and insights
- Error tracking
- Log querying
- HogQL queries and natural language query generation
- Person, group, event, and property search
- One-command product analytics summary
git clone https://github.com/nelsongallardo/posthog-cli.git
cd posthog-cli
python -m venv .venv
source .venv/bin/activate
pip install -e .pip install phog-cli# 1. Authenticate (auto-detects US/EU cloud)
posthog auth login
# 2. Pick your project
posthog project list
posthog project switch <project-id>
# 3. Get a full product health report
posthog activity summaryposthog auth loginYou'll be prompted for your Personal API Key. The CLI auto-detects whether your account is on US or EU cloud. For self-hosted instances, pass --host:
posthog auth login --host https://posthog.yourcompany.comFor CI/CD, scripts, or AI agent workflows:
export POSTHOG_API_KEY="phx_..."
export POSTHOG_HOST="https://us.posthog.com" # or https://eu.posthog.com
export POSTHOG_PROJECT_ID="12345"posthog auth status
posthog auth logout| Command | Description |
|---|---|
posthog auth |
Login, logout, check auth status |
posthog org |
List and inspect organizations |
posthog project |
List, switch, and inspect projects |
posthog flag |
Create, list, update, delete feature flags |
posthog experiment |
Manage A/B experiments and view results |
posthog survey |
Create, manage surveys and view response stats |
posthog dashboard |
Manage dashboards and their tiles |
posthog insight |
Create, manage, and query saved insights |
posthog error |
Browse and manage error tracking issues |
posthog log |
Query logs with filters |
posthog query |
Run HogQL queries or generate SQL from natural language |
posthog search |
Search persons, groups, events, and properties |
posthog activity |
Quick analytics — active users, top events, product summary |
posthog api |
Raw API escape hatch (GET, POST, PATCH, DELETE) |
Every command supports --help for detailed usage.
# Full product health report (auto-discovers your events)
posthog activity summary
posthog activity summary --date-from -90d
# Active users
posthog activity users # weekly active users
posthog activity users --period daily
posthog activity users --period monthly
# Top events by volume
posthog activity events --date-from -30d
# Pageview trends
posthog activity pageviews --date-from -7d --interval dayThe activity summary command runs 8 queries in parallel and returns: WAU trends, all custom events with unique user counts, weekly trend breakdowns, traffic sources, top pages, and browser stats. One command, full product context.
# List all flags
posthog flag list
posthog flag list --active # only active flags
# Create a flag
posthog flag create \
--key new-checkout \
--name "New Checkout Flow" \
--rollout-percentage 50
# Update rollout
posthog flag update <id> --rollout-percentage 100
# Get details
posthog flag get <id>
# Delete
posthog flag delete <id># List experiments
posthog experiment list
# Create a draft
posthog experiment create \
--name "Button Color Test" \
--feature-flag-key button-color
# Launch / end
posthog experiment update <id> --launch
posthog experiment update <id> --end
# View results
posthog experiment results <id>
posthog experiment results <id> --refresh
# Delete
posthog experiment delete <id># List surveys
posthog survey list
# Create from inline JSON
posthog survey create \
--name "NPS Survey" \
--questions-json '[{"type": "rating", "question": "How likely are you to recommend us?", "scale": 10}]'
# Create from a file
posthog survey create --name "Feedback" --from-file survey.json
# Launch / stop
posthog survey update <id> --start
posthog survey update <id> --stop
# View response stats
posthog survey stats <id>
# Delete
posthog survey delete <id>posthog dashboard list
posthog dashboard get <id>
posthog dashboard create --name "KPIs"
posthog dashboard add-insight <dashboard-id> --insight-id <insight-id>
posthog dashboard delete <id>posthog insight list
posthog insight get <id>
posthog insight query <id> # execute the insight's saved query
posthog insight query <id> --refresh # force refresh
posthog insight delete <id>posthog error list
posthog error list --status active --search "TypeError"
posthog error get <issue-id>
posthog error update <issue-id> --status resolvedposthog log query --date-from -1d
posthog log attributes # list available log attributes# Run a HogQL query
posthog query run --hogql "SELECT event, count() FROM events GROUP BY event ORDER BY count() DESC LIMIT 10"
# Run from a JSON file (InsightVizNode format)
posthog query run --from-file my-query.json
# Generate HogQL from natural language
posthog query generate "show me the top 10 countries by pageviews"posthog search persons --search "john@example.com"
posthog search events --search "checkout"
posthog search groups
posthog search propertiesFor anything the CLI doesn't cover yet:
posthog api get /surveys/
posthog api post /query/ --data '{"query": {"kind": "HogQLQuery", "query": "SELECT 1"}}'
posthog api patch /feature_flags/123/ --data '{"active": false}'
posthog api delete /feature_flags/123/All api commands use the active project context and output raw JSON.
posthog --json <command> # Machine-readable JSON output
posthog --yes <command> # Skip all confirmation prompts
posthog --version # Show version
posthog --help # Show helpThe --json and --yes flags make this CLI composable and safe for automated workflows:
# AI agent workflow: get flag list as JSON, pipe to jq
posthog --json flag list | jq '.[] | select(.active) | .key'
# Non-interactive: delete without confirmation prompt
posthog --yes flag delete 123
# Full product context for an AI agent in one call
posthog --json activity summaryCredentials are stored at ~/.config/posthog-cli/config.json with 600 file permissions. The config file contains:
api_key— your PostHog Personal API Keyhost— API host (e.g.,https://eu.posthog.com)project_id— currently active project
Environment variables (POSTHOG_API_KEY, POSTHOG_HOST, POSTHOG_PROJECT_ID) take precedence over the config file.
git clone https://github.com/nelsongallardo/posthog-cli.git
cd posthog-cli
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
# Lint
ruff check src/
# Type check
mypy src/
# Test
pytestThis is an independent, community-driven project built on top of the PostHog REST API. It is not officially affiliated with or endorsed by PostHog Inc.
PostHog is an open-source product analytics platform that provides event tracking, feature flags, A/B testing, surveys, session replay, and more. Thanks to the PostHog team for building an incredible platform and providing a comprehensive, well-documented API that makes community tools like this possible.
MIT — see LICENSE for details.