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

# Log in to the Square Cloud CLI

> Log in to the Square Cloud CLI from the browser, with an API key or through SQUARECLOUD_API_KEY in CI, check the current account and renew an expired key.

<Steps>
  <Step title="Start the login">
    Run the login command in your terminal:

    ```bash theme={"system"}
    squarecloud auth login
    ```

    The CLI shows a short code and opens the authorization page in your browser.
  </Step>

  <Step title="Approve in the browser">
    Type the code on the page and approve. The CLI receives its own API key, no copy and paste needed, and saves it on this machine.

    ```bash Output theme={"system"}
    ✓ Logged in as <email>.
    This API key expires on <date>.
    ```
  </Step>
</Steps>

A key issued this way has only the permissions the CLI's commands use and expires after **90 days**. [`auth whoami`](#squarecloud-auth-whoami) shows the date; run `squarecloud auth login` again to renew it.

The key is saved in a `config.json` file readable only by you: in `%APPDATA%\Square Cloud CLI` on Windows, and in `$XDG_CONFIG_HOME/squarecloud` or `~/.config/squarecloud` on macOS and Linux.

## `squarecloud auth login`

```bash Usage theme={"system"}
squarecloud auth login [--no-browser] [--token <key> | --with-token] [-y]
```

| Flag | Description |
| - | - |
| `--no-browser` | Prints the authorization link without opening a browser. Use it in SSH sessions and containers, and open the link on any device. |
| `--token <key>` | Logs in with an API key you created in the [dashboard](https://squarecloud.app/en/account/security). The key is checked before it is saved. |
| `--with-token` | Reads the API key from stdin, for scripts. Can't be combined with `--token`. |
| `-y`, `--yes` | Replaces the saved key of another account without asking. |

```bash theme={"system"}
squarecloud auth login --token <API key>
# Logs in with an existing API key.
```

```bash theme={"system"}
echo "$SQUARECLOUD_KEY" | squarecloud auth login --with-token
# Reads the API key from stdin.
```

```bash Output with an API key theme={"system"}
API key saved. You are now logged in as <name>.
With great power comes great responsibility!
```

* Press `Ctrl+C` to cancel a login that is waiting for approval.
* If this machine is already logged in to another account, `auth login` asks before replacing it. Pass `-y` to skip the question.
* If your account has reached its API key limit, the browser login says so and continues on its own as soon as you revoke a key in the [dashboard](https://squarecloud.app/en/account/security).
* Without a terminal, the command doesn't prompt: it exits with a hint. With `CI=true`, the browser login refuses to run. See [CI and scripts](#ci-and-scripts).

## `squarecloud auth whoami`

```bash Usage theme={"system"}
squarecloud auth whoami [--json]
```

Shows the account you are logged in as, its plan and how many days are left before the plan expires. For a key issued by the browser login, it also shows when the key expires and its scopes; when the key comes from `SQUARECLOUD_API_KEY`, it says so instead.

```bash Output theme={"system"}
You are currently logged in as <name> on the <plan> plan.
You have <days> days left before your plan expires.
Your API key expires on <date>.
Scopes: <scopes>
```

With `--json`, it prints the account (ID, name, email, locale, plan and creation date) as JSON.

## `squarecloud auth logout`

```bash Usage theme={"system"}
squarecloud auth logout
```

Removes the saved API key from this machine. It doesn't revoke the key: to do that, delete it in the [dashboard](https://squarecloud.app/en/account/security). When `SQUARECLOUD_API_KEY` is set, commands keep using it after a logout.

```bash Output theme={"system"}
You have successfully logged out of your Square Cloud account.
```

When no account is connected, it prints `No account is connected on this machine.` and exits with code 0.

## CI and scripts

In CI, don't log in at all: create an API key in the [dashboard](https://squarecloud.app/en/account/security) and set it in the `SQUARECLOUD_API_KEY` environment variable. Every command uses it instead of the saved key, and the CLI runs even on machines without a home folder.

```bash theme={"system"}
export SQUARECLOUD_API_KEY=<API key>
squarecloud commit <appID> --restart
```

* Without a terminal, `auth login` doesn't prompt for anything: it exits with a hint. Use `--with-token`, `--token` or `SQUARECLOUD_API_KEY`.
* With `CI=true`, the browser login refuses to run, since its key expires in 90 days and only a person can renew it.

More on exit codes and JSON output in [Global flags and CI](/en/cli-reference/global-flags-and-ci#scripts-and-ci).

## When the key stops working

If a command says your session expired or the API key was revoked, run `squarecloud auth login` again. Commands that need an account print `You need to be logged in to run this command.` and exit with code 1 when no key is saved or set.

## Related

| Task | API | JavaScript SDK | VS Code |
| - | - | - | - |
| Show the current account | [`GET /v2/users/me`](/en/api-reference/endpoint/users/me) | [`api.account.me()`](/en/sdks/js/client) | Status bar item |
| Log in | [API keys](/en/api-reference/authentication) | [`new SquareCloudAPI(key)`](/en/sdks/js/client) | [Connect Account](/en/vscode-extension/installation#install) |


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