# CLI reference

> Complete matrix of pitafix CLI commands, flags, --json outputs, exit codes, and environment variables.

Binary paths live in [Start here](https://pitafix.app/wiki/agents/index.md#helper-binary). Run `pitafix help` or `pitafix help <command>` for live usage from the installed binary.

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success (or `-h` / `--help`) |
| `1` | Runtime error (missing git root commit, store/IO error, capture or doctor failure) |
| `2` | CLI usage error (unknown command, bad flag, missing positional argument) |
| `3` | Tree-sitter parser library unavailable (`pitafix index` when `libpitafix-ts` cannot load) |

## Command matrix

| Command | Flags | `--json` | Purpose |
| --- | --- | --- | --- |
| `pitafix record run` | `--project`, `--config`, `--commit`, `--diff-scoped`, `--no-replace`, `--timeout`, `--browser`, `--cef-host`, `--allow-host`, `--json`, `-- <command...>` | Yes | Starts authenticated localhost recorder, runs `.pitafix/capture.json` (or `--config` / `-- <command>`), and ingests traces. |
| `pitafix record serve` | `--project`, `--browser`, `--cef-host`, `--allow-host`, `--json` | Yes | Starts standalone recording daemon; `--json` prints one-line `{url, token, attributionUrl}`. |
| `pitafix ingest <dir>...` | `--project`, `--json` | Yes | Ingests one or more Level-0 `pitafix.trace/1` run folders into the project store. |
| `pitafix affected` | `--project`, `--from`, `--since`, `--to`, `--json` | Yes | Maps git changes onto affected journeys, screens, and newly dark files. |
| `pitafix map` | `--project`, `--section`, `--json` | Yes | Shows behavioral areas, totals, freshness, and unreached routes. |
| `pitafix ops` | `--project`, `--category`, `--section`, `--query`, `--limit`, `--json` | Yes | Lists canonical operations (`op_<hex>`). |
| `pitafix op <id>` | `--project`, `--tier`, `--include-ui`, `--limit`, `--json` | Yes | Inspects one operation's outcomes, UI triggers, tiered code, and server effects. |
| `pitafix components` | `--project`, `--platform`, `--device`, `--kind`, `--finds`, `--limit`, `--read`, `--at`, `--since`, `--intend`, `--reason`, `--unintend`, `--json` | Yes | Analyzes screenshots, lists UI components/finds, diffs commits, or marks finds intentional. |
| `pitafix component <name>` | `--project`, `--platform`, `--device`, `--kind`, `--read`, `--json` | Yes | Inspects one component's call sites, undrawn calls, visual states, and state-specific code. |
| `pitafix scale` | `--project`, `--platform`, `--device`, `--measure`, `--limit`, `--json` | Yes | Lists kept visual scale values (`gap`, `corner`, `text`, `fill`, `ink`) and departures. |
| `pitafix hot` | `--project`, `--tier`, `--repo`, `--sample`, `--limit`, `--json` | Yes | Ranks non-accessor symbols by share of sampled steps. |
| `pitafix dark` | `--project`, `--prefix`, `--repo`, `--include-tests`, `--exact`, `--limit`, `--json` | Yes | Lists tracked source files with zero captured execution plus unreached routes. |
| `pitafix blueprint import <path>` | `--json` | Yes | Validates and stores an immutable SHA-256 verified blueprint folder or archive. |
| `pitafix blueprint list` | `--json` | Yes | Lists imported blueprints and versions. |
| `pitafix blueprint attach <id>` | `--project`, `--version`, `--stack`, `--module`, `--json` | Yes | Attaches a blueprint to a project (auto-detects stacks when `--stack` omitted). |
| `pitafix blueprint show` | `--project`, `--json` | Yes | Prints the project's attached blueprint, active stacks/modules, rules, and gates. |
| `pitafix blueprint detach` | `--project`, `--json` | Yes | Detaches the active blueprint from a project. |
| `pitafix blueprint remove <id>` | `--version`, `--json` | Yes | Removes an imported blueprint version from the local library. |
| `pitafix mcp` | `--project`, `--agent`, `--run`, `--record`, `--browser`, `--cef-host`, `--allow-host` | N/A | Serves the stdio MCP server for coding agents (`--record` adds live recording tools). |
| `pitafix lsp` | `--stdio`, `-v` | N/A | Serves the read-only stdio LSP 3.17 server for the VS Code and Zed extensions. |
| `pitafix doctor` | `--project`, `--scope`, `--json` | Yes | Checks local toolchains and prints fixes for missing tools. |
| `pitafix index <dir>` | `--db`, `--rebuild`, `--jobs`, `--max-file-size`, `--parse-timeout`, `--serve`, `--parse-worker`, `--json` | Yes | Indexes repository symbols with tree-sitter, reparsing only changed git blobs. |
| `pitafix grants` | `--json` | Yes | Lists active and revoked trust grants and their keys. |
| `pitafix revoke <key>` | (none) | No | Revokes a trust grant by key while preserving its audit record. |
| `pitafix gc` | `--dry-run`, `--cache-only`, `--vacuum`, `--prune-empty-projects`, `--prune-grants`, `--all-cache`, `--json` | Yes | Reports and reclaims obsolete PitaFix data and cache storage. |

## Environment variables

### Store, cache & agent identity

| Variable | Default / Meaning |
| --- | --- |
| `PITAFIX_DATA_DIR` | Default `~/Library/Application Support/PitaFix` (stores, blobs, sidecars, blueprints) |
| `PITAFIX_CACHE_DIR` | Default `~/Library/Caches/pitafix` (build/capture throwaway copies, CEF archive) |
| `PITAFIX_AGENT` | Fallback agent actor name for `pitafix mcp` when `--agent` is omitted (default `"agent"`) |
| `PITAFIX_TS_LIBRARY` | Explicit path to `libpitafix-ts.dylib` / `libpitafix-ts.dll` for tree-sitter indexing |

### Passed by `pitafix record run` to capture scripts

| Variable | Meaning |
| --- | --- |
| `PITAFIX_RECORDER_URL` | Localhost recorder base URL (for example `http://127.0.0.1:54321`) |
| `PITAFIX_RECORDER_TOKEN` | Bearer token required on every recorder HTTP request |
| `PITAFIX_ATTRIBUTION_URL` | Endpoint for backend execution probes (`$PITAFIX_RECORDER_URL/v1/attribution`) |
| `PITAFIX_PROJECT_ROOT` | Absolute path to the target repository |
| `PITAFIX_TRACES_DIR` | Per-run directory where Level-0 `pitafix.trace/1` folders are auto-ingested on script exit |
| `PITAFIX_DIFF_SCOPED` | `"1"` on diff-scoped runs; empty on full captures |
| `PITAFIX_AFFECTED_JOURNEYS` | Comma-separated journey IDs impacted by the diff (may be empty) |
| `PITAFIX_CHANGED_FILES` | Comma-separated repo-relative changed file paths on diff-scoped runs |
| `PITAFIX_COMMIT` | Commit SHA being captured |
| `PITAFIX_LIVE` | `"1"` when launched for a Live interactive hand-over (use `POST /v1/sessions/{id}/hold`) |
