Migrate from posthog-cli to hog

The CLI docs are moving to hog

posthog-cli is deprecated and has been replaced by hog. We're rewriting the CLI docs for hog. Until then, the other CLI pages describe posthog-cli, and this guide maps each posthog-cli command, flag and variable to hog.

hog is the successor to posthog-cli. It does what posthog-cli does, with new command names, HOG_ environment variables, and output that agents can read.

Let your coding agent move the repository

Open your coding agent in the repository and give it this prompt:

text
Fetch https://posthog.com/docs/cli/migrating.md
and follow it to move this repository from posthog-cli to hog.

It finds every place posthog-cli runs, makes the changes, and stops when it needs you, for example to approve a login.

The steps move one repository: its scripts, its CI and the machine you work on. The sections after the steps are the reference: every variable, command and flag that changed.

The goal

  • Nothing in the repository runs posthog-cli, depends on @posthog/cli, or reads a POSTHOG_CLI_ variable.
  • The build uploads the same symbols with hog. hog sends the same bytes and content hashes, so keep the release names, paths and settings as they are.
  • In GitHub Actions, GitLab.com and Depot CI, the job logs in with its OIDC token instead of a stored personal API key.
  1. Find where posthog-cli runs

    Search the whole repository, including hidden folders:

    Terminal
    git grep -n -E 'posthog-cli|@posthog/cli|POSTHOG_CLI_|POSTHOG_CLIENT_RATE_LIMIT|POSTHOG_RELEASE_MODE|POSTHOG_HOME|PostHog/resolve-release'

    Look in particular at:

    • package.json: @posthog/cli as a dependency, and scripts that call posthog-cli. Leave lockfiles to the package manager.
    • CI config: .github/workflows/, .gitlab-ci.yml, .depot/workflows/, .circleci/, bitbucket-pipelines.yml, Jenkinsfile, vercel.json, netlify.toml.
    • Build scripts: Dockerfiles, Makefiles, shell scripts, Fastlane lanes, Gradle tasks and Xcode build phases.
    • Environment files: .env*, and any file passed with --dotenv-file.
    • The names of CI secrets, such as POSTHOG_CLI_API_KEY. You can't read their values, and you don't need to.
    • PostHog/resolve-release@v1 in a GitHub Actions workflow. It runs posthog-cli inside the action, so it changes too.

    Also look for a PostHog build plugin: @posthog/nextjs-config, @posthog/webpack-plugin, @posthog/rollup-plugin, @posthog/nuxt, the com.posthog.android Gradle plugin, posthog-ios's upload-symbols.sh, or the posthog-react-native Xcode and Gradle scripts. A plugin runs the CLI for the build, so it changes differently.

    List what you found before you change anything, so the person can check it.

  2. Install hog

    Use the package manager the project already uses. Its lockfile tells you which one:

    npm install -D hog # add hog to the project (package-lock.json)
    npm install -g hog # install hog globally
    npx hog # run hog once

    Yarn 2 and later have no global installs, and Yarn 1 has no dlx, so use npm for those.

    When the project ran posthog-cli through @posthog/cli in package.json, remove @posthog/cli and add hog with that package manager, so the lockfile changes with it. When it installed posthog-cli globally in CI, install hog the same way, with the same package manager.

    A project without Node, or a machine without a project, can use Homebrew or the install script:

    brew install posthog/tap/hog
    hog is two files

    Every install puts hog-worker, the program hog runs for hog error-tracking, next to hog. posthog-cli is one file and hog is two, so a Dockerfile or CI cache that copied the posthog-cli binary must copy both hog and hog-worker into the same folder.

    hog upgrade replaces posthog-cli update.

    In GitHub Actions

    A workflow that installed posthog-cli with curl or a download step, outside a Node project, uses PostHog/setup-hog instead. It downloads the newest hog 1.x and hog-worker, checks them against the checksums of the hog release, caches them, and puts hog on PATH for the later steps:

    YAML
    - uses: PostHog/setup-hog@v1

    To control when hog changes, pin the version, and the checksum of each archive your runners use, from the SHA256SUMS of the hog release:

    YAML
    - uses: PostHog/setup-hog@v1
    with:
    version: 1.0.0
    sha256: <checksum of hog-linux-x64.tar.gz>

    A workflow that installs hog with the project's package manager doesn't need setup-hog.

  3. Log in on the machine

    • Run hog auth migrate when posthog-cli was logged in on this machine. It moves that login to hog.
    • Otherwise run hog auth login. An agent passes --region us or --region eu, or --host for self-hosted PostHog, after asking the person which. It gets a link and exit code 3: give the link to the person, and run hog auth login --wait once they approve.

    hog auth status shows which login hog uses and why.

  4. Log in from CI

    posthog-cli in CI almost always logs in with a personal API key, stored as a CI secret such as POSTHOG_CLI_API_KEY. That key is a poor fit for CI:

    • It acts as the person who created it, so everything CI does runs as them, and it stops working when they leave the organization.
    • It works until someone deletes it, so a copy that leaks, through a log or a compromised action, keeps working.
    • It often has more scopes and projects than the job needs, because a person made it for themselves.
    • Every workflow and person with access to the secret can use it.

    GitHub Actions, GitLab.com and Depot CI

    Use the job's OIDC token, so CI stores no key at all. The CI provider signs a token that says which repository, branch and workflow the run comes from. hog trades it for a PostHog token that lasts a few minutes, works in one project, has only the scopes an admin allowed, and only for the runs the admin allowed, such as pushes to main.

    1. In the repository, logged in, run hog ci setup --scope error_tracking:write. List every scope the job needs, like --scope error_tracking:write,query:read.
    2. hog asks which runs may get a token, such as pushes to main. An agent gets the presets PostHog offers: ask the person which one fits, and pass it with --preset.
    3. An organization admin approves the request in PostHog. This needs a person. hog ci setup --wait checks on it.
    4. Add the host and projectId that hog prints to posthog.json, and the snippet it prints to the job. The snippet lets the job get an OIDC token. For self-hosted PostHog, hog leaves the host out and says to set HOG_HOST in the job instead.
    5. Remove POSTHOG_CLI_API_KEY from the job. HOG_PERSONAL_API_KEY wins over OIDC, so don't set it either.

    Once a run passes with OIDC, the old key has nothing left to do: the person deletes it from the CI secrets, and deletes it under Personal API keys in their PostHog account settings if nothing else uses it.

    Every other CI provider

    These providers have no OIDC login for PostHog yet, so the job keeps a personal API key. Rename the variables the job sets, with the table below. The secret keeps its value. Only the variable the job sets changes, so the job can set HOG_PERSONAL_API_KEY from the same secret until someone renames it. Give the key only the error_tracking:write scope, or the scopes the job needs, and only the project it uploads to.

    PostHog/resolve-release

    PostHog/resolve-release finds or creates the error tracking release for a build, and outputs its ID. v1 runs posthog-cli with a personal API key. v2 runs hog with the job's OIDC token.

    To upgrade from v1 to v2:

    1. Change PostHog/resolve-release@v1 to PostHog/resolve-release@v2.
    2. Set hog-version to 1 for the newest hog 1.x, or to an exact version such as 1.0.0 with its checksum in hog-sha256, as in setup-hog.
    3. Add permissions: id-token: write to the job, and run hog ci setup --scope error_tracking:write once, as above.
    4. Remove the api-key input. Delete its secret once a run passes.
    5. Keep project-id, or move it and the host into posthog.json.
    diff
    jobs:
    build:
    + permissions:
    + id-token: write
    + contents: read
    steps:
    - id: release
    - uses: PostHog/resolve-release@v1
    + uses: PostHog/resolve-release@v2
    with:
    - api-key: ${{ secrets.POSTHOG_API_KEY }}
    + hog-version: 1
    project-id: ${{ vars.POSTHOG_PROJECT_ID }}

    v2 also puts hog on PATH, so later steps in the job can run it. A workflow that only needs hog, and doesn't use the release-id output, uses PostHog/setup-hog instead.

  5. Rewrite the commands

    Replace each command with the commands table, and check its flags against flags that changed. A script that reads hog's output passes -o text or -o json, as Output explains.

  6. Update build plugins

    Optional

    When a PostHog build plugin is the only thing that runs posthog-cli, update the plugin to a version that runs hog itself. The plugin config stays the same.

    PluginFirst version that runs hog
    @posthog/nextjs-config1.13.0
    @posthog/webpack-plugin1.9.0
    @posthog/rollup-plugin1.7.0
    @posthog/nuxt1.10.0
    com.posthog.android (Android Gradle plugin)1.9.0
    upload-symbols.sh (posthog-ios)4.3.0
    posthog-react-native (JavaScript source map scripts)4.89.0

    Older versions run posthog-cli and need personalApiKey, so keep the key until the plugin is on one of these versions. In GitHub Actions, GitLab.com and Depot CI, the plugin can then use the job's OIDC token too: run hog ci setup as in Log in from CI, then remove personalApiKey from the plugin config.

    The Android, iOS and React Native integrations run hog when it's installed, so install hog where the build runs, as in Install hog. Without hog, they keep running posthog-cli and warn that it's deprecated. React Native's native symbol uploads run through the posthog-ios and Gradle plugin versions the app resolves, so they follow those rows. To keep posthog-cli while hog is installed, set postHogExecutable = "posthog-cli" in the Android Gradle plugin. With OIDC, remove postHogApiKey from the Android Gradle plugin config.

    The plugins still read posthog-cli's environment variables, such as POSTHOG_RELEASE_MODE, and print a warning to rename each one, as in the table below.

  7. Check the result

    Checkpoint
    • The search from step 1 finds nothing, except the lockfile before the next install.
    • hog auth status shows a login, on the machine and in CI.
    • hog config check passes when the repository has a posthog.json.
    • hog error-tracking process <build output> --dry-run, or upload when the build injects chunk IDs itself, lists the same symbol sets posthog-cli uploaded, and sends nothing.
    • The CI job passes, and its upload step lists the symbol sets it uploaded.

Steps for a person

When your coding agent runs the migration, it stops and asks you to do these, because an agent can't:

  • Approve the browser login from hog auth login.
  • Approve hog ci setup in PostHog. It needs an organization admin.
  • Delete POSTHOG_CLI_API_KEY from the CI secrets once a run passes with hog.
  • Delete the personal API key in PostHog when nothing else uses it.

Reference

What stays the same

  • Your login. hog auth migrate moves the key posthog-cli login saved in ~/.posthog/credentials.json into hog's store. It checks the key with PostHog first, and a key PostHog rejects stays out of hog's store. hog doesn't read that file otherwise and never changes it.
  • Uploads. hog sends the same bytes and content hashes, so either CLI can re-upload what the other uploaded. Chunk IDs and releases don't change.
  • posthog.json. hog reads the languages entries posthog-cli exp schema writes, and the endpoint YAML files posthog-cli exp endpoints writes.
  • Global flags. --host, --dotenv-file, --no-fail, --skip-ssl-verification and --rate-limit work as before. posthog-cli took them only before the command, and hog also takes them after it.

Environment variables

hog doesn't read posthog-cli's variables. Rename these:

posthog-clihog
POSTHOG_CLI_API_KEY, POSTHOG_CLI_TOKENHOG_PERSONAL_API_KEY
POSTHOG_CLI_PROJECT_ID, POSTHOG_CLI_ENV_IDHOG_PROJECT_ID
POSTHOG_CLI_HOSTHOG_HOST
POSTHOG_CLI_ORGANIZATION_IDhog api call --organization-id
POSTHOG_CLI_DOTENV_FILEHOG_DOTENV_FILE
POSTHOG_CLI_DRY_RUNHOG_DRY_RUN
POSTHOG_CLIENT_RATE_LIMITHOG_RATE_LIMIT
POSTHOG_CLI_SOURCEMAP_UPLOAD_CONCURRENCYHOG_UPLOAD_CONCURRENCY
POSTHOG_RELEASE_MODEHOG_RELEASE_MODE
POSTHOG_HOMEHOG_HOME
POSTHOG_CLI_INSTALL_DIR, for the install scriptHOG_INSTALL_DIR

posthog-cli api also read POSTHOG_API_KEY, POSTHOG_HOST, POSTHOG_PROJECT_ID and POSTHOG_ORGANIZATION_ID. Apps often set these for other reasons, so rename them only where they were there for posthog-cli.

HOG_HOME moves only the ~/.posthog folder, where hog auth migrate finds posthog-cli's login. hog keeps its own settings, and its logins when there is no keychain, in another folder, as Credentials explains.

A dotenv file that --dotenv-file names needs the new names too. In CI, you can set both sets of names while some jobs still run posthog-cli.

Commands

posthog-clihog
loginauth login, plus auth status (or whoami), auth add for more scopes, and auth logout
updateupgrade
sourcemap inject --directory <dir>error-tracking inject <dir>
sourcemap upload --directory <dir>error-tracking upload <dir> --kind js. Without --kind, hog also uploads the native debug files it finds
sourcemap process --directory <dir>error-tracking process <dir> --kind js. Without --kind, hog also uploads the native debug files it finds
hermes inject --directory <dir>error-tracking inject <dir>
hermes clone -m <file1> -c <file2>error-tracking clone <file1> <file2>
hermes upload --directory <dir>error-tracking upload <dir>
dsym upload --directory <dir>error-tracking upload <dir>
proguard upload --path <file> --map-id <id>error-tracking upload <file> --map-id <id>
symbol-sets upload --directory <dir>error-tracking upload <dir>
exp hermes, exp proguard, exp dsymThe same as hermes, proguard and dsym above
symbol-sets download --id <id> -o <dir>error-tracking download <id> --output-dir <dir>
symbol-sets download --ref <ref>error-tracking download <ref>, with --ref when the ref looks like an ID
symbol-sets extract <file> -o <dir>error-tracking extract <file> --output-dir <dir>
release resolveerror-tracking release -o text
release resolve --jsonerror-tracking release -o json
exp query run <query>query run <query>
exp query check <query>query check <query>
exp endpoints list, get, open, run, diffendpoints list, get, open, run, diff. list shows one page, and --offset picks the next
exp endpoints pull -o <dir>endpoints pull --to <dir>
exp endpoints pushendpoints push
exp schema pull -o <file>schema pull --file <file>
exp schema statusschema status
api tools, search, info, schema, callapi tools, search, info, schema, call, with -o json for --json
api skill list, api skill install <id>skills list, skills add <skill...>. add takes any listed skill and writes to the folder your agent reads

hog et is short for hog error-tracking. hog error-tracking upload detects what each path holds, so one command uploads JavaScript, Hermes, ProGuard, dSYM and ELF symbols, and --kind skips detection. Run hog <command> --help for every flag, or hog commands -o json for all of them at once.

These posthog-cli commands don't come to hog. Remove them from scripts and CI, and tell the person when a repository depends on one:

  • api agents-md. hog setup writes the AGENTS.md note for a project it sets up.
  • exp logs import, exp task, and exp query editor.

Flags that changed

  • Paths are arguments. --directory, --path, -m and -c become positional arguments, and one command takes several paths.
  • -o is the output format. It takes text or json. posthog-cli's -o paths become --to in endpoints pull, --file in schema pull, and --output-dir in download and extract.
  • --stdin becomes -. hog error-tracking upload - and process - read one path per line from stdin, like --stdin did. inject has no stdin form, so pass its paths as arguments.
  • Old aliases are gone. Use --release-name for --project, and --release-version for --version. --file (for --directory) and --ignore (for --exclude) are gone with the flags they stood for.
  • --include and --exclude are gone. List the paths as arguments, or keep them in errorTracking.sources in posthog.json, where ignore globs skip files.
  • --skip-release-on-fail is gone. hog always retries without the release when PostHog says a chunk belongs to another release, as posthog-cli did.
  • --main-dsym is gone. hog takes the release from --release-name, --release-version, --info-plist, posthog.json or git.
  • dsym upload --no-release-bind is gone. hog has no such flag, so remove it from a script that passes it.
  • symbol-sets upload --source-root is gone, with no replacement.
  • endpoints run takes -o. --json and --format json become -o json, --format table becomes -o text, and -q is gone.
  • endpoints diff -v becomes --verbose. hog's diff has no short form for it.
  • --debug and --raw are global. --debug prints each request to stderr for every command, and --raw prints PostHog's whole response, as exp query check --raw did.

Dry runs

posthog-cli's --dry-run skipped uploads and release without doing anything. hog's --dry-run does the work and shows the result without changing anything: uploads list each symbol set with its content hash, and schema pull, endpoints pull and push show what they would change.

HOG_DRY_RUN=1 turns on --dry-run for every command that has one. Commands that only read run as usual. Commands that change something but have no dry run fail when HOG_DRY_RUN is set: auth login, auth logout, auth add, auth migrate, mcp add, setup, skills add and upgrade.

Output

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

Terminal
# before
RELEASE_ID=$(posthog-cli release resolve)
# after
RELEASE_ID=$(hog error-tracking release -o text)

posthog-cli exp query run prints one JSON array per row. hog query run -o json prints one object instead: columns, with the name and ClickHouse type of each, rows, as arrays in column order, and hasMore, which is true when PostHog cut the rows off. A script that read one row per line reads .rows instead:

Terminal
# before
posthog-cli exp query run "select event from events" | while read -r row; do echo "$row"; done
# after
hog query run "select event from events" -o json | jq -c '.rows[]' | while read -r row; do echo "$row"; done

--raw prints PostHog's whole response, as --debug did in posthog-cli.

posthog-cli waits for a query until PostHog finishes it. hog does the same at a terminal and in CI. An agent or a pipe outside CI waits up to a minute, then gets {"status":"running","queryId":"<query-id>","next":"hog query run --wait <query-id>","hint":"…"} and exit code 4. hog query run --wait <query-id> waits for that query again. A query that joins a run another caller named with an ID beyond letters, digits, _ and - waits until it finishes, as in posthog-cli.

Errors go to stderr, as JSON with a stable code in JSON mode. Each error also names the hog feedback command to report it, as a last line for a person and as feedback in the JSON. posthog-cli's errors don't.

Exit codes

posthog-cli exits with 1 for every failure, and with 0 when a check such as exp endpoints diff finds a problem. hog gives each outcome its own code, so a script can tell them apart without reading stderr:

What happenedposthog-clihog
The command worked00
The command failed11
A check found problems: errors in query check, drift in endpoints diff, a stale SDK in schema status01
A usage error22
A person has to act: log in, approve in the browser, add a scope, or answer a question13
The work started and is still running. The output names the --wait command that resumes itNot used4

--no-fail turns every failure into 0 in both CLIs. In hog that covers 1, 3 and 4. A usage error keeps code 2 in both. A pipeline that reads exit code 1 as "not logged in" reads 3 with hog.

posthog.json

hog reads more from posthog.json than posthog-cli did: the host, error tracking sources and release, the endpoints folder, and defaults for --no-fail and --rate-limit. When the file is invalid, every command stops except hog config check, which lists the problems, and hog config schema.

posthog-cli rewrites posthog.json with only languages when it pulls a schema, so it drops hog's settings. Run only hog's schema pull once a project uses hog settings.

Where hog writes

posthog-cli writes and deletes files wherever a repository's files point it. hog keeps those writes inside the project:

  • schema pull refuses an output_path in posthog.json outside the project, and any module path inside the repository that links out of it. A module outside the repository, such as ../web/typed.ts, needs --file on each run.
  • hog won't write a posthog.json that links out of its folder.
  • endpoints pull writes only inside the endpoints folder, and leaves alone a file there that links somewhere else. endpoints.dir in posthog.json must be inside the project.
  • error-tracking commands refuse a folder in errorTracking.sources that resolves outside the project, through .., an absolute path or a link.
  • error-tracking commands skip a bundle whose sourcemap is outside the selected paths, and never open that map, so they don't read, rewrite, upload or delete it. Pass the folder that holds the maps too.

A path you pass with --file, a file you name with --to, or a folder you pass to an error-tracking command can be anywhere.

Still have questions?

Was this page useful?