# Signing in with the CLI

> branchd auth login, scoped logins with --repo, --group, --scopes and --wait, and branchd auth token.
## Your everyday login

```sh
branchd auth login
```

This signs you in with Xeonr Auth's device-code flow: open the printed
URL, confirm the code, and the sign-in is stored in your OS keychain (or a
`0600` file under `~/.config/branchd`). The CLI refreshes it silently, and
`branchd auth setup-git` and `branchd registry setup-docker` let git and
Docker use it too. `--no-browser` prints the URL without opening a
browser. That is also what happens when there is no terminal.

To use the current token from a script:

```sh
curl -H "Authorization: Bearer $(branchd auth token)" https://branchd.run/…
```

## Agent sessions

An AI agent session on your machine (Claude Code, T3 Code, Codex, or an AI
Sessions run) that runs `branchd`, `git` over HTTPS or `docker` against
branchd acts **as you, with your full permissions**, as soon as you are
signed in: there is nothing to set up, no flag and no variable.

The CLI does not send your login itself. It exchanges it at Xeonr Auth for
a short-lived token for that one session: you are its subject, the branchd
CLI is its actor, and it names the session (`t3:<thread>`,
`aisessions:<session>`, `codex:<thread>` or `claude-code:<session>`). The
token is cached for the session and renewed from your login without a
prompt. Everything done with it, from an API call to a push, a pull
request, a merge or a grant, is recorded as **an agent acting for you, in
that session**, never as you alone:

```sh
$ branchd auth status
signed in as   you@example.com
credential     agent-session
actor          agent session t3:thread-… (client …), acting for the subject
```

Approving what the agent does is your agent tool's job: its permission
prompts are where you allow or refuse a command. branchd checks only what
you yourself may do, and an agent acting for you may do all of it:
changing who has access, issuing personal API keys, approving pull
requests and environment gates (it counts as you, so it never approves your
own work), deleting a published version tag, making something public, and
administering branchd if you do. The same holds for the Xeonr MCP gateway's
branchd tools, within the toolsets you ticked.

- **Not signed in?** The CLI says to run `branchd auth login`, which the
  agent may start for you to approve in your browser.
- **Want a session to reach less?** Give it a session credential
  (`forge_create_session_credential` on the Xeonr MCP gateway) limited to
  some repositories and refs, or a [scoped login](https://docs.branchd.run/branchd/access/cli-login#scoped-logins) with
  `--profile`.
- **In a pipeline job** nothing changes: the job's own token is used, never
  a person's login.
- The session is recognised from the agent tool's environment variables.
  They label the token; they are not a security boundary.

## Scoped logins

A scoped login asks for less than your everyday one. It is a **separate**
login, named with `--profile`, so your default login is untouched:

```sh
# A login that can read one repository: clone it, pull its images, read its pull requests
branchd auth login --profile api --repo acme/api
branchd --profile api repo list acme

# The same, but only for cloning and pulling images
branchd auth login --profile api-pull --repo acme/api --scopes forge:contents:read,forge:package:read
```

| Flag              | Meaning                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------- |
| `--profile NAME`  | Required. The name of this login. Use it with `--profile` on any command.                                |
| `--repo PATH`     | Limit the login to this repository. Repeat, or separate with commas.                                     |
| `--group PATH`    | Limit the login to this group and everything under it. Repeat, or separate with commas.                  |
| `--scopes S,...`  | Ask for only these `forge:` [scopes](https://docs.branchd.run/branchd/access/scopes). Repeat, or separate with commas or spaces. |
| `--wait DURATION` | How long to wait for the browser, for a link that will be opened later (e.g. `4h`). Default `30m`.       |

**Without `--scopes`**, a scoped login asks for the [Read level](https://docs.branchd.run/branchd/access/scopes):
`forge:repository:read forge:contents:read forge:release:read forge:package:read forge:pipeline:read forge:pull-request:read forge:review:read forge:check:read forge:branch-rule:read`
(plus `forge:group:read` on a group). So it can clone and fetch, pull
images, and read releases, pipeline runs, pull requests, reviews, checks
and branch rules, on its repositories and groups only. Pass `--scopes` to
ask for less, or for write scopes such as `forge:contents:edit`.

`forge:repository:read` on its own reaches repository metadata and
settings, not git contents or images: cloning needs `forge:contents:read`
and pulling needs `forge:package:read`. branchd CLI releases before 0.50
asked only for `forge:repository:read forge:pull-request:read
forge:review:read forge:check:read` by default, so a scoped login made with
one of them cannot clone; sign in again with a current CLI.

A scoped login signs in through the **browser**: it pushes its request to
Xeonr Auth ([PAR](https://docs.xeonr.io/auth/guides/rar#using-par)) with each repository
and group as [`authorization_details`](https://docs.xeonr.io/auth/guides/rar) and
branchd as the RFC 8707 `resource`. So it needs a browser that can reach
this machine's loopback address. On the consent screen you can narrow it
further ([what the person grants](https://docs.xeonr.io/auth/guides/consent-narrowing)).

### Using a scoped login with git and Docker

```sh
branchd auth setup-git --profile api
branchd registry setup-docker --profile api
```

`registry setup-docker --profile api` records the profile for
`registry.branchd.run`, so Docker's credential helper answers with that
login, and the registry then serves only its own repositories' images.

Source: https://docs.branchd.run/branchd/access/cli-login
