---
title: "Login and Logout"
description: "Authenticate the CLI against Shelve and manage stored credentials."
canonical_url: "https://shelve.cloud/docs/cli/login-logout"
---
# Login and Logout

> Authenticate the CLI against Shelve and manage stored credentials.

## Login

```bash [terminal]
shelve login
shelve login --no-browser
shelve login --with-token
shelve login --token "$SHELVE_TOKEN"
```

By default, `shelve login` starts a **device authorization** flow (similar to Vercel or GitHub CLI):

1. The CLI opens your browser to Shelve (or prints a URL and short code).
2. Sign in if needed, then click **Authorize CLI**.
3. Shelve creates a revocable API token named `CLI — <hostname>` (90-day expiry, full read/write) and the CLI stores it locally.

You can revoke CLI tokens anytime from [app.shelve.cloud/user/tokens](https://app.shelve.cloud/user/tokens). Tokens are [scopeable, expiring, and IP-bound](https://shelve.cloud/docs/core-features/tokens) when created manually from the dashboard.

### Options

<field-group>
<field name="token" type="string">

API token (skips device login). `SHELVE_TOKEN` is also accepted without running `login`.

</field>

<field name="with-token" type="boolean">

Prompt for a pasted API token instead of browser login.

</field>

<field name="no-browser" type="boolean">

Do not open a browser; print the authorization URL and user code only.

</field>
</field-group>

### Where the token is stored

1. **OS keychain** — Keychain (macOS), Credential Vault (Windows), Secret Service / GNOME Keyring (Linux) via [`@napi-rs/keyring`](https://github.com/napi-rs/keyring).
2. **XDG file fallback** — `$XDG_CONFIG_HOME/.shelve` (typically `~/.config/.shelve`), mode `0600`, when the keychain is unavailable.

<callout type="info">

Legacy `~/.shelve` is migrated automatically on first read with v5+.

</callout>

## Me

```bash [terminal]
shelve me
shelve --json me
```

Human mode prints the logged-in username and email. JSON mode returns `{ "loggedIn": true, "username", "email" }` or `{ "loggedIn": false }`.

## Logout

```bash [terminal]
shelve logout
shelve --json logout
```

Clears the keychain entry and XDG config. JSON returns `{ "loggedOut": true }`.

## Non-interactive environments

Skip `shelve login` in CI and agents — set `SHELVE_TOKEN` directly:

```bash [terminal]
SHELVE_TOKEN="$SHELVE_TOKEN" shelve --non-interactive run -- pnpm test
```

The CLI reads `SHELVE_TOKEN` before the keychain. Pair with scoped, expiring tokens for least privilege.

<callout type="warning">

Never commit `SHELVE_TOKEN`. Use your CI provider's secrets store.

</callout>

## Multiple accounts

One account per machine. To switch: `shelve logout`, then `shelve login` again.


## Sitemap

See the full [sitemap](https://shelve.cloud/sitemap.md) for all pages.
