# CLI reference

> Every kavach command and flag, the environment variables it reads, and its exit codes.

```text
kavach [--no-banner] <command> ...

  kavach list    [dir] [--json]
  kavach inspect <fixture> [--json] [--full]
  kavach replay  <fixture> --bin <host-command> [--until <seq>] [--probe <input>]... [--hold] [--json]
  kavach diff    <fixture> --old <host-command> --new <host-command> [--variants N] [--regressions N] [--keep DIR] [--json]
  kavach contract init|show|approve|check ...
  kavach map     [map.json] [fixture.kavach]... [flags]
  kavach mcp
  kavach version
```

A **host command** starts your service's own build in replay mode, in any language: `./ledger`, `"python -m ledger"`, `"node dist/main.js"`. It is split into words like a shell would, and `kavach-host` is appended. See [Concepts](https://www.thekavachlabs.com/docs/concepts#host-command).

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | The replay is `ok` or `fixed` (for `diff`, the verdict is `fixed`; for `contract check`, `pass`). |
| `1` | Any other verdict. |
| `2` | Usage error. |
| `3` | A fixture or binary cannot be used. |

## Environment

| Variable | Effect |
| --- | --- |
| `KAVACH_BIN` | Default for `--bin` on `replay` (not on `map`). |
| `KAVACH_RECORDER` | Path to `kavach-recorder`, used by every SDK. |
| `KAVACH_NO_BANNER=1` | Same as `--no-banner`. |
| `NO_COLOR=1` | No colour or styling. Piped output and `--json` are never styled. |

## `kavach list`

```text
kavach list [dir] [--json]
```

Finds every `*.kavach` under `dir` (default: the current directory), with each one's recorded failure.

## `kavach inspect`

```text
kavach inspect <fixture> [--json] [--full]
```

Prints the journal record by record: header, environment, each input with its reads and outputs, and the failure marker.

| Flag | Meaning |
| --- | --- |
| `--full` | Do not truncate data; show the panic stack and every environment fact. |
| `--json` | Print the decoded journal as JSON. |

## `kavach replay`

```text
kavach replay <fixture> --bin <host-command> [--until <seq>] [--probe <input>]... [--hold] [--json]
```

Re-runs a fixture on a build and reports a [verdict](https://www.thekavachlabs.com/docs/reference/verdicts). Reads are answered from the fixture; outputs are compared with production and captured, never delivered.

| Flag | Meaning |
| --- | --- |
| `--bin H` | Host command. Default `$KAVACH_BIN`. |
| `--until N` | Stop after the last step whose input `seq` is at most `N`, and hold the host there. |
| `--probe INPUT` | Send a synthetic input (source `probe`, your text as data) to the held host and print what it does. Repeatable. |
| `--hold` | After replay, read probe inputs from stdin, one per line, until EOF. |
| `--json` | Print the result as JSON, including `steps[].outputs`. |

## `kavach diff`

```text
kavach diff <fixture> --old <host-command> --new <host-command> [--variants N] [--regressions N] [--keep DIR] [--json]
```

Verifies a fix. The verdict is `fixed` only when:

1. the new build replays the recorded fixture with the failure gone, invariants holding, and earlier steps producing production's outputs;
2. it passes at least `N` **variants** of the incident (the failing input with fields changed or removed, moved earlier, earlier inputs dropped or redelivered, the clock shifted), each of which makes the old build fail exactly as it did in production;
3. on up to `N` **regression variants** (the same mutations applied to earlier inputs that resemble the failing one, which the old build handled without failing), it produces the old build's outputs.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--old H` | | Host command for the code that failed. |
| `--new H` | | Host command for the candidate fix. |
| `--variants N` | `10` | Reproducing variants the fix must pass. `0` checks only the recorded journal. |
| `--regressions N` | `48` | Regression variants checked. `0` skips them. |
| `--keep DIR` | a new temporary directory | Where failing variants are saved. |
| `--json` | | Print the verification as JSON. |

Useful JSON fields: `verdict`, `old`, `new`, `variants.{candidates,reproducing,passing,required,reproducing_by_kind}`, `variants.checks[].file`, `regressions.{counted,passing}`, `regressions.checks[].file`, `divergence`, `wall_ms`.

## `kavach contract`

```text
kavach contract init    --spec FILE --traffic FIXTURE [--feature-steps 40-52,60] [--feature-match EXPR]...
                        [--invariant NAME]... [--invariant-source FILE]... [--dir DIR] [--force]
kavach contract show    [--dir DIR] [--json]
kavach contract approve [--dir DIR] [--yes]
kavach contract check   --new <host-command> [--old <host-command>] [--dir DIR] [--no-variants] [--json]
                        [--save-replays DIR]
```

Checks a build against a behaviour contract for a new feature. `DIR` defaults to `./contract`. A match expression selects inputs by a value in their JSON data, for example `'$.argv[0]=="HSETEX"'`.

- `approve` locks the contract by hashing its files. It asks for confirmation at a terminal; otherwise it needs `--yes`, which the lock records. An agent must not approve its own contract.
- `check` exits `0` only on `pass`. Each check is a round in `DIR/rounds.jsonl`; `streak` counts rounds in a row with the same outcome. Failing variants go to `DIR/variants/` and are kept per round in `DIR/rounds/N/`. `--save-replays DIR` writes `replay-old.json` and `replay-new.json`. `--no-variants` skips feature variants.

See [Build a feature](https://www.thekavachlabs.com/docs/guides/build-a-feature) for the loop and every verdict.

## `kavach map`

```text
kavach map [map.json] [fixture.kavach]... [--bin H] [--new H] [--diff D.json]... [--overlay O.json]...
           [--source [GROUP=]DIR]... [--patch P.diff]... [--watch DIR]... [--listen ADDR] [--interval D]
           [-o out.html] [--json] [--max-data N] [--title T]
```

Renders one self-contained interactive HTML file showing the call, data and invariant flow, or serves it live.

| Flag | Default | Meaning |
| --- | --- | --- |
| `--bin H` | none (no `$KAVACH_BIN` default) | Replay fixtures on this build. |
| `--new H` | | Also replay on a candidate fix (needs `--bin`). |
| `--diff FILE` | | Attach a `kavach diff --json` report. Repeatable. |
| `--overlay FILE` | | Attach a stage overlay. Repeatable. |
| `--source [GROUP=]DIR` | | Source root for code excerpts. Repeatable. |
| `--patch FILE` | | Unified diff whose hunks attach to the nodes they touch. Repeatable. |
| `--watch DIR` | | Serve a live map of a recorder or fixtures directory. Repeatable. |
| `--listen ADDR` | `127.0.0.1:8090` | Live server address. |
| `--interval D` | `500ms` | Live poll interval. |
| `-o`, `--out FILE` | `kavach-map.html` | Output file. |
| `--json` | | Print the map model instead of HTML. |
| `--max-data N` | `512` | Bytes of payload preview; `0` omits payloads. |
| `--title T` | | Override the title. |

See [Flow maps](https://www.thekavachlabs.com/docs/guides/flow-maps) and the [`map.json` schema](https://www.thekavachlabs.com/docs/reference/map-json).

## `kavach mcp`

Serves the Model Context Protocol on stdin and stdout. See [MCP tools](https://www.thekavachlabs.com/docs/reference/mcp).

## `kavach version`

Prints the CLI version.

Source: https://www.thekavachlabs.com/docs/reference/cli
