> ## Documentation Index
> Fetch the complete documentation index at: https://xerg.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Compare

> Understand how Xerg chooses a baseline and how to make before and after comparisons meaningful.

## Basic usage

```bash theme={null}
npx @xerg/cli@latest audit --compare
```

Xerg compares the current audit against the newest compatible prior snapshot stored in the local JSON snapshot store.

For Hermes, local snapshots also compare mechanical metric values and report newly observed or resolved mechanical finding kinds. These deltas remain separate from monetary comparison, recommendations, and failure thresholds, and never cross the push wire.

## What makes a snapshot compatible?

For local audits, Xerg matches on:

* the same source roots for gateway logs and session files
* the same normalized `--since` window

For SSH and Railway audits, Xerg uses a stable comparison key derived from the target plus the effective remote log and session paths.

That means these usually compare cleanly:

* rerunning the same local audit
* rerunning the same SSH target with the same remote paths
* rerunning the same Railway service with the same remote paths

These usually do not compare cleanly:

* changing from default paths to different explicit paths
* changing the `--since` window from `24h` to `7d`
* switching to a different SSH host or Railway service

## First run behavior

If you use `--compare` before a compatible baseline exists, Xerg still completes the audit. It adds this note to the summary:

```text theme={null}
No prior comparable audit was found. Run the same audit again after a fix to unlock before/after deltas.
```

Versions before `0.5.3` stored local snapshots in a native SQLite database. The current CLI uses a JSON snapshot store, so older `xerg.db` baselines do not participate in new comparisons. Run one current audit to create the new baseline.

## Database requirements

`--compare` needs local snapshot history.

This works:

```bash theme={null}
npx @xerg/cli@latest audit --compare
npx @xerg/cli@latest audit --db /path/to/xerg-snapshots.json --compare
```

This does not:

```bash theme={null}
npx @xerg/cli@latest audit --no-db --compare
```

That combination fails because there is no local snapshot store to compare against.

## Recommended workflow

1. Run an initial audit.
2. Make one workflow or model change.
3. Re-run the same audit with the same effective inputs and `--compare`.
4. Use the delta section to confirm whether total spend, structural waste, and high-confidence waste improved.
