PostHog CLI

hog is the PostHog CLI. Use it to work with PostHog from your terminal, your coding agents, local scripts, and CI/CD pipelines.

Using PostHog, not installing it

This page is about installing hog on your computer or in CI, so that you and your agents can work with PostHog from the command line. To add PostHog to your app or website, follow the installation guide.

  • API: hog api gives you PostHog's API and MCP tool catalog as shell commands
  • Queries: hog query run runs SQL against your data
  • Error tracking: Inject and upload source maps and other debug symbols
  • Endpoints and schemas: Keep endpoints as YAML files, and generate typed SDKs from your event schemas
  • Skills and MCP: Add PostHog's agent skills to a repository, and connect PostHog's MCP server to your agent

hog replaces posthog-cli. If you use posthog-cli, follow Migrate from posthog-cli to hog.

The CLI is open source. You can find the code in the hog directory of the PostHog repo.

Installation

Install hog, PostHog's CLI:

curl -fsSL https://posthog.com/install.sh | sh

In GitHub Actions, install hog with the PostHog/setup-hog action:

YAML
- uses: PostHog/setup-hog@v1

To run hog once without installing it, use npx hog.

The install script picks the build for your OS and processor, checks its checksum, and puts hog in ~/.local/bin. It tells you when that folder isn't on your PATH. Every install puts hog-worker, the program hog runs for error tracking files, next to hog. If you copy hog to another machine or image, copy both files.

Using Claude Code, Codex, or another coding agent? Follow Setup for agents.

Updating

To update hog, run:

Terminal
hog upgrade

If you installed with the install script, this downloads the new version and checks its checksum. If you installed with Homebrew or npm, it shows the command your package manager uses, such as brew upgrade hog, and runs it when you confirm. hog upgrade --check only says whether a newer version is out.

Shell completion

hog completion <shell> prints a script that completes commands and options when you press Tab, in bash, zsh, and fish. Homebrew installs it for you. Otherwise, save it once:

Terminal
echo 'eval "$(hog completion bash)"' >> ~/.bashrc # bash
hog completion zsh > "${fpath[1]}/_hog" # zsh
hog completion fish > ~/.config/fish/completions/hog.fish # fish

Authentication

Terminal
hog auth login

hog logs in with a device code, the same way you log in to a TV app. You approve the login in your browser, and hog never sees your password:

  1. hog asks where your PostHog account is hosted. Then it shows a link and a short code, such as WHHS-GRXP, and opens the link in your browser.
  2. In the browser, check that the code on the page is the same as the code in your terminal. The code connects the page to the hog that waits in your terminal. If the codes are different, or you didn't start this login, click Deny.
  3. Select your organization and project, and set what hog can do in each product area. The login only works in the project you select.
  4. Click Approve. hog sees the approval and finishes the login.
The page where you approve a hog login, with the code, the organization and project, and the permissions

hog stores a short-lived token for that project in your system keychain, and renews it automatically. It also writes the host and project to posthog.json in the current folder.

The code expires if nobody approves it in time. To get a new one, run hog auth login again.

Because you approve in a browser, you can log in from anywhere hog runs:

  • Over SSH: hog shows the link but doesn't open a browser on the remote machine. Open the link on your own computer.
  • From an agent or a script: hog prints the link and the code, and exits. The agent gives them to you. After you approve, it runs hog auth login --wait to finish the login.

To ask for read access only, add --read-only. You can add write scopes later with hog auth add.

CommandDescription
hog auth statusShows whether hog is logged in, which login it uses, and why
hog auth add <scope...>Adds scopes to your login, such as hog auth add insight:write
hog auth logoutRemoves the login that commands in this folder use. --all removes every login
hog auth migrateMoves the login that posthog-cli saved into hog, so you don't have to log in again

For EU Cloud, pass --region eu. For self-hosted PostHog, pass --host <url>.

In CI/CD

In GitHub Actions, GitLab.com, and Depot CI, hog logs in with the job's OIDC token, so you don't store a key in CI. Run hog ci setup once in the repository, with the scopes that the job's commands need. An organization admin then approves it in PostHog.

Terminal
hog ci setup --scope error_tracking:write

To give several scopes, separate them with commas, as in --scope error_tracking:write,query:read. hog commands -o json lists the scopes that each command needs.

In other CI providers, and in headless environments, set environment variables instead:

Environment variableDescription
HOG_PERSONAL_API_KEYA personal API key with the scopes required for the commands you run
HOG_PROJECT_IDYour PostHog project ID. This is the number in your project URL, such as 12345 in https://us.posthog.com/project/12345. You can also set projectId in posthog.json
HOG_HOSTPostHog host to connect to. Defaults to https://us.posthog.com. Use https://eu.posthog.com for EU Cloud

posthog.json

hog reads project settings from posthog.json, from the current folder up to the git root. The closest one wins. It holds the host and projectId, and settings for error tracking, endpoints, and schemas. It never holds API keys, so you can commit it.

JSON
{
"$schema": "https://raw.githubusercontent.com/PostHog/posthog/master/hog/posthog.schema.json",
"host": "https://us.posthog.com",
"projectId": 12345
}

Run hog config check to check the file.

Command reference

CommandDescription
hog authLog in, add scopes, check, and log out. See Authentication
hog ci setupAsks an admin to trust this repository's CI jobs, so they use their OIDC token instead of a stored key
hog apiList, search, and call the PostHog MCP tools from the shell
hog query run <query>Runs a SQL query. hog query check checks a query without running it
hog error-trackingInject, upload, and download debug symbols, and resolve releases. hog et is short for it
hog endpointsList, run, pull, diff, and push endpoints
hog schemaGenerate a typed SDK from your event definitions, and check that it's up to date
hog skillsList, read, and add PostHog's agent skills
hog mcp addConnects PostHog's MCP server to your agent
hog configCheck posthog.json, or print its schema
hog upgradeUpdates hog
hog feedback [message]Sends feedback about hog or PostHog to the PostHog team
hog commandsLists every command, with its arguments, options, and scopes

Run hog <command> --help for every option of a command.

Global options

These options work with any command, before or after it. Each one also has an environment variable.

OptionEnvironment variableDescription
--host <url>HOG_HOSTPostHog host to connect to. Defaults to https://us.posthog.com
-o, --output <format>HOG_OUTPUTtext or json
--rawHOG_RAWPrints a command's full result as JSON
--debugHOG_DEBUGPrints each HTTP request to stderr
--dotenv-file <path>HOG_DOTENV_FILEReads credentials from a dotenv file when the environment has none
--no-failHOG_NO_FAILExits with code 0 when a command fails. Use with caution
--skip-ssl-verificationHOG_SKIP_SSL_VERIFICATIONAccepts any TLS certificate. Use only with a self-signed, self-hosted PostHog
--rate-limit <requests>HOG_RATE_LIMITThe most requests per minute. No limit by default
--no-telemetryHOG_NO_TELEMETRYSends no anonymous usage data

Output and exit codes

hog prints tables for a person at a terminal, and JSON for an agent, a pipe, or a script. A script that reads hog's output should pass -o text or -o json, so the format doesn't depend on where it runs.

Exit codeMeaning
0The command worked
1The command failed, or a check found problems
2A usage error, such as an unknown option
3A person has to act, such as to log in or approve in the browser
4The work started and is still running. The output names the --wait command that continues it

Using the CLI with a coding agent

PostHog supports both CLI and MCP interfaces for agent workflows. You usually only need one, and which one you choose depends on how you want the agent to interact with PostHog.

hog detects when a coding agent runs it, and gives the agent JSON output, errors with hints, and links for you to approve instead of prompts.

When to use the CLI

The CLI interface is familiar to agents and allows for composability, so it's more useful for scripting and deterministic flows. It can be more token-efficient when working with large datasets because the agent can stream, filter, aggregate, or sample data before it enters the model context.

When to use the MCP

MCP is useful when you're working with an AI agent that doesn't have access to terminal or shell commands. This is especially important in non-coding environments, where the agent may support tool calling but doesn't have access to a terminal.

MCP is also preferred when you want a native tool-calling experience, you need typed tool calls and results, and your workflows are happening in an AI client rather than script, CI, or shell.

To connect the MCP server to your agent, run:

Terminal
hog mcp add

Setup for agents

Agents are unlikely to automatically know that our CLI tool exists or that it's available to them, so we need to make them aware of it.

  1. Install hog and log in. An agent can do both. When an agent runs hog auth login, hog gives it a link for you to approve.
  2. Add this note to your agent's instructions file, such as AGENTS.md or CLAUDE.md:
markdown
## PostHog
Use `hog`, the PostHog CLI, for PostHog tasks, such as querying data, managing feature flags, or uploading source maps.
- `hog commands -o json` lists every command, with its options and the scopes it needs.
- `hog skills search <keywords>` finds a step-by-step guide for a task, and `hog skills read <skill>` reads it.
- When a command needs a login or a scope, its error names the `hog auth` command to run.

Skills

Skills add task-specific instructions for common PostHog workflows. You don't need to install them upfront: agents can read a skill with hog when they need it.

Terminal
hog skills list # every skill
hog skills search session replay # find skills by keywords
hog skills read <skill> # read a skill
hog skills add <skill> # copy a skill into this repository

hog skills add writes to the folder your agent reads, such as .claude/skills/ for Claude Code or .agents/skills/ for most other agents. To refresh a skill you added, add it again with --force.

FAQ

My agent doesn't know about the CLI

Agents only use hog if their instructions tell them to. Add the note from Setup for agents to your agent's instructions file.

If the note is there but the agent still ignores hog, check that your agent reads that file. Most coding agents, including Claude Code and Codex, read AGENTS.md.

The tool list looks outdated

hog downloads the newest tool catalog from PostHog once a day. To download it now, run:

Terminal
hog api refresh

If a tool you used before is gone, names change as the PostHog API evolves. Use search to find the current name:

Terminal
hog api search dashboard

A command says hog is out of date

hog warns when a newer version is out, or when your version has a known problem. Run hog upgrade.

Still have questions?

Was this page useful?