> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mutagent.io/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI installation

> Install the Mutagent CLI, sign in (in a terminal, from a coding agent, or with an API key), choose a workspace, and check that it worked.

The Mutagent CLI (`@mutagent/cli`) is published on
[npm](https://www.npmjs.com/package/@mutagent/cli). Every other page assumes you have done the four
steps on this page: install, sign in, choose a workspace, check.

## Requirements

| Requirement | Minimum | Notes |
| - | - | - |
| Bun | ≥ 1.1 | Recommended package runtime |
| Node.js | ≥ 22.18 | Alternative package runtime |
| OS | macOS · Linux · Windows | — |

You also need a Mutagent account. If you have none, the browser sign-in below creates one.

## 1. Install

```bash bun theme={null}
bun add -g @mutagent/cli
```

```bash npm theme={null}
npm install -g @mutagent/cli
```

```bash pnpm theme={null}
pnpm add -g @mutagent/cli
```

Check that the binary is on your `PATH`:

```bash theme={null}
mutagent --version
```

It prints the version number and exits 0. If the shell says `command not found`, your package
manager's global bin directory is not on `PATH`.

## 2. Sign in

Pick the way that fits who is at the keyboard. All three save a key on this machine. The key works in
every workspace you belong to in that organization, for 30 days.

> [tab] You, in a terminal
>
> ```bash theme={null}
> mutagent login
> ```
>
> The CLI asks whether to sign in with the browser or paste an API key. The browser sign-in opens
> app.mutagent.io, where you sign in or create an account and approve the CLI. The CLI waits up to
> 5 minutes. The first sign-in in a terminal ends with a short setup menu.

> [tab] A coding agent, with a person
>
> ```bash theme={null}
> mutagent login --browser --json
> ```
>
> The CLI does not open a browser here. It prints the sign-in URL as the first line of output, then
> waits up to 5 minutes:
>
> ```json theme={null}
> {"event":"auth_url","url":"https://app.mutagent.io/…","expiresAt":"…"}
> ```
>
> The agent shows that URL to the person verbatim. The person opens it, signs in and approves. The
> CLI then prints the result on the next line (see [the result](#check-that-it-worked)).

> [tab] CI or an agent with a key
>
> ```bash theme={null}
> export MUTAGENT_API_KEY=mg_live_...
> mutagent login --json
> ```
>
> With `MUTAGENT_API_KEY` set, `mutagent login` opens no browser: it checks the key and saves it.
> Mutagent keys start with `mg_live_`. See [API keys](https://docs.mutagent.io/quickstart/api-keys.md).

> [!NOTE]
>
> Every command reads `MUTAGENT_API_KEY` when it is set, even without `mutagent login`. A key you
> never saved with `mutagent login` has no saved workspace, so `mutagent workspaces use` refuses it:
> name the workspace with `MUTAGENT_WORKSPACE_ID` or `--workspace` instead. Run
> `mutagent login --json` once if you want `workspaces use` to work.

`mutagent login --json` without `--browser` and without `MUTAGENT_API_KEY` cannot ask how to sign in
when there is no terminal, so it fails and tells you to add one of them.

To sign in to another organization, name it. It is preselected on the approval page:

```bash theme={null}
mutagent login --org <organization-slug>
```

All sign-in flags and environment variables are on [Sign in](https://docs.mutagent.io/cli/commands/login.md).

## 3. Choose a workspace

Every command works in one workspace. Sign-in selects one when it can: the workspace you approved in
the browser, or your only workspace. List your workspaces and select one:

```bash theme={null}
mutagent workspaces list --json
mutagent workspaces use <workspace-name> --json
```

In the list, `selected: true` marks the current workspace. The workspace is chosen in this order: the
`--workspace` flag on the command, then the `MUTAGENT_WORKSPACE_ID` environment variable, then the
workspace you chose with `mutagent workspaces use`. Create workspaces in the web app at
app.mutagent.io.

## 4. Check that it worked

```bash theme={null}
mutagent workspaces current --json
```

```json theme={null}
{
  "success": true,
  "scope": "organization",
  "organization": { "id": "org_…", "name": "acme" },
  "workspace": { "id": "<workspace-id>", "name": "staging" },
  "expiresAt": "2026-10-13T15:51:27.381Z"
}
```

Exit code 0 and a `workspace` object mean you are ready. The CLI asks the server, so the answer is
checked, not read from local settings.

`mutagent auth status --json` checks the sign-in alone. It returns `"authenticated": true`, the
`endpoint` and `keyPrefix`, and exits 0 when the server accepts the key.

The JSON a successful `mutagent login --json` prints has the same information:

```json theme={null}
{
  "success": true,
  "authenticated": true,
  "endpoint": "https://api.mutagent.io",
  "workspace": { "id": "<workspace-id>", "name": "staging" },
  "organization": { "id": "org_…", "name": "acme" }
}
```

It also carries `_directive.next`, the follow-up commands to run after a success; on a failure, read
`_agentGuidance.fix` instead (see [which field to read](https://docs.mutagent.io/cli/json.md#coding-agents)). `"workspace": null` means no workspace
is selected yet: run step 3.

## Exit codes

| Code | Meaning | Fix |
| - | - | - |
| 0 | Success. | |
| 1 | The command failed, including a wrong flag or argument. | Read `error` and `suggestedAction` in the `--json` output. |
| 2 | The API key expired, was revoked, or is not a valid Mutagent key. | Run `mutagent login` again, or set a valid `MUTAGENT_API_KEY`. |
| 3 | Not signed in, or no workspace selected. | Run step 2 or step 3. |

> [accordion] Exit 3, AUTH\_REQUIRED: not signed in
>
> No saved key and `MUTAGENT_API_KEY` is not set. Sign in (step 2).

> [accordion] Exit 3, WORKSPACE\_REQUIRED: no workspace selected
>
> Run `mutagent workspaces list --json`, then `mutagent workspaces use <workspace-name>`. With a
> `MUTAGENT_API_KEY` you did not save with `mutagent login`, set `MUTAGENT_WORKSPACE_ID` or pass
> `--workspace <name-or-id>` instead.

> [accordion] Exit 2: key expired or invalid
>
> The saved key is older than 30 days, was revoked, or is not a Mutagent key. Sign in again.

> [accordion] The browser sign-in timed out
>
> Nobody approved the URL within 5 minutes. Run the same command again and approve the new URL.

See [Errors and exit codes](https://docs.mutagent.io/cli/errors.md) for every error code.

## Settings

To inspect the saved settings:

```bash theme={null}
mutagent config list
mutagent config get endpoint
```

## Uninstall

```bash bun theme={null}
bun remove -g @mutagent/cli
```

```bash npm theme={null}
npm uninstall -g @mutagent/cli
```

To also remove saved credentials, run `mutagent auth logout` first, or delete `~/.config/mutagent`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.