# Account

## Account: sign up or sign in with an emailed code

The same two commands create a new account or sign in to an existing one.

1. Already signed in? `cofactor setup status --json` succeeds (it calls the API; a 401 means the session is dead, and `whoami` alone is offline and only checks expiry): skip to `source`.
2. Ask the human: "What email address should I use?"
3. Ask the human for the organization name now, so `verify` succeeds the first time: "If this is a new Cofactor account, I'll name the organization `<name from the product or repository>`. OK, or is it an existing account?" A new account needs the name. An existing account must not be given a new one: see `workspace`. Existing account: leave `--organization` out below, or pass an organization it already has.
4. Show the human the Terms (https://runcofactor.com/terms) and Privacy policy (https://runcofactor.com/privacy). Ask: "Do you accept them?" Only on a yes:

   ```bash
   cofactor signup --email <email> --accept-terms --organization "<name>" --json
   ```

   The organization is remembered with the email until verified, so `verify` below needs no `--organization`. Leave `--organization` out for an existing account that has not named one.
   Output: `{email, codeExpiresInSeconds, next}`. A refusal prints `Error (CODE): message` plus a next step; under `--json` it is `{code, error, next}` (see `troubleshooting`). Errors without a catalog code (for example HTTP 401 or 429) print as plain text; see troubleshooting. The email, organization and API are remembered outside the project until verified.
5. Ask the human: "What is the 8-digit code from the email?" One thing only.
6. Verify (the email and organization are remembered from step 4):

   ```bash
   cofactor signup verify --code <8 digits> --json
   ```

   Only if the CLI still asks for an organization (an existing account with several, or a name that matched none of its own), pass `--organization <id|slug|name>` (see `workspace`).
   Success output: `{user, organization, appUrl, created, trackingUrl, next}`. The session is saved; the token is never printed.
7. Re-read, do not trust the exit code:

   ```bash
   cofactor setup status --json
   ```

   It must succeed. Then `cofactor whoami --json` shows the user and organization.

Now give the human the tracking link: `trackingUrl` from the `signup verify --json` output in step 6. Say "Open this to watch my progress." (see `overview`, "Progress page"). It signs them in to the progress page without a password; it works once, within 24 hours. Show it only to the human: do not write it to files, commits, issues or chat channels, and do not paste it into a page that previews links (a preview spends it). If they say it expired or was already used, run `cofactor open --no-open` and give them the link it prints right away (that one lasts 5 minutes). Post a first update: `cofactor setup update --step connect-agent "Signed in to Cofactor from <your coding agent>."`.

If the code expired or was lost: re-run step 4 for a new code (a short wait applies between sends; the error says how long). After 5 wrong guesses a code stops working; run step 4 again for a new one, and if it says to wait, wait (up to 30 minutes after a lockout).

Accounts that require MFA, and accounts that must use the browser login (`cofactor login`), cannot use emailed codes: run `cofactor login` (the human approves in a browser), then continue at `workspace`.

Do not paste the code anywhere but `--code`. Do not run `signup verify` twice with guesses.

Next: `cofactor setup guide workspace`
