
# CLI quickstart

Install `tdx`, sign in to your gateway and read its workspaces, in about five minutes.

You need a supported Node.js LTS release (see `engines` in [`package.json`](https://github.com/ArtificialAnalysis/Tokedex/blob/main/typescript/package.json)), a running gateway and an account on its dashboard. The [Gateway quickstart](/gateway/quickstart) starts a gateway at `http://127.0.0.1:4000`.

## Install the CLI

```bash
npm install --global @tokedex/cli
tdx --version
```

### Install from source

To build the CLI from a checkout, use pnpm 10.34.9. Open your Tokedex checkout or clone the repository.

```bash
git clone https://github.com/ArtificialAnalysis/Tokedex.git
cd Tokedex
```

From the checkout, build and install the CLI.

```bash
pnpm -C typescript install --frozen-lockfile
pnpm -C typescript build:refs
npm install --global --install-links ./typescript/packages/cli
tdx --version
```

## Sign in

```bash
tdx auth login --host http://127.0.0.1:4000
```

```text
Open http://127.0.0.1:4000/cli-sign-in
Enter this code in the browser: SFBB-ZWBT
Only enter a code that your own terminal shows you. The code expires in 10 minutes.
Opened your browser. Waiting for approval… (Ctrl-C to cancel)
```

The page is on the gateway's public URL (`TOKEDEX_PUBLIC_URL`) when it has one, even if `--host` is another address for it, so signing in through your identity provider brings you back to it. The exception is a public URL and `--host` on this machine with different ports, such as a port-forward on another port: the page is then on `--host`, and you sign in there with your email and password.

In the browser page that opens:

1. Sign in to the dashboard, if it asks.
2. Enter the code from your terminal and choose **Continue**.
3. Check the request: the CLI's name, the network it asked from and how long its token lasts. Choose **Approve**. If you signed in more than 10 minutes ago, confirm it's you first.

The page says **Request approved. Return to your terminal to confirm that sign-in completed.** The terminal prints the saved profile when sign-in completes.

```json
{
  "schemaVersion": "tokedex.cli.v1",
  "command": "auth login",
  "data": {
    "profile": {
      "name": "default",
      "origin": "http://127.0.0.1:4000"
    },
    "principal": {
      "kind": "user",
      "id": "usr_01M83XDKHP308B8X1770RJZ9PQ",
      "name": "Ada Lovelace"
    },
    "breakGlass": false,
    "expiresAt": "2026-12-23T09:59:27.105Z",
    "warning": null,
    "preview": null
  }
}
```

`tdx auth login` saved a personal access token, with the gateway's address, in a file only your user can read under `~/.config/tokedex/`. The token can do what your role lets you do, except what only the dashboard does, and lasts 30 days; ask for less with `--expires-in 7d`. It is listed under **Account → Access tokens**, where you can revoke it.

Approve only a code your own terminal shows you. Anyone who sends you a code and a link is asking for your access.

On a machine without a browser, including SSH without a terminal, select browser sign-in explicitly. Replace the host with your gateway's address.

```bash
tdx auth login --host https://gateway.example.com --method browser --no-browser
```

Open the printed address on a device that can reach the gateway and approve the code there.

## Check the connection

```bash
tdx auth status --json=principal,expiresAt,source
```

```json
{
  "schemaVersion": "tokedex.cli.v1",
  "command": "auth status",
  "data": {
    "principal": {
      "kind": "user",
      "id": "usr_01M83XDKHP308B8X1770RJZ9PQ",
      "name": "Ada Lovelace"
    },
    "expiresAt": "2026-12-23T09:59:27.105Z",
    "source": {
      "profile": "default",
      "profileSource": "default",
      "origin": "http://127.0.0.1:4000",
      "hostSource": "profile",
      "credential": "profile",
      "ephemeral": false,
      "browserSignIn": true
    }
  }
}
```

`expiresAt` is when the token stops working; run `tdx auth login` again before then. `browserSignIn` shows the token came from browser sign-in, and plain `tdx auth status` also lists your `permissions`.

### Diagnose a proxy connection

Run [`tdx doctor`](/cli/reference/doctor) when you connect through an HTTPS proxy. If it reports `TRANSPORT_FAILED`, test the proxy tunnel and TLS handshake against the same gateway URL. This health check needs no gateway credentials.

```bash
export TOKEDEX_URL='https://gateway.example.com'
curl --silent --show-error --output /dev/null \
  --write-out 'Proxy CONNECT status %{http_connect}\n' "$TOKEDEX_URL/healthz"
```

| Result | What to check |
| --- | --- |
| Proxy CONNECT returns `407` | Check the credentials for your proxy. Set the proxy URL in `HTTPS_PROXY` or its lowercase equivalent. |
| Proxy CONNECT returns `200` and curl reports a certificate trust error | Ask your network administrator for the trusted CA certificate. For `tdx`, set `NODE_EXTRA_CA_CERTS` to the path of its PEM file, then run `tdx doctor` again. |
| Proxy CONNECT returns `000` and you expected a proxy | Check for a matching `NO_PROXY` entry and check the lowercase proxy variables. The CLI gives lowercase settings precedence. |

If the connection passes and the login check reports `AUTHENTICATION_FAILED`, sign in to the gateway again. See the [CLI environment variables](/cli/reference#environment-variables).

## List workspaces

```bash
tdx workspaces list --json --jq '.data.workspaces[] | {slug, name, status}'
```

```json
{
  "slug": "default",
  "name": "Default",
  "status": "active"
}
```

It lists the workspaces your role lets you read, as the dashboard's workspace switcher does. Without `--jq`, the command prints every field of each workspace, wrapped in the same object as `auth status`. `--jq` runs your installed `jq` on that object.

## Connect another gateway

Each profile holds one gateway. Sign in to another under a name, then pass that name to choose it:

```bash
tdx auth login --host https://gateway.example.com --profile staging
tdx workspaces list --profile staging
```

`tdx auth logout --profile staging` revokes that profile's token on the gateway and deletes the profile, so sign out of a machine you no longer use. A CI job or agent should not use your sign-in: give it an admin key through `TOKEDEX_TOKEN` and `TOKEDEX_HOST`, as [Scripts and agents](/cli/scripts-and-agents#choose-how-to-pass-credentials) describes.

Next: [Scripts and agents](/cli/scripts-and-agents), the [Command reference](/cli/reference) or [API keys](/gateway/api-keys) in the gateway docs.
