Sign in from the CLI

Sign the cruxy CLI in with device login, know what the credential it saves can do, when it expires, and how to sign out and revoke it.

The CLI signs in with device login: it shows you a link and a code, you approve in a browser, and the gateway issues a key that the CLI saves on your machine. For how device login works on the API side, see Get your API key.

Sign in with device login

Run cruxy login in a terminal. The first cruxy run in a terminal with no key runs the same flow.

  1. Start the login

    cruxy login

    If a credential is already saved, the CLI says that this replaces it and that there is no undo. If CRUXY_API_KEY is set, it warns that the environment always wins: the new credential is saved, but requests keep using the environment variable until you unset it.

  2. Open the link and check the code

    The CLI asks the gateway for a device code and prints where to approve it. The values come from the gateway; these are examples:

    To sign in, open https://cruxy.ai/device?user_code=WDJB-MJHT
    and enter the code WDJB-MJHT
     
    waiting for approval (expires in 10 minutes)…

    The link already carries the code when the gateway provides one; otherwise type the code on the page. The approval page names the CLI as the client, because the CLI sends Cruxy-Client: cli/<version> when it starts the login.

  3. Approve in the browser

    Approve the request before the code expires. The browser can be on another machine. While it waits, the CLI polls the gateway, and slows down when the gateway asks it to.

  4. Confirm it is saved

    On approval, the CLI saves the credential to ~/.cruxy, says it is signed in, names the organization the credential is bound to and your role in it, and prints the date the credential expires. The last two lines look like this:

      organization: Acme (admin)
      it expires on 2027-01-25; run `cruxy login` again before then.

    The organization decides whose memory, standing rules, and budget the session draws on, and a login does not always bind to the same organization as the last one. The CLI does not send a test request: the gateway issued the key on that same connection. On a first run, the CLI then carries on into the task or session you started.

When sign-in does not finish

Each of these leaves any saved credential untouched and suggests cruxy login --paste. Under cruxy login, the CLI then prints that the login was not completed and exits 1.

The CLI saysWhat happenedWhat to do
the sign-in was declined in the browser.The request was declined on the approval page.Run cruxy login again if that was a mistake.
the code expired before it was approved.Nobody approved it in time.Run cruxy login for a new code.
that sign-in could not be completed.The gateway refused the device code.Run cruxy login to start over.
couldn't reach the gateway to sign in.The login could not start, or the gateway gave an answer the CLI does not expect. Network drops while it waits for approval are retried until the code expires.Check your connection and cruxy.gatewayUrl, then run cruxy login again.

Without a terminal, cruxy login does not start: it prints that it is interactive and exits 1.

The CLI sends a credential only over https://, and over plain http:// only to localhost, 127.0.0.1, or [::1]. With any other cruxy.gatewayUrl, cruxy login, cruxy logout, and every other command that calls the gateway fail before a request is made, with CRUXY_E_CONFIG_INVALID (exit 3); see Gateway URL.

Where the credential is stored

The CLI writes the credential to ~/.cruxy/credentials.json, never to a config file or to your project. Next to the key it records the expiry the gateway stated, the key's id, that it came from device login, and the organization and role it is bound to, so cruxy logout can name them.

The file is readable only by you: mode 0600 in a 0700 directory on macOS and Linux, and an access-control list for your user alone on Windows. If the CLI cannot make it owner-only, for example on a FAT or exFAT drive, it refuses to write the key and fails with CRUXY_E_CREDENTIALS_UNPROTECTED.

When the CLI reads a key from a file that other users can read, it first makes the file owner-only and warns once that anything in it may already have been copied: run cruxy login for a new key, revoke the old one in the Console, and issue any MCP tokens stored there again. If it cannot make the file owner-only, it refuses to read it and fails with CRUXY_E_CREDENTIALS_UNPROTECTED; set CRUXY_API_KEY instead.

Which key the CLI uses

  1. CRUXY_API_KEY in the environment, if it is set.
  2. Otherwise, the credential saved in ~/.cruxy/credentials.json.

The environment always wins, and the CLI never reads a key from a config file. cruxy config list --origin shows whether a key is set.

What a signed-in credential does

A device-login credential is a signed-in credential. Its bucket in GET /api/v1/limits is subscription, and cruxy limits shows your plan's weighted-token pool and what is left of it. A developer API key, pasted or set in CRUXY_API_KEY, works only on a plan with API access, and cruxy limits shows its pool too once the gateway reports one. On a plan without API access, the CLI reports CRUXY_E_PAID_PLAN_REQUIRED and exits 22.

Whatever the key, the CLI states the gateway's memory and rules on every chat request in a session, so your config decides them and the kind of key does not:

  • Memory recall is on (cruxy.memory.recall).
  • Memory capture is off (cruxy.memory.capture). Turn it on in config, or for one run with --memory-capture.
  • Your organization's standing rules are on (cruxy.rules).

--no-memory turns recall and capture off for one run. See Gateway memory and rules for the secret guard and the version pin, and Memory and Standing rules for what each one does. This gateway memory is separate from the CLI's own local memory; see Projects, permissions, and context.

Use a key you already have

cruxy login --paste takes an existing key instead of approving in a browser, for example on a machine with no browser to approve in.

cruxy login --paste

The CLI points you to the Console's API keys page, https://platform.cruxy.ai/keys, to create a developer API key. It reads the key with masked input, checks it with one small chat request that sends memory off, and saves it only if the gateway accepts it. You get three tries. A key whose account's plan has no API access is not saved and not retried: the CLI reports CRUXY_E_PAID_PLAN_REQUIRED and exits 22. A pasted key is saved with no expiry or organization, because the CLI is not told either. A developer API key from the Cruxy Console does not expire.

Expiry

A device-login credential stops working 90 days after it is issued. Using it does not extend it.

  • At login, the CLI prints the expiry date.
  • In the last 7 days, each run and each session start prints a notice that your sign-in expires in a given number of days, with cruxy login as the fix.
  • After expiry, requests fail with CRUXY_E_AUTH_EXPIRED, titled "your cruxy login has expired", and exit 4. Run cruxy login for a new credential.

The gateway answers an expired key with the same 401 it gives a wrong one. The CLI tells them apart only from the expiry it recorded at login, so an expired pasted key reports CRUXY_E_AUTH_INVALID instead. This check runs when a 401 ends the command, such as a one-shot cruxy run, and it reads the saved credential even when CRUXY_API_KEY is the key in use. Inside an interactive session, a turn the gateway rejects reports CRUXY_E_AUTH_INVALID either way. The expiry notice also reads the saved credential, whatever key is in use.

Sign out

cruxy logout

cruxy logout revokes the saved credential at the gateway with DELETE /api/v1/me/key (see Revoke the current key), then removes it from ~/.cruxy/credentials.json, and names the organization it signed out of:

✓ signed out of Acme (admin)
  key <key id>: revoked at the gateway and removed from ~/.cruxy

A key the gateway already refuses, because it was revoked or has expired, also counts as signed out: the CLI removes it and says so. In both cases the command exits 0. A pasted key has no organization recorded, so the first line says that instead of naming one.

In every other case the credential stays saved, you are still signed in, and the command fails:

OutcomeCodeExit
The key is not allowed to revoke itself, such as a read-only or scoped key. Revoke it in the Console at https://platform.cruxy.ai/keys, then run cruxy logout again to remove it.CRUXY_E_AUTH_INVALID4
The gateway cannot be reached.CRUXY_E_GATEWAY_UNREACHABLE5
The gateway answered with an error after retries, or with a redirect, which the CLI does not follow with a credential.CRUXY_E_API6

When the gateway cannot be reached and you are at a terminal, the CLI asks whether to remove the credential from this machine anyway. Only y removes it, and then the key is not revoked: it stays valid until it expires or you revoke it in the Console, and the CLI warns you of that. Without a terminal it never asks, and keeps the credential.

With no credential saved, cruxy logout says there is nothing to remove and exits 0. It never revokes a key in CRUXY_API_KEY: if that variable is set, the CLI warns that it still uses it, and you finish signing out by unsetting it. MCP server tokens you stored with cruxy mcp login stay in the file.

To replace the credential instead, run cruxy login again. The new credential overwrites the old one in ~/.cruxy/credentials.json, and the old one stays valid until it expires or is revoked, so run cruxy logout first if you no longer want it to work.

In CI and scripts

cruxy login and cruxy init need a terminal. Elsewhere, set CRUXY_API_KEY. For a shared server or CI job, use a developer API key from the Cruxy Console, not your own signed-in credential: a signed-in credential is bound to you and your organization, and expires after 90 days. See Get your API key.

Was this page helpful?