---
title: The tessera CLI
summary: The tessera command-line tool registers apps, manages access and invites, and runs your realm from a terminal or a script.
section: reference
order: 5
---
# The tessera CLI

The `tessera` command-line tool registers apps, manages access and invites, and runs your realm from a terminal or a script.

It is one static binary. Anyone can use it, and coding agents use the same commands. It talks to the admin API, so every change it makes is also possible there and in the console.

## Install and sign in

Install the command line tool with one line:

```sh
curl -fsSL https://tessera.kurthlabs.ai/install.sh | bash
```

During early access, the CLI download is by invitation. [Ask us](https://tessera.kurthlabs.ai/#early-access) for it.

It downloads the build for your system from `dl.kurthlabs.com`, checks that the release's `SHA256SUMS` is signed by the Tessera downloads key and that the binary matches it, and installs `tessera` to `~/.local/bin` (set `TESSERA_INSTALL_DIR` to use another folder). It never uses sudo, and if a check fails it installs nothing. Put the folder on your `PATH` if the script says it is not there, then confirm it works:

```sh
tessera version
```

Update later with `tessera upgrade` (add `--check` to only look, `--version 1.2.3` to pick a release). It runs the same checks. `tessera version --check` prints the current and the newest version. On a terminal, tessera prints a one-line notice on stderr when a newer release exists, at most once a day; set `TESSERA_NO_UPDATE_CHECK=1` to turn that off (it is also off in CI and for JSON output).

Sign in with `tessera login`. It prints a link and a code; open the link in a browser where you are signed in and enter the code. The session is stored in `~/.config/tessera-cli/` with mode 0600 and refreshed automatically. `tessera whoami` shows who you are and which admin scopes you have, never the token. `tessera logout` deletes the session.

`tessera init` starts this sign-in by itself when you are not signed in. Add `--no-login` to make it fail instead. Other commands stop with exit code 6 until you sign in.

### Credentials for scripts and CI

The first of these that is set is used:

| Set | Meaning |
| --- | --- |
| `TESSERA_TOKEN` or `--token-file` | An admin API bearer token, used as is |
| `TESSERA_CLIENT_ID` with `TESSERA_CLIENT_SECRET_FILE` (or `TESSERA_CLIENT_SECRET`) | An agent: the CLI gets a token for exactly the scopes each command needs |
| None of the above | The session from `tessera login` |

Create an agent identity for automation with `tessera agents grant` (see below). See [Agent identities](/docs/agents/identities.md). To get and renew tokens inside your own Go or TypeScript program rather than through the CLI, see [get and refresh tokens in code](/docs/agents/token-source.md).

### Settings

| Flag | Environment | Meaning |
| --- | --- | --- |
| `--realm` | `TESSERA_REALM` | The realm to act on |
| `--admin-url` | `TESSERA_ADMIN_URL` | Admin API address; default `https://login.kurthlabs.com` |
| `--issuer` | `TESSERA_ISSUER` | Token issuer for agent sign-in |
| `--profile` | `TESSERA_PROFILE` | Named profile in `~/.config/tessera-cli/config.yaml` (`tessera config show`, `use`, `set`) |
| `-o json` or `-o text` | | Output format. Default is JSON when stdout is not a terminal |

`TESSERA_CONFIG_DIR` moves the config directory. The CLI refuses an admin URL or issuer that is not `https` (plain `http` only for localhost).

## How commands behave

- Results go to stdout and progress to stderr, so `-o json` output is safe to parse.
- Changes are idempotent. An `ensure` command creates what is missing, changes only fields that differ and otherwise reports `unchanged`. Lists you pass (`--redirect-uri` and so on) are the full list, not additions.
- Every change takes `--dry-run`, which prints the plan and changes nothing. Deletes need `--yes`; without it they print the plan.
- Secrets are never printed, put in arguments or logged. See "Where secrets go" below.
- In JSON mode a failure prints `{"state": "...", "exit": N, "error": "...", "kind": "...", "next": "..."}`. When the server sent an error code the object also has `code`, `cause`, `fix` and `docs`. See [Error codes](/docs/reference/error-codes.md).
- Every command takes `--json`, the same as `-o json`. A command that needs a person's approval also prints one JSON object per state change (`approval_required`, `allowed`) before its result.

### Exit codes

The exit codes are the same in every company CLI. The `kind` in the JSON error says which class of failure it was.

| Code | State | Meaning |
| --- | --- | --- |
| 0 | `allowed`, `completed` | Success |
| 1 | `failed` | Anything else, including `not_found`, `conflict` and `validation`, a failed secret delivery or a failed `tessera doctor` check |
| 2 | | Bad flags, arguments or spec file (`usage`) |
| 3 | `denied` | The person said no (a refused sign-in) |
| 4 | `expired` | Nobody answered in time |
| 5 | `not_permitted` | The credential lacks a needed admin scope or grant (HTTP 403) |
| 6 | `step_up_required` | Not signed in, or the sign-in no longer works (HTTP 401): run `tessera login` |
| 7 | `unknown` | A request that changes something went out and the server failed or the connection broke, so it may have taken effect: check before you retry |

Before 2026-11-09, 3 meant an auth error, 4 not found, 5 conflict, 6 validation and 7 a server or network error. Scripts that branch on those must change: use 6 or 5 for auth, and `kind` for not found, conflict and validation.

## Add sign-in to an app: init

```sh
tessera init                      # detect the stack, register the app, write .env.local, print the code
tessera init --dry-run -o json    # the plan only
tessera init --url https://app.acme.example    # also register a deployed URL (repeatable)
tessera init --stack mcp-server --resource https://mcp.acme.example
tessera init --pair ABCD-1234     # a coding agent, with a pairing code instead of your sign-in
```

In order, `init` signs in (or redeems a pairing code), detects the stack (Next.js, SvelteKit, Express, Go, Python, MCP server), picks the realm, creates or extends the client, writes the env file, checks the issuer's discovery document and prints the quickstart code with your real values.

- A new client is confidential, with the `authorization_code` and `refresh_token` grants, the `openid`, `profile`, `email` and `offline_access` scopes, RS256 ID tokens, and redirect, post-logout and web-origin entries for the dev origin and each `--url`. Use `--public` for a client without a secret.
- An existing client only gains missing URLs. Re-running is safe.
- The env file (`.env.local`, or `.env` for Python) gets `TESSERA_ISSUER`, `TESSERA_CLIENT_ID`, `TESSERA_CLIENT_SECRET` and a random `AUTH_SECRET` or `SESSION_SECRET`. It is kept out of git first. For an MCP server it writes `TESSERA_MCP_RESOURCE` and no secret.
- A confidential client's secret is shown once. If the client exists and the env file lacks the secret, `init` exits with code 1 (kind `conflict`). Re-run with `--rotate-secret` only if you accept that the old secret stops working.
- Redirect entries for the dev origin are `http://localhost:PORT`, `http://127.0.0.1:PORT`, `http://[::1]:PORT` and the portless `https://<client-id>.localhost`. A redirect URL on an IP literal matches any port; `localhost` matches the exact port.
- Flags: `--dir`, `--stack`, `--realm`, `--client-id`, `--name`, `--port`, `--url`, `--public`, `--resource`, `--create-realm` (a platform operator), `--idp-url`, `--env-file`, `--no-env-file`, `--print-secret`, `--rotate-secret`, `--pair`, `--no-verify`, `--no-login`, `--dry-run`.

`tessera skill install` writes a skill file that teaches a coding agent to run all of this safely.

## Pairing codes: init --pair

A coding agent should not hold your credentials. A realm administrator mints a pairing code, and the agent redeems it.

```sh
tessera pairing create                        # prints a code like ABCD-1234, and a line to give your agent
tessera pairing create --client-id acme-web   # pin the code to one app
tessera init --pair ABCD-1234 -o json         # the agent: or `--pair -` to be asked, or TESSERA_PAIRING_CODE
```

`pairing create` needs a realm administrator (`tessera:realm-admin`). The code is single use, lasts 10 minutes and belongs to one realm. `init` redeems it for a token that lasts 15 minutes and can register or update one client in that realm and nothing else: it cannot list clients, read the realm or its users, delete anything, or touch an admin client. The token is held in memory and never printed, and a new client's secret still goes straight from the server to the env file.

The realm and issuer come from the code, so no `--realm` is needed. `--pair` cannot be combined with `--dry-run` (redeeming spends the code), `--create-realm` or the MCP stack. A refused code (unknown, expired, used, or for another client) exits with code 5. Redemption is rate limited per address. On a terminal with no credentials at all, `init` offers to take a pairing code instead of starting a device login.

## Check that it works: doctor

```sh
tessera doctor                  # read .env.local, run the round trip, exit 1 if a step fails
tessera doctor --fix            # also add the redirect and post-logout URLs the app uses and the client lacks
tessera doctor -o json          # {ok, failing_step, checks: [{id, status, code, remedy, ...}]}
tessera doctor --mcp https://mcp.acme.example/mcp
```

The steps, in order:

- `config`: the env file names an issuer.
- `discovery`: the issuer's discovery document answers and names the same issuer.
- `jwks`: the signing keys can be fetched.
- `client`: the client exists, and its redirect and post-logout URLs include the ones the app really uses. The result lists missing and extra URLs. This step needs admin credentials or `--pair`, and is skipped without them.
- `sign_in`: a headless sign-in as a development test persona, when you pass `--persona-issuer`, `--persona-subject` and `--persona-key-file`. Without them it is skipped with a note.
- `token`: signature, `iss`, `aud` and `exp` of that token, or of `--access-token-file`.
- `roles`: the `roles` claim is present when the client binds roles, or with `--expect-roles`.

Every failing or warning check has a stable `code` (for example `issuer_mismatch`, `redirect_uri_mismatch` or `token_audience_mismatch`) and a `remedy` to act on. The client secret and tokens are used in memory and never appear in the report.

`--mcp <resource>` checks a protected MCP server instead: the unauthenticated request must get a `401` with a `WWW-Authenticate: Bearer` challenge, the protected-resource metadata (RFC 9728) must name exactly this resource and an authorization server, that server must advertise PKCE S256, a made-up bearer token must be refused and, with `--access-token-file`, the token's `aud` must be bound to the resource.

## Commands

Realm-scoped commands take `--realm`. Run `tessera <command> --help` for every flag.

| Group | What it does |
| --- | --- |
| `clients list`, `get`, `ensure`, `rotate-secret`, `delete` | OAuth clients. Flags for `ensure`: `--kind public\|confidential`, `--redirect-uri`, `--post-logout-uri`, `--web-origin`, `--grant`, `--scope`, `--resource`, `--pkce=false`, `--backchannel-logout-uri`, `--rotate-secret` |
| `logs --client <id> [--follow]` | What just happened to a client: discovery, authorize, redirect mismatches, token exchanges, errors |
| `access apps`, `roles`, `groups`, `members`, `bind`, `unbind`, `bindings`, `effective`, `templates` | Apps, roles, groups and who holds what. See [Roles and permissions](/docs/concepts/roles-and-permissions.md) |
| `invites list`, `create`, `revoke`, `extend`, `regenerate`, `link` | Invites. `create` takes `--email`, `--client`, `--landing-url`, `--role app:role`, `--group`, `--expires 7d`, `--no-email`, `--print-link`, `--link-file`, or `--claimable` for an open link (with `--allowed-domain` to limit who can claim it). See [Invites](/docs/customize/invites.md) |
| `users list`, `get`, `mfa reset` | Look up users; remove a user's second factor |
| `domains list`, `status`, `ensure`, `verify`, `activate`, `deactivate`, `provision`, `delete` | Custom login domains. See [Login domains](/docs/customize/login-domains.md) |
| `realms list`, `get`, `ensure`, `update` | Realms. Settings include `--display-name`, `--signup-policy` and `--sign-in-methods` |
| `keys list`, `rotate`, `revoke`, `rotation` | Signing keys; never shows key material. `rotate --revoke-previous` is the emergency form |
| `pairing create` | A pairing code for `init --pair`. See [Pairing codes](#pairing-codes-init-pair) |
| `doctor` | Check that sign-in works end to end. See [Check that it works](#check-that-it-works-doctor) |
| `theme import-brand`, `preview` | Read a theme from your website ("match my site") and preview it on the real pages. See [Themes](/docs/customize/themes.md) |
| `agents grant`, `list`, `revoke`, `create`, `apply`, `disable`, `enable`, `rotate`, `delete`, `card` | Agent identities. See [Agent identities](/docs/agents/identities.md) |
| `delegation show`, `limits`, `limit`, `unlimit`, `legacy-actor` | Delegation settings for agents acting for people |
| `kill agent\|client\|realm`, `resume agent\|client\|realm` | Stop token issuance now, and lift it. See [Revocation and the kill switch](/docs/agents/revocation-and-kill-switch.md) |
| `workload-federation add`, `list`, `delete`, `test` | Let CI and cloud workloads get tokens without secrets. See [Workload identity](/docs/agents/workload-identity.md) |
| `federation list`, `get`, `oidc ensure`, `delete` | Upstream sign-in providers |
| `agreements get`, `set`, `delete`, `accepted` | Terms and privacy statements. See [Agreements](/docs/customize/agreements.md) |
| `plan -f spec.yaml`, `apply -f spec.yaml`, `export realm <realm>` | Declare a realm in a file, preview and apply it, or export it |
| `errors [code]` | The error catalogue, offline |
| `config show`, `use`, `set` | Profiles |
| `version`, `login`, `logout`, `whoami` | Session and version |

Platform operators also have `workspaces` commands for creating and limiting workspaces.

### Where secrets go

A command that mints a secret (a confidential client, an agent, a rotation) needs a destination, or it stops with exit code 2 before anything is created.

| Flag | Destination |
| --- | --- |
| `--env-file PATH --env-key KEY` | `KEY=secret` in a local file, mode 0600, other lines kept |
| `--gh-repo owner/repo --gh-secret NAME` | A GitHub Actions secret, set through the `gh` tool |
| `--print` | The secret once, in the JSON result, only when you ask |

If a delivery fails, what was just created is revoked and the command exits 1. Invite links are credentials too: they print only with `--print-link` or go to `--link-file`.

## Realm specs

A spec file declares a realm: its settings, clients, apps, roles, groups, bindings, domains and themes.

```yaml
apiVersion: tessera.dev/v1
kind: Realm
realm:
  name: acme
clients:
  - client_id: acme-web
    kind: confidential
    redirect_uris: [https://app.acme.example/auth/callback]
    post_logout_redirect_uris: [https://app.acme.example/]
    grants: [authorization_code, refresh_token]
    scopes: [openid, profile, email, offline_access]
    id_token_signed_response_alg: RS256
```

```sh
tessera plan -f acme.yaml       # show what would change
tessera apply -f acme.yaml      # make it so; apply only adds and updates, it never deletes
tessera export realm acme       # write the current state as a spec
```
