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.
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 apigives you PostHog's API and MCP tool catalog as shell commands - Queries:
hog query runruns 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:
In GitHub Actions, install hog with the PostHog/setup-hog action:
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:
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:
Authentication
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:
- 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. - 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.
- Select your organization and project, and set what hog can do in each product area. The login only works in the project you select.
- Click Approve. hog sees the approval and finishes the login.

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 --waitto finish the login.
To ask for read access only, add --read-only. You can add write scopes later with hog auth add.
| Command | Description |
|---|---|
hog auth status | Shows 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 logout | Removes the login that commands in this folder use. --all removes every login |
hog auth migrate | Moves 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.
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 variable | Description |
|---|---|
HOG_PERSONAL_API_KEY | A personal API key with the scopes required for the commands you run |
HOG_PROJECT_ID | Your 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_HOST | PostHog 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.
Run hog config check to check the file.
Command reference
| Command | Description |
|---|---|
hog auth | Log in, add scopes, check, and log out. See Authentication |
hog ci setup | Asks an admin to trust this repository's CI jobs, so they use their OIDC token instead of a stored key |
hog api | List, 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-tracking | Inject, upload, and download debug symbols, and resolve releases. hog et is short for it |
hog endpoints | List, run, pull, diff, and push endpoints |
hog schema | Generate a typed SDK from your event definitions, and check that it's up to date |
hog skills | List, read, and add PostHog's agent skills |
hog mcp add | Connects PostHog's MCP server to your agent |
hog config | Check posthog.json, or print its schema |
hog upgrade | Updates hog |
hog feedback [message] | Sends feedback about hog or PostHog to the PostHog team |
hog commands | Lists 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.
| Option | Environment variable | Description |
|---|---|---|
--host <url> | HOG_HOST | PostHog host to connect to. Defaults to https://us.posthog.com |
-o, --output <format> | HOG_OUTPUT | text or json |
--raw | HOG_RAW | Prints a command's full result as JSON |
--debug | HOG_DEBUG | Prints each HTTP request to stderr |
--dotenv-file <path> | HOG_DOTENV_FILE | Reads credentials from a dotenv file when the environment has none |
--no-fail | HOG_NO_FAIL | Exits with code 0 when a command fails. Use with caution |
--skip-ssl-verification | HOG_SKIP_SSL_VERIFICATION | Accepts any TLS certificate. Use only with a self-signed, self-hosted PostHog |
--rate-limit <requests> | HOG_RATE_LIMIT | The most requests per minute. No limit by default |
--no-telemetry | HOG_NO_TELEMETRY | Sends 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 code | Meaning |
|---|---|
0 | The command worked |
1 | The command failed, or a check found problems |
2 | A usage error, such as an unknown option |
3 | A person has to act, such as to log in or approve in the browser |
4 | The 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:
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.
- 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. - Add this note to your agent's instructions file, such as
AGENTS.mdorCLAUDE.md:
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.
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:
If a tool you used before is gone, names change as the PostHog API evolves. Use search to find the current name:
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.





