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

> ## Agent Instructions
> CrispStats is a hosted, privacy-first analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing and no data import except a site's history from a Plausible export (Settings, Import and export). Websites use the script. iOS, Android, React Native and Flutter use the mobile SDKs in the install guides. Those SDKs are source files, not a published package, and they do not read an advertising id.
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> The script tag is the main install; the npm package @crispstats/tracker does the same from code, never alongside the tag. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# CrispStats command line

> Read stats, breakdowns, funnels and payments, and record or delete payments, from a terminal, a CI job or an AI agent with the crispstats CLI. Install, sign in, environment variables and exit codes.

The `crispstats` command line reads the same numbers as the dashboard and the [REST API](https://docs.crispstats.com/api-reference/introduction.md): every command maps to one API endpoint. It prints aligned tables for people and the API's JSON, untouched, for scripts and agents. It needs Node 20 or newer and has no dependencies.

Try it now on the public demo site, no key needed:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
npx @crispstats/cli stats --site demo --range 7d
```

## Install

Run it without installing through `npx`, or install it once to get the `crispstats` command:

```bash npx theme={"theme":{"light":"github-light","dark":"github-dark"}}
npx @crispstats/cli stats --site demo
```

```bash npm theme={"theme":{"light":"github-light","dark":"github-dark"}}
npm install --global @crispstats/cli
crispstats stats --site demo
```

```bash pnpm theme={"theme":{"light":"github-light","dark":"github-dark"}}
pnpm add --global @crispstats/cli
crispstats stats --site demo
```

`npx crispstats` works too: the `crispstats` package installs `@crispstats/cli` and exposes the same command.

## Sign in

**1. Run login**

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats login
```

It prints the address of the API and MCP page, at the **API keys** section, and opens it in your browser.

**2. Create a secret key**

Create a key with the **Read** scope to read reports. To record or delete payments, give it the **Events** or **Admin** scope too. See [API keys](https://docs.crispstats.com/account/api-keys.md#create-a-key).

**3. Paste the key**

Paste it at the prompt. Nothing is shown as you type, and the key never lands in your shell history. The CLI checks it against the API before saving it.

The key is saved to `~/.config/crispstats/config.json`, or `$XDG_CONFIG_HOME/crispstats/config.json` when that is set. The file is readable by you only (mode 600). If the key reads exactly one site, that site becomes the default.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats whoami            # check the key works and see what it reads
crispstats sites             # the sites the key reads
crispstats use example.com   # the site other commands read by default, by id or by domain
crispstats logout            # remove the saved key from this computer
```

`logout` only removes the key from this computer. The key keeps working until you revoke it on the API and MCP page.

## Pick a site

Every report reads one site. The CLI takes the first of these that is set:

1. `--site <id>` on the command
2. the `CRISPSTATS_SITE` environment variable
3. the default saved with `crispstats use`

A site id is the segment after `/app/` in your dashboard URL; `crispstats sites` lists them. `crispstats use` also takes the site's domain.

Without any of them, a report stops with `No site picked.` and exit code 2.

## Environment variables

| Variable | What it does |
| - | - |
| `CRISPSTATS_TOKEN` | A secret API key (`cs_sk_…`). Used instead of the saved key. |
| `CRISPSTATS_SITE` | The site to read. `--site` wins over it. |
| `CRISPSTATS_API_BASE` | The API address, `https://crispstats.com/api/v1` by default. `--api-base` wins over it. Only `https` is accepted, or `http` to localhost. |
| `NO_COLOR` | Any value turns colour off. |
| `XDG_CONFIG_HOME` | Where the config folder lives. |

A flag wins over an environment variable, which wins over the saved file.

## Flags for every command

| Flag | What it does |
| - | - |
| `--site <id>` | The site to read |
| `--json` | Print the API's JSON exactly as sent |
| `--verbose` | Log each request, its status and the rate limit headers to stderr. The key is always shown as `[redacted]`. |
| `--api-base <url>` | Another API address |
| `-y`, `--yes` | Answer yes to confirmation prompts |
| `--no-color` | Plain text, no colour |
| `-h`, `--help` | Help for the command, with one example |
| `--version` | The CLI's version |

Colour is also off when the output is not a terminal, so piped output is always plain.

## Output

For people, numbers come formatted the way the dashboard shows them: money from the API's integer minor units in the site's currency (`4900` USD is `$49.00`), rates as percentages, durations as minutes and seconds, times in UTC. Long lists end with where the next page starts:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
$ crispstats pages --site demo --limit 3
Last 30 days

Page      Visitors  Pageviews  Bounce  Duration  Revenue  Conv.  Share
/           23,365     26,277     39%       36s   $4,804  0.34%  15.6%
/pricing    12,991     14,914     28%       58s  $19,914  2.19%   8.7%
/signup      7,310      8,197     36%       51s  $11,838  2.27%   4.9%

Showing 1 to 3 of 43. Next page: --offset 3, or --all for every row.
```

With `--json`, the CLI prints the response body untouched, so `jq` and agents read the API's documented fields. `--all` fetches every page of a paged list and prints them as one response, with every row in `rows` (or `events` for raw events).

## Errors and exit codes

Errors go to stderr, never into piped output. Each one names the cause, as the API wrote it, and the way out:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
$ crispstats stats --site demo --range 8d
Error: range: Invalid option: expected one of "today"|"yesterday"|"24h"|"7d"|"30d"|"90d"|"mtd"|"last_month"|"ytd"|"12m"|"all"
```

With `--json`, the API's error envelope is printed to stderr as is. See [errors](https://docs.crispstats.com/api-reference/errors.md) for every code.

| Exit code | Meaning |
| - | - |
| `0` | Done |
| `1` | The API refused the request or could not be reached |
| `2` | The command was used wrongly: an unknown flag, a missing argument, no site, or a delete without `--yes` where nobody can answer the prompt |
| `130` | Cancelled at a prompt |

## Use it in CI

Store the key as a secret and pass it through the environment. Nothing is written to disk.

```yaml GitHub Actions theme={"theme":{"light":"github-light","dark":"github-dark"}}
- name: Yesterday's numbers
  env:
    CRISPSTATS_TOKEN: ${{ secrets.CRISPSTATS_TOKEN }}
    CRISPSTATS_SITE: ${{ vars.CRISPSTATS_SITE }}
  run: npx --yes @crispstats/cli stats --range yesterday --json > stats.json
```

A delete needs `--yes` in CI, since there is no one to answer the prompt. Requests count against the key's [rate limit](https://docs.crispstats.com/api-reference/rate-limits.md); `--verbose` shows how much is left.

## Use it from an AI agent

Coding agents that run shell commands can read your analytics with the CLI. Give the agent a **Read only** key, through `CRISPSTATS_TOKEN`, and tell it to pass `--json`:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
crispstats breakdown source --range 7d --json
crispstats funnels funnel_signup --json
crispstats api GET /sites/demo/visitors -q segment=customers -q limit=5
```

Every command has `--help` with an example, and every report's JSON carries a `summary` sentence an agent can quote. For assistants that speak MCP, the [MCP server](https://docs.crispstats.com/api-reference/mcp.md) offers the same reports as tools.

Next: [every command](https://docs.crispstats.com/cli/commands.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.