# Set up an agent

> Sign up and log in with one command and a code a person approves, install the CLI, or hand an agent a token.

## 1. Sign up or log in

```sh
npx jsflow-cli signup
```

This needs Node 20 or newer and no installation: `npx` fetches the CLI and runs it. It opens your browser on **Create your jsflow account** (when you are signed out or have no account), and that is the only part a person does. They are asked to:

1. **Choose how to sign in**: GitHub, Google or an email link. An existing account signs in the same way.
2. **Check the code** the terminal shows against the page, and that the device and network are yours.
3. **Approve**, choosing what the tool may do.

The CLI always prints the link and the code as well. It does not open a browser over SSH, in CI, or on Linux without a display (nor with `--no-browser` or `JSFLOW_NO_BROWSER=1`): open the link yourself. When an agent runs it (output is not a terminal), it prints the link and the code as JSON and exits, so the agent can hand them to you; then it runs `npx jsflow-cli login --wait`, which finishes the login.

jsflow is in early access, by invitation. An address that is not invited ends the login at once with a link to the [waitlist](https://jsflow.com/waitlist/). After the login, `signup` prints the next steps: `jsflow apps create`, and the quick start.

**No invitation yet?** Build and run on `http://localhost` or `127.0.0.1` with the shared demo app (up to 16 peers a room); its key is in the [quick start](https://jsflow.com/docs/start/quick-start.md). The demo app is shared, so use a random room name. Your own app key, for your own domain, comes with an invitation: join the [waitlist](https://jsflow.com/waitlist/).

To type `jsflow` instead of `npx jsflow-cli`, install it once:

```sh
npm install -g jsflow-cli
jsflow --version
```

The CLI has no dependencies. To upgrade, run `jsflow upgrade`: it prints the command.

## 2. Give it access

Start with `jsflow whoami`. It reuses a login or token the CLI already has (a stored login, or `JSFLOW_TOKEN`) and shows who it belongs to, the account, its scopes and when it expires. If it works and the scopes cover the task, you are done. If it says you are not logged in, there are two ways. Pick one.

### A person approves a login (recommended)

Run `jsflow login` (or `jsflow signup` for a person with no account yet). On a terminal it prints a link and a code and waits. When an agent runs it (output is not a terminal), it prints the link and the code as JSON and exits at once, so the agent can hand them to you:

```json
{"verification_uri_complete":"https://app.jsflow.com/device?user_code=ABCD-EFGH","user_code":"ABCD-EFGH","expires_in":600,"scopes":"dev","next":"jsflow login --wait"}
```

You open the link, check that the code, the device and the network are yours, choose the scopes, and approve. You need to have signed in within the last 10 minutes. Then the agent runs `jsflow login --wait`, which finishes the login. The token goes straight into the CLI's login file (`~/.config/jsflow/credentials.json`, readable only by you); it never passes through the agent's conversation.

**Approve only a login you started yourself, just now.** A code someone else sends you may be an attempt to get into your account. A code lives 10 minutes and works once, and the owners of the account get an email for each approval.

### You create a token

In the dashboard, open **Access tokens → Create a token**, choose a preset or the scopes, the apps and the lifetime, and copy the value (it is shown once). Give it to the tool through its environment:

```sh
export JSFLOW_TOKEN=jft_…
jsflow whoami
```

`JSFLOW_TOKEN` overrides a stored login. Keep the token in a secrets store, never in a repository, a prompt or an `AGENTS.md`.

## 3. Choose scopes

| preset | for | holds |
|---|---|---|
| `read` | reporting | usage, plan and app settings; no personal data |
| `dev` | day-to-day work | read everything, create and change apps and publishable keys, evict and block |
| `full` | setting up | everything in `dev`, and creating and revoking secret keys (the owners are emailed) |

The [scope list](https://jsflow.com/docs/agents/scopes.md) has each scope. Give the least that does the job, with a short lifetime. Revoke a token on the Access tokens page, or with `jsflow tokens revoke <id> --confirm <id>`; `jsflow logout` revokes the one the CLI is using.

## 4. Tell the agent how to behave

Add the [`AGENTS.md` section](https://jsflow.com/docs/agents/agents-md.md) to your repository, and set `JSFLOW_ACTOR` (for example `claude:usage-report`) so the audit log shows "you via claude:usage-report".

## A first task for an agent

```sh
jsflow apps create myapp --origin https://example.com --dev
jsflow keys create --app myapp --kind secret --write-env .env      # the secret goes to a file, not the transcript
jsflow records --app myapp --since 1h --type join,refusal          # why a join was refused
```

If a command exits with code 4 and `human_required`, give the person the link in the error and stop.

Source: https://jsflow.com/docs/agents/setup/
