# QuiverAI CLI

Add QuiverAI creations and SVG files to your React project as components.

This is the command-line tool. To call the QuiverAI API from code, install the TypeScript SDK, [`@quiverai/sdk`](https://www.npmjs.com/package/@quiverai/sdk).

```sh
npx quiverai add https://app.quiver.ai/creations/<CREATION_ID>
```

`add` writes one `.tsx` or `.jsx` file that exports a self-contained React component. It edits no other file.

Requires Node.js 22.12 or later.

## Add a component

```sh
# A creation, by URL or id
npx quiverai add https://app.quiver.ai/creations/<CREATION_ID>
npx quiverai add <CREATION_ID> --name logo

# The newest creation in a chat
npx quiverai add https://app.quiver.ai/chat/<CHAT_ID> --latest

# A public share link (no login)
npx quiverai add https://app.quiver.ai/share/<SHARE_ID>

# Any SVG file on the web (no login)
npx quiverai add https://example.com/logo.svg --name logo
```

The CLI prints the file it wrote and the line to import it:

```text
Added FoxLogo to src/components/quiverai/fox-logo.tsx
import { FoxLogo } from "@/components/quiverai/fox-logo";
```

The component takes `width`, `height` and `className` props:

```tsx
<FoxLogo width={32} height={32} />
```

### Where the file goes

The first of these that applies:

1. `--path <dir|file>`.
2. `"quiverai": { "dir": "<path>" }` in your `package.json`.
3. The `components` alias in `components.json` (shadcn projects), in a `quiverai/` folder.
4. `src/components/quiverai/` if `src/` exists.
5. `components/quiverai/`.

The file is `.tsx` when the project uses TypeScript and `.jsx` otherwise. In a monorepo, run the command in the app's folder or pass `--cwd ./apps/web`.

### Component name

Without `--name`, the name comes from the creation's file name, or the SVG URL's file name (`fox-logo.svg` becomes `FoxLogo` in `fox-logo.tsx`). In a terminal, the CLI asks `Component name?` with that suggestion filled in; otherwise, or with `--yes`, it uses the suggestion. `React` is reserved and becomes `ReactIcon`.

### Existing files

The CLI never replaces a file silently. If the file exists with different content, it asks first. When it cannot ask (see [Scripts and CI](#scripts-and-ci)), it fails with exit code 1; pass `--overwrite`.

### Options

| Option | Description |
| --- | --- |
| `--name <name>` | Component name, in any case (`fox logo`, `fox-logo`, `FoxLogo`). |
| `--latest` | For a chat link, add the newest creation without asking. |
| `--path <dir\|file>` | Write to this folder or file. |
| `--cwd <dir>` | Project folder. Defaults to the current folder. |
| `-o, --overwrite` | Replace an existing file with different content. |
| `--yes` | Skip prompts: use the suggested name and replace a changed file. |
| `--dry-run` | Run the same steps and show what would be written, without writing. |

## Authentication

Creation and chat links need a QuiverAI account. Share links and SVG URLs do not.

```sh
npx quiverai login    # sign in through your browser
npx quiverai whoami   # shows the signed-in account
npx quiverai logout   # signs out
```

`login` needs a terminal, and is not available with `--json`, `--non-interactive` or `CI`. On a machine without a browser, such as over SSH, press `H` at the login prompt. Open the link on any device, approve, then paste the URL your browser lands on.

`login` signs in as the QuiverAI CLI application, which QuiverAI hosts at `https://app.quiver.ai/oauth/quiverai-cli.json`, whatever `--app-url` is. Set `QUIVERAI_CLIENT_ID` to override that client ID.

The CLI stores credentials in your OS keychain when one is available, and otherwise in a file only your user can read, under `quiverai/` in your config folder: `$XDG_CONFIG_HOME` if set, otherwise `%APPDATA%` on Windows and `~/.config` elsewhere. Set `QUIVERAI_TOKEN_STORAGE` to `keyring` or `file` to choose.

### Credential storage

The keychain service is `quiverai` and the account is the app origin. The optional `@napi-rs/keyring` binding uses macOS Keychain, Windows Credential Manager, or Linux Secret Service. Linux pins Secret Service so a missing service falls back to disk instead of using an in-memory kernel keyring. Installation still works where the native binding is unavailable. Forced `keyring` mode fails if the keychain is unavailable.

The plaintext fallback stores one file per app origin. On POSIX, the directory uses mode `0700` and each file uses `0600`. On Windows, the files inherit the profile directory's ACLs. Writes rename a temporary file from the same directory into place. The first fallback write that creates the file prints its path to stderr. Forced `file` mode is silent. A successful keychain write removes the fallback for that origin. Reads check the file first because a remaining file holds the newest tokens.

`logout` clears the current origin's file and keychain entry. With no `--app-url` or `QUIVERAI_APP_URL` and exactly one saved login, it removes that login; with several, a terminal run asks which and any other run uses the given or default app URL, naming the other saved logins if it removes nothing. If the keychain refuses to delete an existing entry, logout fails and tells you that you are still signed in. The CLI uses a stored access token while it has more than one minute left, then tries to refresh it. If refresh fails, it asks you to sign in again. The fixed one-minute margin works with the application-specific token lifetime configured in WorkOS.

## Scripts and CI

The CLI never prompts when it cannot. A run is non-interactive when `--non-interactive` or `--json` is passed, when `CI` is set to anything but empty, `0` or `false`, or when stdin or stderr is not a terminal. Each prompt then has an answer instead: `add` uses the suggested name, fails when a file differs and `--overwrite` is missing, and asks for `--cwd` or a creation id where it would have shown a picker. It never starts a login; it fails and names `quiverai login`. `login` itself needs a terminal. `--yes` is unchanged.

### Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Success. Declining the overwrite prompt (`Skipped`) and a `logout` with nothing to remove (`Already logged out of QuiverAI.`) are successes. |
| `1` | The command ran and failed: not logged in, not found, no access, a file in the way, the network, a request over 60 seconds, a server error, or an unexpected error. |
| `2` | The command line is wrong or input is missing: an unknown option or command, an invalid value, a missing argument, a choice that needs a terminal, or `login` without one. |
| `130` | A prompt was canceled (`Ctrl-C`). It prints `Canceled.` |

### JSON output

`--json` works with `whoami`, `add` and `logout`. On success, stdout holds one JSON document and stderr is empty. On failure, stdout is empty and stderr holds one line:

```json
{
  "message": "Not logged in to QuiverAI. Run `quiverai login`.",
  "reason": "login_required",
  "status": "action_required",
  "next": [{ "argv": ["quiverai", "login"], "command": "quiverai login" }]
}
```

`reason` is one of `api_error`, `canceled`, `conflict`, `internal_error`, `interactive_required`, `invalid_arguments`, `login_required`, `missing_input`, `network_error`, `not_found`, `permission_denied`, `timeout`, `unknown_command` or `unknown_option`. `status` is `action_required` when input or a step by a person would let the command run (`missing_input`, `interactive_required`, `login_required`) and `error` otherwise. `next` lists a command that recovers the failure, when there is one. Warnings are a `warnings` list of `{ "reason", "message" }` in the document, never stderr text. Usage errors, such as `add --bogus --json`, use the same line.

| Command | Success document |
| --- | --- |
| `whoami` | `{"account":{"email":"ada@example.com","organizationId":"org_1"}}` |
| `add` | `{"component":{"name":"Logo","file":"/abs/path/logo.tsx","importSpecifier":"@/components/quiverai/logo"},"outcome":"added"}`. `outcome` is `added`, `updated` or `unchanged`. With `--dry-run` it is `planned`, plus `"change"`: `add`, `update` or `none`. |
| `logout` | `{"outcome":"logged_out","appUrl":"https://app.quiver.ai"}`, or `"unchanged"` when nothing was saved (then `savedLogins` lists any other saved logins). With `--all`, `"all":true` replaces `appUrl`. |

### Color

Color is on in a terminal. `NO_COLOR` set to anything but empty, or `--no-color`, turns it off and wins over `FORCE_COLOR`.

## Global options

| Option | Description |
| --- | --- |
| `--app-url [url]` | QuiverAI URL to use. Defaults to `https://app.quiver.ai`. Also `QUIVERAI_APP_URL`. Without a URL, in a terminal, it asks you to pick from your saved logins, production and staging, or to type another URL. |
| `-H, --header "Name: value"` | Send a header with every request to the app URL. Repeatable. |
| `--debug` | Print stack traces for unexpected errors. Also `QUIVERAI_DEBUG=1`. |
| `--json` | Print the result of `whoami`, `add` and `logout` as JSON, and an error as one JSON line on stderr. |
| `--non-interactive` | Never prompt. Also the case with `--json`, a truthy `CI`, or when stdin or stderr is not a terminal. |
| `--no-color` | Turn off color. Also `NO_COLOR`. |
| `-h, --help` | Show help. |
| `-v, --version` | Show the version. |

To send the same headers every time, save them per URL in `config.json`, in the same `quiverai/` folder as the credentials:

```json
{
  "headers": {
    "https://app.example.com": { "x-custom-header": "value" }
  }
}
```

A header is sent only to the URL it is listed under. A header value cannot contain a line break.
