# Sign-in and working context

> Buff Code’s first launch: the connector address and the sign-in code confirmed in the workspace; organisation, project, spaces; per-folder memory; devices.

There are no separate setup commands: Buff Code asks for everything it needs on first launch, and you
can change it right while working.

## First launch

1. Run `buff` in the project folder (or open the app). Buff Code asks for **your company’s connector
   address** — the administrator gives it to you; it is also shown in the workspace, on the connector’s
   card, as the “Buff Code sign-in” line. If the administrator handed out the address in advance with
   the `BUFF_CONNECTOR_URL` variable, this step is skipped.
2. Buff Code shows an eight-character **sign-in code** and opens the sign-in page of the workspace
   in the browser. If you are not signed in to the workspace yet, sign in as usual first. Check that the
   code matches the one Buff Code shows, choose the organisation and click **“Allow sign-in”**. The code
   lives for ten minutes.
3. Choose the **organisation**, the **project** (or “No project — organization only”) and, if
   needed, **knowledge spaces**. This is the working context: models, knowledge and tools are taken
   from it, and usage is charged to it. If there is only one organisation, it is chosen without asking.

That’s it. From then on Buff Code works, and the status bar shows the context: “organisation › project · N sp.”.

### In the window

- On first launch the window first gives a short introduction (see [Settings and first
  launch](/en/docs/buff-code/work/settings#first-launch)), and at the end offers “Sign in to Buff”.
- **“Connect Buff”** — the connector address field, a hint “Where to get the connector address”, and “Later”. The address
  is remembered: at the next sign-in (for example, after “Disconnect”) it is already filled in.
- While the code waits for confirmation, the window shows how long it is still valid, “Open cabinet” and
  “Cancel”; for an expired code — “Get a new code”.
- If you are not a member of any Buff organisation yet, the window says so: ask the administrator
  to add you and choose again.
- The sign-in is shown in **“Settings → Providers”**: the line “Buff · Sign-in through the connector · your login ·
  organisation” and “Disconnect”; while no context is chosen, next to it is “Choose an organization and project”.

_Illustration: Sign-in in the window: the company connector address — and the confirmation code in the workspace._

_Illustration: The sign-in page in the workspace: the code from the Buff Code screen, the organisation choice and your devices._

From the console in a single command (`buff run "…"`, `buff models`) whatever is missing is asked
right there — but only in a real terminal. In a script without a terminal Buff Code refuses:
“Buff Code is not set up: run buff to sign in to Buff, or connect your own provider with
buff auth login”. Sign in once interactively, and scripts work from then on.

Signing in to Buff is optional: with your own provider connected (or with `--model` for your own model)
Buff Code works without it. See [Own providers and local models](/en/docs/buff-code/own-providers).

## The context is remembered per folder

The choice of organisation and project is stored **for each folder** Buff Code is started from. In
another folder Buff Code asks again — so in different folders you can work with different
organisations and projects. The sign-in itself is one per machine.

## Switching the organisation, project, space

Inside Buff Code — commands starting with `/`:

| Command | What it does |
| --- | --- |
| `/org` | switch the organisation |
| `/project` | switch the project or choose “No project” |
| `/space` | choose knowledge spaces |
| `/models` | see the organisation’s models |

In the app it is the same — by clicking “Buff context”. The switch applies from the next
message. The choice is checked against a fresh list of what is available to you: if a project was taken
away, Buff Code says “This is not among what is available to you” and offers to choose again.

## Devices

Every sign-in is a separate **device** named after the machine. What happens on the machine at sign-in:

- a device key is created; it signs every sign-in refresh, so a stolen
  token is useless without the device key;
- the access token lives 15 minutes and refreshes itself; the refresh lives 90 days — once every three months
  Buff Code asks you to sign in again.

The list of your devices is on the sign-in page in the workspace: when they signed in and when they were last
seen. There you can also **revoke** a device. A revoked device loses access to models immediately, and to
the connector’s tools within a minute at most. Buff Code on that machine shows
“The sign-in is damaged — sign in again”.

## What goes into the audit log

Confirming and rejecting a sign-in, revoking a device and a rejected token refresh
are recorded in the organisation’s [audit log](/en/docs/audit-log) — with the address and browser of whoever
confirmed. The mere fact that the console requested a code and waited for an answer is not an event. The full
list is on the [Audit log and Buff Code](/en/docs/buff-code/sessions/audit) page.

## Protection against guessing

The sign-in code has eight characters and lives for ten minutes. After five wrong codes within ten
minutes the sign-in page is locked for ten minutes: “Too many wrong codes. Please wait”.
