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

# Get Started

> Set up traceroot in your repository and work with your project from the terminal

The traceroot CLI sets up tracing in your repository with one command, then lets you work with your project from the terminal — traces, detector findings, alerts, dashboards, evaluations, and SQL — and pipe the JSON into whatever comes next. It is built for AI coding agents and power users who prefer the command line.

Full source and reference live in the [`traceroot-cli`](https://github.com/traceroot-ai/traceroot-cli) repo.

## Set up a repository

Run this from the root of the repository you want to trace:

```bash theme={null}
npx -y traceroot-cli@latest setup
```

Setup signs you in, has your coding agent add the traceroot SDK, and waits for your first trace; no install or sign-in needed first. [Tracing](https://traceroot.ai/docs/tracing/get-started.md) covers each step, self-hosting, and troubleshooting.

### Run without prompts

Setup never prompts when it isn't attached to a terminal, when `CI` is set, or with `--no-input` or `--json`. Pass what it would otherwise ask for:

```bash theme={null}
npx -y traceroot-cli@latest setup --no-input --api-key "$TRACEROOT_API_KEY"
```

A project API key also sets the project. If you signed in with `traceroot login` instead and have several projects, pass `--project`. Without prompts, setup notes uncommitted changes instead of asking, and writes the instrumentation task to a file rather than running a coding agent. Pass `--agent claude` or `--agent codex` to run one.

## Install

Every command also runs through `npx`, as above. To keep the `traceroot` command, install the CLI globally:

```bash theme={null}
npm install -g traceroot-cli
```

The CLI needs Node.js 20.3 or later, and `setup` needs 20.12 or later.

## Authenticate

The CLI authenticates with either a **browser login** (the default interactive device flow) or a **project API key** (for CI environments and scripts).

### Browser login (default)

Run `traceroot login` to sign in through your browser:

```bash theme={null}
traceroot login
```

This opens your browser to approve the sign-in and saves a session to `~/.config/traceroot/credentials.json`, which refreshes automatically.

### API key login (CI & scripts)

For CI pipelines, automated scripts, or headless environments, use a project API key (`tr-...`):

```bash theme={null}
traceroot login --api-key tr-...
```

This validates the key against the API and saves it to `./.traceroot/config.json`.

```bash .env theme={null}
TRACEROOT_API_KEY=tr-...
TRACEROOT_HOST_URL=https://app.traceroot.ai
```

The CLI resolves credentials in this order:

1. `--api-key` flag
2. `--env-file <path>`
3. `TRACEROOT_TOKEN` environment variable
4. Credentials file (`~/.config/traceroot/credentials.json`)
5. `TRACEROOT_API_KEY` environment variable
6. Config file (`./.traceroot/config.json`)
7. Auto-discovered `./.env` — a `TRACEROOT_API_KEY` here selects key mode when nothing above it is set

Create API keys in [traceroot Cloud](https://app.traceroot.ai) or your [self-hosted](https://traceroot.ai/docs/developer/self-hosting.md) dashboard.

### Verify credentials

Confirm your active identity:

```bash theme={null}
traceroot status
```

* **Browser login**: Displays your authenticated email address, host URL, active project (or a hint to select one), and accessible workspaces.
* **API key login**: Displays your workspace, project, host URL, and a masked key hint (e.g. `tr-d0a3-57e3`).

## Scope to a project

A browser login identifies you across your workspaces rather than binding to one project, and commands such as `traces` and `evals` are project-scoped, so pick a project first. An API key is already scoped to its project, so a key login can skip this step.

List the projects you can access to find your project ID:

```bash theme={null}
traceroot projects list
```

Set `TRACEROOT_PROJECT_ID` so later commands need no extra flags, or pass `--project <id>` to individual commands:

```bash theme={null}
export TRACEROOT_PROJECT_ID=<project-id>
```

## Inspect and export traces

Once authenticated and scoped to a project, list, inspect, and export traces:

```bash theme={null}
# List recent traces, newest first (filter by time with --since, --from, or --to)
traceroot traces list --limit 10

# Inspect one trace: header, duration, span tree, and web app link
traceroot traces get <trace-id>

# Fetch full trace details including span inputs, outputs, and metadata as JSON
traceroot traces get <trace-id> --fields full --json

# Write a full trace bundle to disk to share or feed into another tool
traceroot traces export <trace-id> --output ./my-trace
```

### Trace projections and field groups (`--fields`)

By default, `traceroot traces get` prints the trace header, an optional detector finding block, the span tree, and the web app URL.

When emitting JSON (`--json`), `traceroot traces get` defaults to the lightweight `skeleton` projection, leaving span `input`, `output`, and `metadata` as `null` to minimize payload size. Pass `--fields` to include specific data groups:

* **Field groups**: `core`, `usage`, `io`, `metadata`
* **Aliases**: `skeleton` (`core,usage`) and `full` (`core,usage,io,metadata`)

So `--fields full`, or `--fields io,metadata`, includes span I/O in the JSON payload.

`traceroot traces export` instead defaults to the `full` projection, writing `trace.json`, `spans.json`, `git_context.json`, `manifest.json`, and `finding.json` (if flagged by a detector) into the destination directory. Pass `--fields <groups>` to narrow what is exported.

## Read evaluations

The CLI also reads your offline [evaluations](https://traceroot.ai/docs/evals/introduction.md): the datasets you run against and the runs that scored them.

```bash theme={null}
# Which evaluations exist, and how each one's latest run ended
traceroot evals list

# One evaluation's runs, newest first — the RUN ID column is what you read next
traceroot evals runs list --evaluation-id <evaluation-id>

# One run: its counts, per-scorer means, and per-case cost and duration
traceroot evals runs get <run-id>
```

See [From the terminal](https://traceroot.ai/docs/evals/cli.md) for what each read shows, and for the dataset commands.

## Command reference

Add `--json` to any command for machine-readable output, or run `traceroot <command> --help` for the full flag list.

| Command | What it does |
| :- | :- |
| `setup` | Connect this repository to traceroot and see your first trace. See [Tracing](https://traceroot.ai/docs/tracing/get-started.md). |
| `setup doctor` | Diagnose a setup that did not complete. Flag: `--service <path>`. |
| `login` | Sign in through your browser and save the session; with `--api-key`, validate and save a project API key instead. |
| `status` | Show the identity your credentials resolve to — workspace, project, host, and key hint. |
| `traces list` | List traces for your project, newest first. Flag: `--limit <n>`. |
| `traces get <id>` | Show one trace: header, span tree, duration, and I/O preview. `--json` emits the full trace. |
| `traces export <id>` | Write `trace.json`, `spans.json`, `git_context.json`, and a `manifest.json` index to a directory. Flags: `--output <dir>`, `--force`. |
| `datasets list` | List the project's evaluation datasets, newest first. Flags: `--limit <n>`, `--name <substring>`. |
| `datasets get <dataset-id>` | Show one dataset and the version its cases are read from. |
| `datasets versions list <dataset-id>` | List a dataset's published versions with their case counts. Flag: `--limit <n>`. |
| `datasets versions get <version-id>` | Show one version and a page of its cases. Flag: `--limit <n>` — 200 by default, up to 1000. |
| `evals list` | List evaluations with their run count and latest run. Flags: `--limit <n>`, `--name <substring>`. |
| `evals runs list` | List evaluation runs, newest first. Flags: `--limit <n>`, `--evaluation-id <id>`, `--status <status>`. |
| `evals runs get <run-id>` | Show one run: counts, per-scorer means, per-case cost and duration, and its URL. |
| `sql [query]` | Run one read-only query over the project's spans and traces. See [Read-only SQL](https://traceroot.ai/docs/cli/sql.md). |
| `sql schema` | List every table and column available to read-only SQL. |

## Next steps

> [card] [Tracing](https://traceroot.ai/docs/tracing/get-started.md)
>
> Set up tracing with one command, or instrument by hand.

> [card] [Evaluations from the Terminal](https://traceroot.ai/docs/evals/cli.md)
>
> Read datasets, evaluations, and past runs.

> [card] [traceroot Cloud](https://app.traceroot.ai)
>
> Create API keys and open traces in the web app.


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