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

# Authentication and workspaces

> Struct CLI reference: authentication and workspaces.

Use the Struct CLI to inspect and configure a workspace from your terminal. Commands use the permissions of the active login or workspace API key.

## Sign in

```bash theme={null}
struct login
struct whoami --json
```

The CLI prints the authorization link and waits. On your computer it can open the browser; in a remote agent environment, use `struct login --device --json` and give the person the link and code. Device login requires server support. `--no-browser` suppresses opening a browser but does not by itself turn a loopback callback into device login: a loopback link must be opened in a browser that can reach the CLI's machine.

Use `struct login --org WORKSPACE_ID --admin --json` when a workspace admin needs to create keys, configure the GitHub deployment webhook or administer members. The person approves this additional permission. A normal login grants read/write access subject to the person's role; requesting admin scope does not make a member an admin. Billing changes stay in the web app.

| Command | What it does |
| - | - |
| `struct login` | Sign in and save a login for one workspace. Prints the sign-in link first, then waits for approval. Opens your browser on your own computer; over SSH, on Linux without a display, or when no browser opens, it uses a device code if the server supports it. Otherwise it prints a loopback link requiring a browser that can reach this machine. Options: `--org <workspace>`, `--device` (requires server support), `--no-browser`, `--with-token` (read a token from stdin; refused for a workspace that already has a saved browser login, so log out of it first), `--timeout <seconds>` (default 900), `--admin` (also ask for the admin permission needed for keys, the GitHub deploy webhook and member administration; workspace admins. It covers only credentials that let something into Struct). |
| `struct whoami` | Show the user, workspace and role of the current login. |
| `struct orgs list` | List the workspaces you have a login for on this server; the current one is marked `*`. |
| `struct orgs switch <workspace>` | Use a saved workspace, or sign in to it if you have no login for it yet. |
| `struct logout` | Revoke the current workspace's login on Struct and remove it from this computer. `--org <workspace>` or `--all` for others. Exits `1` if Struct could not revoke it. |

## Workspace API keys

Use a workspace API key for recurring jobs such as on-call polling or merged-PR coverage. This requires a Struct server that supports workspace automation scopes and an updated CLI with workspace-key support.

In the intended workspace, a workspace admin signs in and creates the key:

```bash theme={null}
struct login --org WORKSPACE_ID --admin
struct keys api create --name devin-oncall --agent-key
```

The preset grants `workspace:read`, `telemetry:read`, `monitors:read`, `monitors:write` and `observations:publish`. For a polling job, pass only the scopes it needs with repeated `--scope` flags. Explicit scopes take precedence over the preset.

Store the key printed at creation in the runner's secret store. Supply it as `STRUCT_TOKEN` when running commands such as `struct whoami --json`, `struct telemetry query` and `struct monitors firings --json`. The CLI uses the key in memory. The optional `workspace:read` scope lets `whoami` verify the workspace ID.

With the write scopes, the key can add Observations, publish its own drafts, end its own overlays, and create or update native monitors. Each scope works only in the key's workspace, with the workspace's feature settings. An admin revokes an automation key with `struct keys api revoke KEY_ID`.

See [workspace API keys for MCP](https://docs.struct.ai/mcp/authentication.md#workspace-api-keys) to use the same key from an unattended MCP client.

## Create a workspace

Requires CLI 2.5.0 or newer and agent signup available on the server. The [agent setup guide](https://docs.struct.ai/quickstart.md) covers the full flow.

```bash theme={null}
struct init --name "My application" --no-wait --json
```

This creates a workspace with a temporary saved login. `--no-wait` returns without issuing an approval link; it includes `workspace`, `claimed: false`, `activeUntil` and `deleteAfter`. Without `--no-wait`, `init` prints a claim link and waits for a person.

| Option | Behavior |
| - | - |
| `--name <name>` | Name a new workspace; does not rename one being resumed |
| `--new` | Deliberately create another workspace, even when already signed in |
| `--no-wait` | Save the temporary login and return so instrumentation can continue |
| `--status` | Check the pending claim once and save the person's login if claimed |
| `--email <address>` | Restrict the claim to that verified email; no email is sent. Use when issuing a claim link, not with `--no-wait` or `--status` |
| `--no-browser` | Print the approval link without opening it |
| `--timeout <seconds>` | How long to wait; defaults to 900 seconds |

Until claim, the temporary key can manage ingest/deployment keys, query telemetry and configure native monitors while the workspace is active and activated. Other setup operations require claim. There may be ten non-deleted native monitors, including disabled ones; deletion frees a slot. Background AI and outbound notifications remain off.

## Claim and resume

```bash theme={null}
struct init --no-browser --json
```

Give the person the `url` and `userCode` from the `waiting_for_human` event. With `--json` they appear only there, on stdout, never on stderr. They sign in, verify the workspace preview and claim it. The CLI then replaces its temporary login with a login acting as the claimer, who becomes the workspace admin. Completion reports `claimed: true` and `loggedIn: true`.

A code can expire while the CLI waits; it prints a replacement until the command's timeout. On `claim_timeout`, the workspace is kept. Run `struct init` again from the same environment to resume, or `struct init --status --json` to check once. Do not use `--new` as a retry.

A workspace that pauses before claim retains configuration and existing firing-history reads. Telemetry queries, previews and new setup changes wait for claim. Check the returned deadlines; on `claim_expired`, follow the command's recovery advice rather than assuming the original workspace is recoverable.

The claim state is saved under `~/.struct/pending-claims/` and logins under `~/.struct/profiles/`, with private file permissions. Preserve them when resuming in the same environment. Do not copy these files into the repository or paste their contents into chat. If you lose this environment after a person claimed the workspace, use `struct login --org WORKSPACE_ID` to authorize a new login.

## Recovery

| Result | Next action |
| - | - |
| `agent_signup_unavailable` | Create/join a workspace at [app.struct.ai](https://app.struct.ai), then `struct login` |
| `already_logged_in` | Confirm the workspace with `whoami`; only use `--new` if another workspace is intended |
| `workspace_unclaimed` | Complete the claim. Use the command's advice for the specific workspace; a supplied `STRUCT_TOKEN` still overrides saved logins afterward |
| `workspace_paused` | Claim before more telemetry queries, previews or setup changes |
| `account_not_activated` | Complete the activation step reported by Struct; another login does not activate the workspace |
| `auth_required` / `write_login_required` | Reauthorize the intended workspace with `struct login --org WORKSPACE_ID` |
| `local_storage_unavailable` | The CLI could not create or write `~/.struct`. Run it where that directory is writable (a sandbox may need write access), or set `HOME` to a writable directory |
| `admin_login_required` | An admin reauthorizes with `--admin`; a member needs help from an admin |
| `rate_limited` | Respect the returned retry guidance; do not create replacement workspaces |

Access tokens last one hour and renew through the saved login. Ninety days without renewal requires sign-in again. Network failures preserve the saved login. `STRUCT_TOKEN` overrides profiles and is never saved automatically. `struct login --with-token` reads a token from stdin, but refuses to overwrite an existing OAuth login for that workspace.

Interactive CLI and MCP logins authorize separately. Installing [Struct MCP](https://docs.struct.ai/mcp/overview.md) supplies the server URL for your client's sign-in.


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