# Using the CLI

> Drive TReqs from a terminal — logging in, binding a repo to a project, and running the request lifecycle.

The `treqs` CLI does everything the dashboard does, and it's the better tool when you're already in a repository. Most commands are **repo-bound**: run them inside a git repo that's been bound to a project, and they infer the project, branch, and commit from where you are.

For the exhaustive command reference, run `treqs --help`, or `treqs <command> --help` for any subcommand. This page is the path through it.

::u-page-grid{class="lg:grid-cols-2 gap-4"}
:u-page-card{icon="i-lucide-box" title="TReqs CLI on Github" to="https://github.com/treqs/treqs-cli" target="_blank"}
::

## Global options

```
--version       Show the version and exit.
--api-url TEXT  TReqs API base URL.  [env var: TREQS_API_URL]
--json          Emit machine-readable JSON.
```

`--json` goes *before* the subcommand — `treqs --json whoami`, not `treqs whoami --json`. It's what makes the CLI scriptable.

## Log in

```bash [TReqs CLI]
treqs login
```

This starts a device authorization flow: it prints a URL and a code, you approve them in your browser, and the session is stored in your platform config directory. `--no-browser` skips trying to open one for you.

For CI, use an API token issued from the dashboard instead:

```bash [TReqs CLI]
treqs login --token treqs_pat_XXXXXXXX
echo $TOKEN | treqs login --token -   # read from stdin
```

To use a token *without* storing it, set `TREQS_API_TOKEN`. It takes precedence over any stored login — which is what you want in an ephemeral environment.

Check who you are, and which organizations you can act as:

```bash [TReqs CLI]
treqs whoami
```

It lists every owner you can act as — yourself plus your organizations — with your role and project count in each.

## Bind a repo to a project

```bash [TReqs CLI]
treqs projects list          # what you have access to
treqs project use my-project # bind the current repo
treqs project status         # what the current repo is bound to
```

`treqs project use` writes the binding into the repo, so the `tr` commands below know their context without you naming a project each time. `treqs project clear` removes it.

## Check before you run

```bash [TReqs CLI]
treqs doctor --target gpu-box --workflow .treqs/workflows/train.yaml
```

`doctor` validates your laptop, the project binding, the git source, the workflow, and compute readiness together. It's worth running before you open a training request — it catches the errors that would otherwise surface several minutes into a run, when a stage fails on a machine you're paying for.

## The training request lifecycle

```bash [TReqs CLI]
# Create a draft
treqs tr create --title "Baseline run" \
    --workflow-path .treqs/workflows/train.yaml

# Open it for review with a compute target and reviewers
treqs tr open <request-id> --compute-target gpu-box --reviewer alice

# Reviewers decide
treqs tr review approve <request-id>
treqs tr review reject <request-id>

# Queue the approved request; prints a job ID
treqs tr queue <request-id>
```

Also available: `treqs tr list`, `treqs tr show`, `treqs tr update`, `treqs tr comment`, and `treqs tr cancel`. See [Training requests](/docs/training-requests) for what the statuses mean.

## Follow the run

`treqs tr queue` prints a job ID. From there:

```bash [TReqs CLI]
treqs jobs watch <job-id>            # lifecycle + logs until it finishes
treqs jobs logs <job-id> --follow    # just the workload output
treqs jobs logs <job-id> --agent     # the agent's log — read this when a
                                     # task fails before its command runs
treqs jobs tasks <job-id>            # per-stage status
treqs jobs wait <job-id>             # block; non-zero unless Completed
```

`treqs jobs wait` is the one for scripts — it exits non-zero unless the run reaches **Completed**, so it fails a pipeline properly. `treqs jobs stop` cancels a run in flight.

## Manage compute

```bash [TReqs CLI]
treqs compute targets list
treqs compute targets create --name gpu-box
treqs compute targets create --kind on-demand --name burst \
    --type runpod --instance-type cpu3c
treqs compute targets registration-code create --target gpu-box
treqs compute targets instances burst
treqs compute targets archive gpu-box

treqs compute secrets set --target gpu-box WANDB_API_KEY=abc123
treqs compute secrets list --target gpu-box
treqs compute secrets delete --target gpu-box WANDB_API_KEY
```

`--target` accepts an ID, a unique name, or a unique ID prefix. See [Compute targets](/docs/compute-targets).

## Owner context

Most commands take `--owner` to say which organization to act in. It defaults to the repo's bound project owner, so inside a bound repo you rarely need it.

```bash [TReqs CLI]
treqs orgs list
treqs compute targets create --name team-gpu --owner acme
```

## Log out

```bash [TReqs CLI]
treqs logout
```
