# Multiple orgs

> Use one machine with several Comity orgs, and bind each repo to its org with comity.json.

If you belong to several Comity orgs (for example your company and a client), log in to each one. The CLI keeps one login per org, and each repo's committed `comity.json` decides which org its agents report to.

## Log in to each org

```sh
comity login --org acme
comity login --org globex
comity orgs
```

```text
Logged-in orgs
  * acme    Acme Inc · diego@acme.com · https://api.comity.so  ← this repo
    globex  Globex · diego@globex.com · https://api.comity.so
  * default: repos without a comity.json · change it with comity use <org>
```

Each `comity login` adds an org and keeps the others. `comity logout --org <org>` removes one; `comity logout --all` removes all of them.

## Bind each repo

```sh
cd ~/code/globex-app
comity init --org globex
git add comity.json && git commit -m "Bind repo to Comity org globex"
```

`comity init` writes [`comity.json`](/docs/reference/cli#comityjson) with the org and server. Once it's committed:

- your agents in this repo always use your `globex` login, whatever your default org is;
- teammates who pull it report to the same org;
- a teammate without a `globex` login gets "This repo uses Comity org `globex`. Run `comity login --org globex`." and nothing is sent to any other org;
- the server refuses a token of another org for this repo (`409 org_mismatch`).

## The default org

Repos without `comity.json` (for example ones set up before CLI 0.6) use the default org: the first one you logged in to, or the one you pick with `comity use <org>`. Run `comity init` in such repos to bind them.

`COMITY_TOKEN` overrides all of this; see [Which credentials apply](/docs/reference/environment-variables#which-credentials-apply).

## Keep unknown repos out

By default, the first hook in a repo the org doesn't know registers it. Owners and admins can turn off **Settings → Organization → Automatically add new repositories** (`auto_register_repos` on [`PATCH /v1/org`](/docs/reference/rest-api#account)). Then only repos whose `comity.json` names the org, or that an admin adds, join it; agents in other repos get a notice and run uncoordinated.
