# Auth and CLI Config

Sign in with agentclash auth, manage CLI tokens, and understand where the CLI stores config and how it resolves the API URL, workspace, and token.

Source: https://www.agentclash.dev/docs/reference/auth-and-config
Markdown export: https://www.agentclash.dev/md/docs/reference/auth-and-config

This page covers the `agentclash auth` and `agentclash config` commands, the files they write, and the environment variables that override them in CI. For worker and API server settings see the [Config Reference](https://www.agentclash.dev/md/docs/reference/config).

## Sign in

```bash
agentclash auth login            # opens a browser to approve the login
agentclash auth login --device   # print the verification URL instead of opening a browser
agentclash auth login --force    # start a new browser login even if credentials are valid
agentclash auth status           # show who the CLI is authenticated as
agentclash auth logout           # delete stored credentials
```

`auth login` prints a verification link, opens it in your default browser when possible, and waits for you to approve the login. Use `--device` in headless or remote shells. Browser login needs an interactive terminal; in CI set `AGENTCLASH_TOKEN` instead.

`auth status` calls the API and prints your user ID, email, display name, and the number of organization and workspace memberships. If you are not logged in it prints a message and exits with code 1. With `--json` it returns the raw session object.

`auth logout` only deletes the stored credentials file. It does not unset `AGENTCLASH_TOKEN`, and it does not revoke the token on the server (use `auth tokens revoke` for that).

## CLI tokens

```bash
agentclash auth tokens list              # ID, name, last used, created
agentclash auth tokens revoke <token-id>
```

`tokens list` shows your CLI tokens (a token that has never been used shows `never` under Last Used). `tokens revoke` revokes one by ID.

## Where things are stored

| Item | Location | Notes |
| --- | --- | --- |
| User config | `~/.config/agentclash/config.yaml` | Written by `config set`, `workspace use`, and `link`; mode `0600` |
| Credentials | `~/.config/agentclash/credentials.json` | Written by `auth login`; JSON with the token and optional expiry, user ID, and email; mode `0600` |
| Project config | `.agentclash.yaml` | Optional; found by searching from the current directory upward. Keys: `workspace_id`, `org_id` |

If `XDG_CONFIG_HOME` is set, the directory is `$XDG_CONFIG_HOME/agentclash` instead. The config directory is created with mode `0700`. The saved baseline bookmark (`agentclash baseline set`) is also kept in the user config file, per workspace.

## Read and write config

```bash
agentclash config list
agentclash config get api_url
agentclash config set output json
```

Valid keys are `default_workspace`, `default_org`, `api_url`, and `output`. `config set` rejects unknown keys, and `output` must be one of `table`, `json`, or `yaml`. `config get` on an unset key exits with an error in table mode; with `--json` it returns `{"key": "...", "value": null}` and exits 0. `config list` prints `(not set)` for empty values.

## How values are resolved

**API URL**, highest priority first:

1. `--api-url` flag
2. `AGENTCLASH_API_URL` environment variable
3. `api_url` in the saved user config
4. Built-in default: `https://api.agentclash.dev` for released binaries, `http://localhost:8080` for source builds

**Workspace**, highest priority first:

1. `--workspace` / `-w` flag
2. `AGENTCLASH_WORKSPACE` environment variable
3. `workspace_id` in the nearest `.agentclash.yaml`
4. `default_workspace` in the saved user config

**Organization** uses `AGENTCLASH_ORG`, then `org_id` in `.agentclash.yaml`, then `default_org` in the user config.

**Token**: when `AGENTCLASH_TOKEN` is set it always takes precedence over the stored credentials file. If you run `auth login` while it is set, the CLI saves the new credentials but warns that the environment variable still wins.

## CI usage

```bash
export AGENTCLASH_API_URL="https://api.agentclash.dev"
export AGENTCLASH_TOKEN="<cli-token>"
export AGENTCLASH_WORKSPACE="<workspace-id>"

agentclash run list
```

No `auth login` is needed when `AGENTCLASH_TOKEN` is set. Pair this with `--non-interactive` (also implied by `CI` and `AGENTCLASH_NONINTERACTIVE`) so the CLI fails fast instead of prompting.

## See also

- [CLI Reference](https://www.agentclash.dev/md/docs/reference/cli)
- [Config Reference](https://www.agentclash.dev/md/docs/reference/config)
- [CI/CD agent gates](https://www.agentclash.dev/md/docs/guides/ci-cd-agent-gates)