PostHog CLI
$ posthog-cli Official Low RiskPostHog CLI (posthog-cli) is PostHog's fast Rust CLI built primarily for CI/CD source map injection/uploading (sourcemap inject, sourcemap upload) for PostHog Error Tracking alongside authenticated project tasks. It distributes cleanly via @posthog/cli, Homebrew, or Cargo.
brew install posthog/tap/posthog-cli Use posthog-cli in build/CI steps to inject and upload source maps (sourcemap inject/upload); use PostHog MCP for querying HogQL analytics, insights, and feature flags.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Fast Rust CLI designed for non-interactive CI/CD pipelines via POSTHOG_CLI_TOKEN, though focused on build/sourcemap workflows rather than JSON analytics querying.
- Non-interactive env-var auth (
POSTHOG_CLI_TOKEN,POSTHOG_CLI_ENV_ID) - Narrower command surface than PostHog's REST API
Scoped personal API tokens and local-first sourcemap inject keep destructive blast radius very low.
sourcemap injectonly modifies local build output before optional upload- Scoped
POSTHOG_CLI_TOKENlimits permissions
Prebuilt Rust binary available via @posthog/cli on npm, Homebrew tap, Cargo, and install script.
npm install -g @posthog/cli,brew install posthog/tap/posthog-cli,cargo install posthog-cli
Solves PostHog Error Tracking source map symbolication cleanly, though analytics queries belong in HogQL/API/MCP.
- Purpose-built for
sourcemap injectandupload
Official PostHog tool developed inside PostHog/posthog under MIT.
- Official PostHog GitHub monorepo
Documented under PostHog Error Tracking source-map upload guides.
- Official docs at posthog.com/docs/cli
Security, Auth & Guardrails
Stores CLI session credentials via posthog-cli login in user config directories or reads POSTHOG_CLI_TOKEN / POSTHOG_CLI_ENV_ID from environment variables.
CLI is free (MIT); PostHog provides a generous free monthly tier across analytics and error tracking.
# PostHog CLI Agent Rules - Run `posthog-cli sourcemap inject` on `./dist` before `upload`, and verify `--project` / `POSTHOG_CLI_ENV_ID` targets staging vs production. - Keep `POSTHOG_CLI_TOKEN` scoped with Error Tracking write permissions only. - Do not upload unredacted build artifacts containing embedded secrets.
Agent-Ready Command Recipes
Safe Read-Only Queries
posthog-cli --version
Prints the installed posthog-cli binary version without making network calls.
posthog-cli sourcemap --help
Lists available source map injection and upload flags locally.
Controlled Writes & Previews
posthog-cli sourcemap inject --directory ./dist
Annotates local JS bundles and source maps in ./dist with chunk IDs without uploading to PostHog.
Strengths for Agents
- + Fast Rust binary with wide distribution (
@posthog/cli, Homebrew, Cargo). - + Separates local
sourcemap injectfrom remotesourcemap uploadcleanly. - + Headless CI auth via
POSTHOG_CLI_TOKENandPOSTHOG_CLI_ENV_ID.
Caveats & Pitfalls
- ! Command surface is still relatively narrow (centered on source maps and auth) compared to PostHog's full API.
- ! Analytics queries and feature-flag evaluations are better handled via PostHog MCP or API.