---
title: "CLI"
description: "npx nuxt-backend: init, dev, doctor, status, env push, env rotate, billing sync, billing reset, billing resync, access admit, email sync, inbox, upgrade, deploy, analyze, eject and mcp, with every flag and each command's contract."
canonical_url: "https://nuxt-backend.dev/docs/reference/cli"
---
# CLI

> npx nuxt-backend: init, dev, doctor, status, env push, env rotate, billing sync, billing reset, billing resync, access admit, email sync, inbox, upgrade, deploy, analyze, eject and mcp, with every flag and each command's contract.

Version: nuxt-backend 0.6.x · Tab: Reference · Kind: reference · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/cli/contract.ts)

`npx nuxt-backend <command>` ships with the package and covers an app's life from the terminal: scaffold it, run it, check it, push its env, sync its billing catalog and email topics, read its dev inbox, upgrade it and deploy it. Each section below gives one command's flags and its contract: what it may change, what `--json` prints, and what each exit code means.

Every command takes `--cwd <dir>` (default `.`, the project directory) and reads `.env` and `.env.local` from it. A deployment's env is read by name, through `npx convex env list`. A **value** is read only where a name alone says too little, and never printed: `BACKEND_ENVIRONMENT` (by `status`, `doctor --prod` and `billing sync`), and the origin of production's `SITE_URL` under `--prod`. A value the CLI sets reaches `npx convex env set` on its stdin, never as an argument.

No command needs an answer: every input is a flag, so a coding agent or a script runs each one unattended. A few ask at a terminal, and only there: the first run of [`dev`](#dev) with no deployment configured, which hands the terminal to `convex dev` for the Convex login, and `doctor --fix`, which asks for the first administrator's address on a deployment with none and asks before each change it makes at a provider (`--yes` answers for it). An empty answer skips it, and `--json` or a run without a terminal never asks. Each command states its contract, which `--help` repeats at the end of its description:

- **Side effects:** what it may change. The classes are *reads only*, *writes project files*, *writes the dev deployment*, *writes a preview deployment*, *writes project env defaults*, *writes production* and *writes provider accounts*. A flag that changes them is named with them: `doctor` reads only, and writes with `--fix`.
- **--json:** stdout is one JSON document, and progress lines go to stderr. The shapes are stable (see [Stability](https://nuxt-backend.dev/docs/ship/releases/stability)); the wording of text output is not.
- **Exit codes:** `0` and `1` everywhere, plus `130` when `dev` is interrupted.

## `init`

Scaffold the backend files, `.env.example`, the `nuxt.config` wiring and the files your coding agent reads. Run it again any time to restore missing files: it never touches an existing scaffold file unless you pass `--force`.

`npx nuxt module add nuxt-backend` is the whole install: the module's install step runs this same setup once, at an interactive terminal, asks whether to write the agent files, and installs `convex` with the project's package manager. `init` is for restoring files, and for a project where the package was added another way, or without a terminal (CI, a coding agent).

```bash
npx nuxt-backend init
npx nuxt-backend init --force       # overwrite existing scaffold files
npx nuxt-backend init --agents      # rewrite only the agent files, for the installed version
npx nuxt-backend init --no-agents   # skip AGENTS.md, .mcp.json and the agent skills
npx nuxt-backend init --json        # what it wrote, as one JSON document
```

**Side effects:** writes project files. **--json:** `{ created, agentsMd, mcpJson, skills, pnpmWorkspace, appComponent, devScript, convexDependency, mcpSdkDependency, nuxtConfig, next }`, or `{ agentsMd, mcpJson, skills, mcpSdkDependency, pnpmWorkspace }` with `--agents`, where `skills` is `{ installed, refreshed, removed, stale }`, each a list of skill names, and `pnpmWorkspace` is `created`, `added`, `unchanged`, `manual` or null; progress goes to stderr. **Exit codes:** `0` done: every file written, or already in place; `1` a file could not be written, or AGENTS.md was refused: its nuxt-backend markers don't pair up.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --force
      </code>
    </td>
    
    <td>
      Overwrite existing scaffold files (and <code>
        .env.example
      </code>
      
      ), replace the <code>
        nuxt-backend
      </code>
      
       section of <code>
        AGENTS.md
      </code>
      
      , and replace the agent skill copies another version wrote, as <code>
        --agents
      </code>
      
       does.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --agents
      </code>
    </td>
    
    <td>
      Rewrite only the agent files, for the version the app has installed: the <code>
        nuxt-backend
      </code>
      
       section of <code>
        AGENTS.md
      </code>
      
       (the text around it stays), the <code>
        nuxt-backend
      </code>
      
       server in <code>
        .mcp.json
      </code>
      
      , and the agent skills in <code>
        .agents/skills/
      </code>
      
      , each replaced whole. On pnpm 12.11 or later, once the skills are copied, it also adds <code>
        skills: false
      </code>
      
       for nuxt-backend under <code>
        permissions
      </code>
      
       in the nearest <code>
        pnpm-workspace.yaml
      </code>
      
      , which can be a monorepo root's. Nothing else is scaffolded, and <code>
        --json
      </code>
      
       prints <code>
        { agentsMd, mcpJson, skills, mcpSdkDependency, pnpmWorkspace }
      </code>
      
      . Run it after <a href="#upgrade">
        <code>
          upgrade
        </code>
      </a>
      
      , whose <code>
        next
      </code>
      
       lists <code>
        init --agents
      </code>
      
       when the agent files name another version; <code>
        doctor
      </code>
      
      's <a href="https://nuxt-backend.dev/docs/reference/cli/diagnostics#agent-files">
        <code>
          agent-files
        </code>
      </a>
      
       finding says when.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --no-agents
      </code>
    </td>
    
    <td>
      Skip <code>
        AGENTS.md
      </code>
      
      , <code>
        .mcp.json
      </code>
      
       and the agent skills.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

What it writes, each file only when it needs it:

- **The scaffold**, every missing file, into the Convex functions directory: `convex.json`'s `functions`, else an existing `backend/` or `convex/`, else `backend/`. The scaffold holds only the files the package calls into: no empty `aggregates.ts`, `search.ts`, `crons.ts` or `migrations.ts`, and no demo functions. [Project files](https://nuxt-backend.dev/docs/reference/configuration/project-files) lists each file.
- **.env.example**, grouped by capability.
- **nuxt.config.{ts,js,mjs}**: `'nuxt-backend'` added to `modules` with magicast, or a message that tells you to add it.
- **app/app.vue** (or `app.vue`): its `<NuxtWelcome />` replaced with `<NuxtPage />` while it is still the `create nuxt` starter. A root component that already renders `<NuxtPage />` stays as it is.
- **app/layouts/default.vue**: `<AppShell>` around the page, when the root component renders `<NuxtLayout>` and the app has no layout.
- **app/pages/index.vue** (in the pages folder `nuxt.config`'s `srcDir` or `dir.pages` names): a home page with the app's name and a link to sign in, or to the account once signed in, when the root component renders `<NuxtPage />` and no page answers `/`. The module's pages turn on the router, so without one `/` answers 404. A page at `/` in a route group, a client-only `index.client.vue`, a catch-all or a local layer in `layers/` counts, a pages folder Nuxt does not read counts for nothing, and an app that extends a layer gets none.
- **package.json**: `convex` added to `dependencies` when neither `dependencies` nor `devDependencies` lists it, as a caret range on the installed copy, else this package's peer range. `npx convex dev` refuses to run until the app declares it, so install once more to link it. A plain `nuxt dev` script, or the `convex dev --start "nuxt dev"` script `nuxt-convex-module` can write, now runs [`nuxt-backend dev`](#dev) with its arguments kept. A `dev` script you wrote yourself stays as it is.
- **The agent files**: a `nuxt-backend` section in `AGENTS.md`, between markers so a second run never duplicates it; one `nuxt-backend` server in `.mcp.json`, which runs [`nuxt-backend mcp`](#mcp), beside the servers the file already holds; and a copy of the package's agent skills in `.agents/skills/`, linked from `.claude/skills/` in a project that uses Claude Code.
- **pnpm-workspace.yaml**, in a project on pnpm 12.11 or later once the skills are copied: `skills: false` for nuxt-backend under `permissions`, so pnpm links no second copy of them. It goes in the nearest `pnpm-workspace.yaml`, the workspace root's in a monorepo, or a new one in the project, and every other key and comment stays. A `skills` entry nuxt-backend already has stays as you set it. `pnpmWorkspace` in `--json` says what happened: `created`, `added`, `unchanged`, or `manual` when the file, or `permissions` in it, is written in a form `init` does not edit line by line: a flow mapping, as JSON writes it, or more than one document.

The `AGENTS.md` section names the version the app has installed, and points the agent at the package's skills, the core first: `node_modules/nuxt-backend/skills/nuxt-backend/`. A skill copy another version wrote, or one of a skill the installed version no longer ships, stays until `init --agents` or `init --force` replaces or removes it. A skill the project's `skills-lock.json` lists belongs to the [skills CLI](https://skills.sh), and `init` leaves it there. `skills` in `--json` lists, by name, the skills it `installed`, `refreshed` and `removed`, and the `stale` ones it left.

`init` never rewrites an `AGENTS.md` whose markers don't pair up (a start marker without its end, or two sections): it says so and exits with `1`. It also says when a `CLAUDE.md` does not import `AGENTS.md`. [Agent files](https://nuxt-backend.dev/docs/develop/agents/agent-files) shows how it merges into files you already have.

It ends with the next steps:

```text
Next steps:
  npm run dev                # the first run sets up your Convex dev deployment (log in
                             # when asked) and provisions its env, then runs Convex and Nuxt
  Sign in at /login: in development, the sign-in code prints in the same terminal.
```

Each command goes through the project's package manager: the one `package.json`'s `packageManager` field names, else the one whose lockfile the project has, else npm. A pnpm project reads `pnpm install` and `pnpm run dev`. An install line comes first when this run added `convex` or the MCP SDK. When your `dev` script is one of your own, `npx nuxt-backend dev` (`pnpm exec nuxt-backend dev` under pnpm) replaces `npm run dev`.

The dev server no longer scaffolds on startup, and the `backend.scaffold` option is gone: `init` and [`dev`](#dev) own the scaffold.

## `dev`

Run Convex and Nuxt from one command, on your dev deployment and the providers' sandboxes. `init` points your `dev` script at it, so `npm run dev` runs it, and arguments after `dev` go to `nuxt dev`. On a dev deployment's first run it provisions the env with `env push`: `AUTH_SECRET`, `SITE_URL`, `BACKEND_ENVIRONMENT=development`, and `EMAIL_DEV_INBOX=1`, the opt-in that lets a page read the [dev inbox](https://nuxt-backend.dev/docs/develop/dev-inbox).

```bash
npx nuxt-backend dev
npx nuxt-backend dev --anonymous   # an account-free local deployment
npm run dev -- --port 3001         # through the dev script: arguments reach nuxt dev
```

**Side effects:** writes project files; writes the dev deployment. **--json:** none: it runs until stopped, with Convex and Nuxt printing to the terminal. **Exit codes:** `0` Convex and Nuxt stopped cleanly; `1` no deployment could be set up, or Convex failed (its own exit code is passed on); `130` stopped by Ctrl-C, SIGINT or SIGTERM.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --anonymous
      </code>
    </td>
    
    <td>
      Start on an account-free local deployment, with no Convex login and no question, on macOS, Linux and Windows alike: it gives the Convex CLI <code>
        CONVEX_AGENT_MODE=anonymous
      </code>
      
       itself, so no shell syntax is needed. A deployment <code>
        .env.local
      </code>
      
       already names is kept, and <code>
        dev
      </code>
      
       says so. <code>
        npx convex login
      </code>
      
       later moves the deployment into your account.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        -- <args>
      </code>
    </td>
    
    <td>
      Everything after <code>
        dev
      </code>
      
       that is not its own flag goes to <code>
        nuxt dev
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

It writes project files only for the scaffold, when the functions directory is missing. On the dev deployment it writes only the env and the code `convex dev` pushes.

In order, it:

1. scaffolds `backend/` when the app has no functions directory yet, before Convex can create a `convex/` one;
2. runs `convex dev --once` when no deployment is configured. The login and project prompts happen here, and `CONVEX_DEPLOYMENT` lands in `.env.local`. On a new deployment this push fails on the env it has not been given yet, which is expected;
3. runs the [`env push`](#env-push) engine once per dev deployment: it generates `AUTH_SECRET`, defaults `SITE_URL`, and sets `BACKEND_ENVIRONMENT` to `development`, which keeps every provider in its test mode, trusts the local origins and logs sign-in codes;
4. hands over to `convex dev --start "nuxt dev …"`: the push succeeds, codegen runs before Nuxt starts, Convex's function logs (sign-in codes among them) print beside Nuxt's, and Ctrl-C stops both.

It starts nothing beside Convex and Nuxt. Billing reads `missing` until you push a sandbox token, then bills in Polar's sandbox ([Billing on Polar's sandbox](https://nuxt-backend.dev/docs/develop/sandboxes#billing-on-polars-sandbox)).

To stop it from another process, as a coding agent or a task runner does, send SIGINT or SIGTERM to its process (`kill -INT <pid>` or `kill <pid>`). It passes either on to Convex as SIGINT, which stops Nuxt and a local backend before exiting. On Windows, `taskkill /PID <pid> /T /F` ends the whole tree.

`convex dev --start "nuxt dev"` on its own is not enough. The scaffold requires `AUTH_SECRET` and `SITE_URL` on the deployment, Convex starts the command only after a successful push, and the values come from this package's env provisioning, so on a new deployment it waits forever. `doctor` warns about that script (`dev-script`), and `doctor --fix` replaces it.

Two terminals still work if you prefer them: `npx convex dev` in one, `nuxt dev` in the other, in either order.

## `doctor`

Check the project and the deployment's configuration. It exits with `1` when any finding fails.

```bash
npx nuxt-backend doctor
npx nuxt-backend doctor --prod     # production posture, and live probes of its site
npx nuxt-backend doctor --fix      # restore missing scaffold files, push env, apply the provider settings
npx nuxt-backend doctor --fix --yes   # the same, unattended: provider changes without asking
npx nuxt-backend doctor --json     # machine-readable { $schema, findings, summary }
npx nuxt-backend doctor --only billing,email   # some capabilities' checks
```

**Side effects:** reads only; --fix: writes project files, writes the dev deployment, writes provider accounts; --fix --prod: writes project files, writes production, writes provider accounts. **--json:** `{ $schema, findings, summary }`, described by [https://nuxt-backend.dev/schemas/doctor.json](https://nuxt-backend.dev/schemas/doctor.json); with `--fix`, the repair's progress goes to stderr. **Exit codes:** `0` no finding failed (warnings allowed); `1` a finding failed, the flags were refused, or with `--fix`, `email sync` was refused or failed.

[Its JSON Schema](https://nuxt-backend.dev/schemas/doctor.json) describes the `--json` output, and each finding has an entry on [Diagnostics](https://nuxt-backend.dev/docs/reference/cli/diagnostics).

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Production posture: checks the project's <strong>
        production
      </strong>
      
       deployment (<code>
        convex … --prod
      </code>
      
      ), and turns the designed degradations production cannot run with into failures. It also reads what production's env names alone cannot say, and probes the live site its <code>
        SITE_URL
      </code>
      
       names (<a href="#under---prod">
        Under <code>
          --prod
        </code>
      </a>
      
      ). Refuses a dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
      , which would point the checks at that deployment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --fix
      </code>
    </td>
    
    <td>
      Repair what <code>
        doctor
      </code>
      
       can: restore missing scaffold files (existing files untouched), point a <code>
        convex dev --start "nuxt dev"
      </code>
      
       dev script at <code>
        nuxt-backend dev
      </code>
      
      , run the <code>
        env push
      </code>
      
       engine (never with <code>
        --force
      </code>
      
      ), at a terminal make the first administrator when the deployment has none (<a href="https://nuxt-backend.dev/docs/build/auth/admin#make-the-first-administrator">
        Make the first administrator
      </a>
      
      ; without a terminal it says it skipped this), and plan <a href="#email-sync">
        <code>
          email sync
        </code>
      </a>
      
       as a dry run, the support inbox's included, then run it (on dev and production alike, as it writes the email provider's account). Then the providers: it names each setting the billing findings recommend (trial abuse prevention, the trial reminder, Polar's customer emails back on), subscribes the billing endpoint to every event the package handles, and turns either provider's webhook endpoint back on once its route answers the probe. Turning the email webhook back on changes its switch alone: its events and the topics stay with the email sync, so one you declined is not made then. A deployment whose backend was pushed by an older version runs the whole email sync with the switch, and the question names what that sync would make. Each change, the email sync among them, is made only once you confirm it at a terminal, or with <code>
        --yes
      </code>
      
      ; without either it is listed and left (<a href="https://nuxt-backend.dev/docs/services#let-doctor-fix-them">
        Let doctor fix them
      </a>
      
      ). An <code>
        email sync
      </code>
      
       that is refused or fails fails the command. It turns nothing off and never touches seat settings.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --yes
      </code>
    </td>
    
    <td>
      With <code>
        --fix
      </code>
      
      : run <code>
        email sync
      </code>
      
       and apply the provider changes without asking, for a script or CI. Without it and without a terminal, <code>
        --fix
      </code>
      
       lists them and leaves them: a CI run without <code>
        --yes
      </code>
      
       runs no <code>
        email sync
      </code>
      
       and changes nothing at either provider.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Machine-readable output, described by <a href="https://nuxt-backend.dev/schemas/doctor.json" rel="nofollow">
        its JSON Schema
      </a>
      
      . With <code>
        --fix
      </code>
      
      , the repair's progress goes to stderr, so stdout stays one JSON document.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --only <capabilities>
      </code>
    </td>
    
    <td>
      Run only the checks of these <a href="https://nuxt-backend.dev/docs/reference/capabilities">
        capabilities
      </a>
      
      , comma-separated: <code>
        auth
      </code>
      
      , <code>
        data
      </code>
      
      , <code>
        jobs
      </code>
      
      , <code>
        billing
      </code>
      
      , <code>
        email
      </code>
      
      , <code>
        notifications
      </code>
      
      , <code>
        ai
      </code>
      
      , <code>
        protection
      </code>
      
      , <code>
        monitoring
      </code>
      
      , <code>
        flags
      </code>
      
      , <code>
        analytics
      </code>
      
       and <code>
        hosting
      </code>
      
      . The other checks never run, so their deployment reads, route probes, site probes and provider calls are skipped too.
    </td>
  </tr>
</tbody>
</table>

### Findings

Each finding has an `id`, the `capability` it belongs to, a status (`pass`, `warn` or `fail`), a message, a fix hint, and a `docsUrl`: `https://nuxt-backend.dev/d/<id>`, which opens its entry on [Diagnostics](https://nuxt-backend.dev/docs/reference/cli/diagnostics). That page lists every finding with what it checks, when it fails, and its fix. In `0.x` a minor release may rename a finding or move it to another capability, and any release may change its wording ([Stability](https://nuxt-backend.dev/docs/ship/releases/stability)).

The route probes, `function-contract` and the path check need the deployment (and `nuxt.config`) to be reachable, and produce no finding otherwise. The `billing-*` catalog checks need a `billing.catalog.ts`, and run the provider half only with a token visible locally. The same preflight (`backend-site-url` … `billing-webhook-secret`) runs on every dev-server start and in the [DevTools tab](https://nuxt-backend.dev/docs/develop/devtools).

### Under `--prod`

Production's env names say what is set, not to what. Under `--prod`, `doctor` also reads, side by side, only what a check needs:

- **Two values, neither of them secret** (`convex env get --prod`). `BACKEND_ENVIRONMENT` is compared and never printed: it fails when it is unset, `development` or `preview`, and warns when it is `sandbox`, a demo or staging app on purpose ([`deployment-backend-environment`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#deployment-backend-environment)). The origin of `SITE_URL` ([`site-url-origin`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#site-url-origin)) is the app's public origin, which every emailed link names, so the findings print it. A name production does not set is never read.
- **What production reports of its own email** (`convex run --prod --component backend posture:email`, an internal function only an admin key can run). The deployment asks the email provider with its own `EMAIL_API_KEY`, and only derived facts come back, never the key or an address: the sender domain's status ([`email-sender-domain`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#email-sender-domain)), the last 7 days' bounce and complaint rates against the provider's limits ([`email-reputation`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#email-reputation)), and the quota used ([`email-quota`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#email-quota)). A deployment on a release without it warns once.
- **The catalog against its production ids** in `billing.generated.ts` ([`billing-catalog-production`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#billing-catalog-production)).
- **The live site**, at the origin `SITE_URL` names, with anonymous requests a visitor or an uptime check could make: HTTPS and HSTS ([`site-https`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#site-https)), the content security policy and the deployment the page talks to ([`site-csp`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#site-csp), [`site-backend-url`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#site-backend-url)), a gated page sending an anonymous visitor to sign in ([`site-gated-page`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#site-gated-page)), the health endpoint's public shape ([`monitoring-health`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#monitoring-health)), and `/llms.txt` where the app serves it ([`agent-docs`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#agent-docs)).

Nothing is probed when `SITE_URL` is unset, unreadable, local or plain HTTP (`site-url-origin` says so). A site that does not answer at all is one warning, on the first probe the run checks. A run scoped with `--only` to capabilities without auth, such as `--only hosting`, gets the same one warning when `SITE_URL` keeps the site from being probed, so it never looks clean.

The posture the other capabilities already report is not repeated here: bot protection, monitoring, the route to the models and the webhook secrets keep their own findings ([Prepare for launch](https://nuxt-backend.dev/docs/ship/checklist)).

## `status`

Show each [capability](https://nuxt-backend.dev/docs/reference/capabilities) and its state: `live`, `test`, `missing` or `failing`. A capability on its service's test mode, or on a deployment that is not production, reads `test`. `status` runs `doctor`'s checks once and reads the result per capability, so it probes nothing `doctor` does not. The one value it adds is `BACKEND_ENVIRONMENT`, read off the deployment, so a capability outside production never reads as live. Under `--prod` it reads it with the rest of [production's posture](#under---prod), once, and shows the same findings, the live site's among them.

```bash
npx nuxt-backend status          # the dev deployment's capabilities
npx nuxt-backend status --prod   # production's, under doctor's production posture
npx nuxt-backend status --json   # { deployment, status, capabilities, summary }
```

**Side effects:** reads only. **--json:** `{ deployment, status, capabilities: [{ name, title, state, reason, providers, missingEnv, findings, top, docsUrl, devtools }], summary }`: `state` is `live`, `test`, `missing` or `failing`, `status` is `ok`, `degraded` or `failing`. **Exit codes:** `0` no capability is failing (missing and test capabilities allowed); `1` a capability is failing, or --prod was refused.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      The production deployment's capabilities. An env name counts as set only on the deployment (none does when its names cannot be read), the mode follows the <code>
        BACKEND_ENVIRONMENT
      </code>
      
       read off it, and <code>
        doctor
      </code>
      
      's production posture turns a warning production cannot run with into a failure, so the capability fails. Refuses a dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
      , as <code>
        doctor --prod
      </code>
      
       does.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the capabilities as one JSON document. <code>
        status
      </code>
      
       is <code>
        ok
      </code>
      
       while every capability is live or test, <code>
        degraded
      </code>
      
       once one is missing, and <code>
        failing
      </code>
      
       once one fails.
    </td>
  </tr>
</tbody>
</table>

Each line is one capability: its light, its state, what it is built on and why it is in that state. Under it come the env names the capability lacks and its most pressing finding, and the last line names the `doctor --only` run that shows their fixes.

On a cloud dev deployment `env push` set up, which generates the web push key pair, with no billing token yet, it prints:

```text
nuxt-backend status · dev:happy-otter-123 (cloud dev deployment)

◐ auth          test       Better Auth: sign-in codes print in the dev console, or reach the email provider's test addresses
◐ data          test       Convex: runs on the cloud dev deployment
◐ jobs          test       Convex: runs on the cloud dev deployment
○ billing       missing    Polar: BILLING_ACCESS_TOKEN is not set
    unset: BILLING_ACCESS_TOKEN, BILLING_WEBHOOK_SECRET
    ⚠ Billing access: BILLING_ACCESS_TOKEN is not set (optional): billing reads answer empty; on production billing is not launched (the pricing reads "Plans open soon" and every sale is refused as not_launched), elsewhere a checkout is refused as not_configured.
◐ email         test       Resend: BACKEND_ENVIRONMENT is development: only the provider's test addresses receive mail
◐ notifications test       Web Push: runs on the cloud dev deployment
○ ai            missing    AI SDK, Convex AI Gateway, Vercel AI Gateway, Convex persistent text streaming, Polar: its credits need billing: BILLING_ACCESS_TOKEN is not set
◐ protection    test       Vercel BotID, Cloudflare Turnstile: test mode: the dev server's bot check answers human, as BotID does in development
◐ monitoring    test       Sentry: no DSN is set, so errors go to the dev server's local error log (DevTools › Monitoring)
    unset: MONITORING_DSN
● flags         live       Convex: flags are evaluated in your own functions: their defaults from code, and the overrides stored on the deployment
○ analytics     missing    Polar: its metrics need billing: BILLING_ACCESS_TOKEN is not set
○ hosting       missing    Vercel: no production deployment yet

1 live · 7 test · 4 missing — fixes: npx nuxt-backend doctor --only billing
```

The lights are the console's: `●` live, `◐` test, `○` missing and `✗` failing, in green, amber, grey and red on a terminal that shows colour.

## `env push`

Sync the backend env contract from `.env(.local)` onto the Convex deployment. On dev deployments (`dev:`, `local:` and `anonymous:`) it also fills the required gaps, so onboarding needs no manual `convex env set`.

```bash
npx nuxt-backend env push
npx nuxt-backend env push --dry-run
npx nuxt-backend env push --prod
npx nuxt-backend env push --json
npx nuxt-backend env push --force BILLING_WEBHOOK_SECRET   # replace a value already set
npx nuxt-backend env push --defaults preview --site-url https://preview.example.com
npx nuxt-backend env push --preview my-branch --site-url https://my-branch.example.app
```

**Side effects:** writes the dev deployment; --prod: writes production; --preview: writes a preview deployment; --defaults: writes project env defaults; --dry-run: reads only. **--json:** `{ deployment, dev, results: [{ name, action, detail, outcome, error }], missingRequired }`: `deployment` names what was written (`dev:<slug>`, `production`, `preview:<name>`, `defaults:<type>`); values never appear. **Exit codes:** `0` every value set, or nothing to set; `1` refused, no deployment (or project defaults) reachable, a set failed, or required env is missing.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Acts on the project's <strong>
        production
      </strong>
      
       deployment (<code>
        convex env set --prod
      </code>
      
      ), whichever deployment <code>
        .env.local
      </code>
      
       names. It invents no value but <code>
        BACKEND_ENVIRONMENT
      </code>
      
      , which it derives, and fails (exit 1) on missing required env. It forwards from <code>
        .env.local
      </code>
      
       only what is the app's everywhere: never a <code>
        SITE_URL
      </code>
      
       that is no public https origin (pass production's with <code>
        --site-url
      </code>
      
      ), <code>
        PROTECTION_PROOF_SECRET
      </code>
      
       (production's own), the challenge provider's test secret key, or <code>
        AI_GATEWAY_API_KEY
      </code>
      
       (development's key: set production's own with <code>
        npx convex env set --prod AI_GATEWAY_API_KEY
      </code>
      
      ). Refuses to run when <code>
        CONVEX_DEPLOY_KEY
      </code>
      
       is a dev or preview key: the Convex CLI follows the key and ignores <code>
        --prod
      </code>
      
      , so the push would land there.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --preview [name]
      </code>
    </td>
    
    <td>
      Acts on the preview deployment of that name (<code>
        convex env set --preview-name
      </code>
      
      ). Without a name, the branch the CI build names, read as <code>
        convex deploy
      </code>
      
       reads it (<code>
        VERCEL_GIT_COMMIT_REF
      </code>
      
       on Vercel, <code>
        HEAD
      </code>
      
       on Netlify, …). Generates <code>
        AUTH_SECRET
      </code>
      
       and sets <code>
        BACKEND_ENVIRONMENT
      </code>
      
       to <code>
        preview
      </code>
      
       when nothing else sets them; <code>
        SITE_URL
      </code>
      
       comes from <code>
        --site-url
      </code>
      
       only. Refuses a deploy key that is not a preview key.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --defaults preview|dev
      </code>
    </td>
    
    <td>
      Writes the project's env defaults for new deployments of that type (<code>
        convex env default set --type
      </code>
      
      ) instead of a deployment: a generated <code>
        AUTH_SECRET
      </code>
      
      , <code>
        SITE_URL
      </code>
      
      , and <code>
        BACKEND_ENVIRONMENT
      </code>
      
       as <code>
        preview
      </code>
      
       or <code>
        development
      </code>
      
      ; dev defaults add <code>
        EMAIL_DEV_INBOX=1
      </code>
      
      . A default already set is kept unless <code>
        --force
      </code>
      
       names it. <code>
        prod
      </code>
      
       is refused, and so is a production deploy key.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --site-url <url>
      </code>
    </td>
    
    <td>
      The <code>
        SITE_URL
      </code>
      
       to write, replacing the one already set: giving it is asking for it. A preview's only source of one, and required for <code>
        --defaults preview
      </code>
      
       until the project has that default.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --dry-run
      </code>
    </td>
    
    <td>
      Print the plan without setting anything.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --force [names]
      </code>
    </td>
    
    <td>
      Replace values already set on the deployment with the local ones: the names given, a comma-separated list (case-insensitive). Bare, or <code>
        all
      </code>
      
      , for every variable of the contract but <code>
        BACKEND_ENVIRONMENT
      </code>
      
      , which is replaced only when named. <code>
        --prod
      </code>
      
       refuses a bare one: <code>
        .env.local
      </code>
      
       holds the dev deployment's values, so name what production takes from it. Rotation has to be asked for: the plan reads deployment <strong>
        names
      </strong>
      
      , never values, so it cannot tell a rotated secret from an identical one. <a href="#env-rotate">
        <code>
          env rotate
        </code>
      </a>
      
       rotates the secrets that must not sign anyone out.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Machine-readable output.
    </td>
  </tr>
</tbody>
</table>

The plan, per variable of the contract (`AUTH_SECRET`, `SITE_URL`, `BACKEND_ENVIRONMENT`, `EMAIL_*`, `BILLING_*`, `AI_GATEWAY_API_KEY`, `PROTECTION_*`, `PUSH_*` and `MONITORING_DSN`):

<table>
<thead>
  <tr>
    <th>
      Action
    </th>
    
    <th>
      When
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        skipped
      </code>
    </td>
    
    <td>
      Already set on the deployment: left alone unless the name is in <code>
        --force
      </code>
      
      . A forced name with no local value is skipped too
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        set
      </code>
      
       (forward)
    </td>
    
    <td>
      Present in <code>
        .env(.local)
      </code>
      
      : forwarded
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        set
      </code>
      
       (update, <code>
        --force
      </code>
      
       only)
    </td>
    
    <td>
      Already set and named in <code>
        --force
      </code>
      
      : replaced with the value from <code>
        .env(.local)
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        set
      </code>
      
       (provision, dev only)
    </td>
    
    <td>
      Required and missing: <code>
        AUTH_SECRET
      </code>
      
       is generated (32 random bytes, base64), and <code>
        SITE_URL
      </code>
      
       defaults to <code>
        http://localhost:3000
      </code>
      
      , or the port <code>
        nuxt-backend dev --port
      </code>
      
       names. <code>
        EMAIL_DEV_INBOX
      </code>
      
       missing is set to <code>
        1
      </code>
      
      , which publishes the <a href="https://nuxt-backend.dev/docs/develop/dev-inbox">
        dev inbox
      </a>
      
       to pages
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        set
      </code>
      
       (derive)
    </td>
    
    <td>
      <code>
        BACKEND_ENVIRONMENT
      </code>
      
       missing: set from the deployment's kind, <code>
        development
      </code>
      
       for a dev deployment, <code>
        preview
      </code>
      
       for a preview and <code>
        production
      </code>
      
       for production. A value already set stays, so a <code>
        sandbox
      </code>
      
       you set by hand is never replaced
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        MISSING
      </code>
    </td>
    
    <td>
      Required and missing on a non-dev push: blocks with exit 1
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        unset
      </code>
    </td>
    
    <td>
      Optional and absent: informational, with the designed degradation. <code>
        EMAIL_DEV_INBOX
      </code>
      
       on a preview or production push too: it goes to dev deployments only, never from <code>
        .env.local
      </code>
      
       elsewhere
    </td>
  </tr>
</tbody>
</table>

`BACKEND_ENVIRONMENT` replaces five variables of earlier previews that `env push` pushed or provisioned: `EMAIL_TEST_MODE`, `BILLING_ENVIRONMENT`, `MONITORING_ENVIRONMENT`, `AUTH_TRUST_LOCAL_ORIGINS` and `NUXT_BACKEND_LOG_OTP`. It sets `BACKEND_ENVIRONMENT` only where the deployment holds none, and never from `.env.local`: its value there is the dev deployment's. [Environments and deployments](https://nuxt-backend.dev/docs/start/concepts/environments) says what each value decides.

Each value reaches `npx convex env set NAME` on its stdin: never as an argument, where every process on the machine could read it (`ps`), and never through a shell. A set that fails is reported as the command, its exit code and the last lines of its stderr, never with the value. The deployment is whatever the Convex CLI targets: `CONVEX_DEPLOYMENT` from `.env.local` in dev, or a `CONVEX_DEPLOY_KEY` in the environment for production. The Convex CLI follows a deploy key whatever the flags say, so a push without `--prod` or `--preview` is refused (exit 1) while the key in the shell, `.env.local` or `.env` is anything but a dev key: the dev values above would land on production, a preview or the deployment a project key picks. `doctor --fix` refuses the same, and `nuxt-backend dev` skips the push and says why. Without a reachable deployment the command exits 1 (`run npx convex dev once, then push again`).

### Preview deployments

`npx convex deploy` with a preview deploy key creates the branch's preview deployment, runs your `--cmd`, then pushes the backend to it. That push fails unless `AUTH_SECRET` and `SITE_URL` are already there, and a new preview starts with nothing but the project's preview env defaults. Two ways put them there, and they work together:

- **In the build, exactly.** `--cmd` runs once the preview exists and before the push, so `env push --preview` can fill its env there, with the branch's own origin as `SITE_URL`. On Vercel, where `VERCEL_BRANCH_URL` is the branch's stable URL and the same build command also runs for production:```bash
npx convex deploy --cmd-url-env-var-name NUXT_PUBLIC_BACKEND_URL \
  --cmd 'if [ "$VERCEL_ENV" = preview ]; then npx nuxt-backend env push --preview --site-url "https://$VERCEL_BRANCH_URL"; fi && npm run build'
```
- **Project env defaults, once.** Convex copies them into every preview it creates, so a preview built without that step can still push:```bash
npx nuxt-backend env push --defaults preview --site-url https://preview.example.com
```

`SITE_URL` is the one value neither will make up. Auth trusts only that origin, and a preview's origin is its own (one per branch on most hosts), so it has to come from the build, which knows it, or from you. A default cannot be exact for every preview: name a stable preview domain if your host gives you one, and let the build step replace it per branch. `doctor` reports the defaults as [`env-defaults`](#findings).

`--defaults dev` writes the same three values for new dev deployments, with `SITE_URL` at `http://localhost:3000` unless `--site-url` names another. That helps when teammates start with a bare `npx convex dev`, which `nuxt-backend dev` makes unnecessary. Every deployment created from the defaults shares their one `AUTH_SECRET`.

`nuxt-backend dev` runs this same engine once per dev deployment, so nobody runs `env push` to get started. The `backend.autoEnv` option, which ran it on dev-server startup, is gone.

## `env rotate`

Rotate a secret the package reads without signing anyone out or refusing a webhook delivery. The new value goes in beside the old, both are accepted for a window, and then the old one is retired. No value is printed: each reaches `convex env set` on its stdin. [Rotate secrets](https://nuxt-backend.dev/docs/ship/security/secrets) walks through each secret.

```bash
npx nuxt-backend env rotate AUTH_SECRET
npx nuxt-backend env rotate EMAIL_WEBHOOK_SECRET --prod
npx nuxt-backend env rotate BILLING_WEBHOOK_SECRET --prod --dry-run
```

**Side effects:** writes the dev deployment; writes provider accounts; --prod: writes production; --dry-run: reads only. **--json:** `{ name, deployment, dryRun, steps: [{ step, outcome, note? }], state, retiresAt? }`: the steps it took and the secret's new state; values never appear. **Exit codes:** `0` rotated, or a dry run; `1` refused, or a step failed.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        <name>
      </code>
    </td>
    
    <td>
      The secret to rotate: <code>
        AUTH_SECRET
      </code>
      
      , <code>
        EMAIL_WEBHOOK_SECRET
      </code>
      
       or <code>
        BILLING_WEBHOOK_SECRET
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Rotate production's secret. Refuses a dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
      , as <code>
        env push --prod
      </code>
      
       does.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --dry-run
      </code>
    </td>
    
    <td>
      Print each step it would take, and change nothing.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --retire
      </code>
    </td>
    
    <td>
      <code>
        AUTH_SECRET
      </code>
      
       only: retire the old value now, not after the 30-day window. After a leak: sessions, links and codes it signed stop working.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

How each secret rotates:

- **AUTH_SECRET** is versioned. The new value signs everything from then on, and the old one still verifies sessions, codes in flight and unsubscribe links for 30 days. The session signing keys rotate with it, with no downtime. Run the command again once the window passed to retire the old value: before then it refuses and says when.
- **EMAIL_WEBHOOK_SECRET** rotates at the email provider, which signs with both secrets for 24 hours while the deployment accepts both.
- **BILLING_WEBHOOK_SECRET** is reset through the billing provider's API, with the `BILLING_ACCESS_TOKEN` visible here (the process env alone under `--prod`). The command writes the `new,old` accept list at once, then the new value alone.

`PROTECTION_PROOF_SECRET` and the push keys keep steps of their own, which the command names when asked to rotate them ([What rotates, and how](https://nuxt-backend.dev/docs/ship/security/secrets#what-rotates-and-how)). A provider token (`BILLING_ACCESS_TOKEN`, `EMAIL_API_KEY`, `AI_GATEWAY_API_KEY`) needs no command: set the new one by name, with `env push --force BILLING_ACCESS_TOKEN` (and `--prod` for production), then revoke the old one.

## `billing sync`

Push `backend/billing.catalog.ts` to the billing provider and write `backend/billing.generated.ts`. It finds or creates each object, and never deletes one. It provisions the `/billing/events` webhook endpoint of the deployment it writes, stores the endpoint's secret there as `BILLING_WEBHOOK_SECRET` (never printed), and runs `billing:syncProducts` on that deployment so pricing renders at once. A sandbox sync writes the deployment `.env.local` names; `--env production` writes the production deployment.

**Side effects:** writes provider accounts; writes project files; writes the dev deployment; writes production. **--json:** `{ environment, dryRun, deployment, log: [{ action, kind, key, id?, note? }], generated, webhook: { url, action: "created" | "exists" | "would-create" | "skipped", secret: "stored" | "kept" | "not-stored" | "none", note? }, products: { status: "synced" | "failed" | "skipped", note? } }`. **Exit codes:** `0` synced, or a dry run. A webhook or product step that could not run is reported, not fatal; `1` refused or failed: unknown environment, no access token or catalog, a catalog plan still in the 0.1 shape (`interval` and `price`) or priced at no interval, an id map (`billing.generated.ts`) that does not load, a deploy key for the other kind of deployment, a production webhook URL that cannot be derived, a webhook URL on a deployment other than the one written, a provider error, or a webhook secret that belongs on the deployment and could not be stored.

The project file it writes is `backend/billing.generated.ts`, and the deployment it writes is the dev or production one: the one `.env.local` names for the sandbox, production with `--env production`.

```bash
npx nuxt-backend billing sync
npx nuxt-backend billing sync --env production
npx nuxt-backend billing sync --dry-run
npx nuxt-backend billing sync --webhook off
npx nuxt-backend billing sync --adopt pro=prod_123,credits=meter_456
```

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --env sandbox|production
      </code>
    </td>
    
    <td>
      The target environment: <code>
        sandbox
      </code>
      
      , Polar's sandbox, or <code>
        production
      </code>
      
      . Default: the environment the deployment bills in, read from its <code>
        BACKEND_ENVIRONMENT
      </code>
      
       (<code>
        production
      </code>
      
       bills live, every other value in the sandbox), else <code>
        sandbox
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --dry-run
      </code>
    </td>
    
    <td>
      Print the plan without creating anything.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --webhook <url>
      </code>
    </td>
    
    <td>
      Provision the webhook endpoint at this URL (default: <code>
        <site>/billing/events
      </code>
      
       of the deployment written; <code>
        off
      </code>
      
       to leave the webhook alone).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --force
      </code>
    </td>
    
    <td>
      Store the endpoint's secret even over a <code>
        BILLING_WEBHOOK_SECRET
      </code>
      
       the deployment already holds, and create a missing endpoint in that case.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --adopt key=<id>[,…]
      </code>
    </td>
    
    <td>
      Record existing provider objects under catalog keys, as they are: their benefits stay untouched.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document (<code>
        { environment, dryRun, deployment, log, generated, webhook, products }
      </code>
      
      , the secret never in it); progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

Before it writes anything, it reads the deployment the Convex CLI will write (`npx convex function-spec` and `npx convex env list`, with `--prod` under production) and works from there:

- **Which deployment.** A deploy key decides it, whatever the flags say, so a key for the other kind of deployment is refused: a dev or preview `CONVEX_DEPLOY_KEY` under `--env production`, and a production key (a legacy key without a type is one) or a project key under the sandbox. The output and `--json`'s `deployment` name the deployment written.
- **The webhook URL.** `--webhook <url>` as given; otherwise `<site>/billing/events`, where the site is the deployment's own `.convex.site` origin. An endpoint on one deployment whose secret would land on another is refused. When the URL cannot be had (the deployment is unreadable, or it runs on this machine, where the provider cannot deliver), a sandbox sync leaves the webhook alone and says why, and a production sync stops and asks for `--webhook`.
- **The secret.** A new endpoint's secret is stored on the deployment. An endpoint that already exists has its secret stored when the deployment has none: the provider reports it on every read, so a secret one run could not store is stored by the next. A `BILLING_WEBHOOK_SECRET` the deployment already holds is kept unless `--force`. Without it, an endpoint missing at the URL is not created, since its secret would replace that one. To set the secret by hand, run `npx convex env set BILLING_WEBHOOK_SECRET` (with `--prod` for production), which asks for it: never put it on the command line.
- **The products.** `billing:syncProducts` runs only when the deployment can load the catalog synced: it holds `BILLING_ACCESS_TOKEN`, and its `BACKEND_ENVIRONMENT` bills in the environment synced. Otherwise it is skipped with the command to run once that is set, and a run that fails reports the deployment's error.

It needs `BILLING_ACCESS_TOKEN` (in the env or `.env.local`) and a `billing.catalog.ts`. [Define and sync your catalog](https://nuxt-backend.dev/docs/build/billing/catalog) covers the full semantics: tagging, drift, adopted products and the generated map.

## `billing reset`

Start the dev deployment's billing over in the organization `BILLING_ACCESS_TOKEN` names, after the token moved to another organization (a new Polar sandbox, say). The billing provider's component maps each billing entity onto a customer once and never forgets it, so after such a move every entity's checkout, portal and free plan are refused as `unavailable` (reason `customer_unknown`), and [`billing-customer-mapping`](https://nuxt-backend.dev/docs/reference/cli/diagnostics#billing-customer-mapping) warns.

**Side effects:** writes provider accounts; writes project files; writes the dev deployment. **--json:** `{ sync: <billing sync --json>, cleared: [{ component, table, status: "cleared" | "failed" | "skipped", note? }], freePlan: { status: "queued" | "skipped" | "failed", note? } }`. **Exit codes:** `0` reset: the catalog synced, the billing data cleared, and the free plan queued (or the catalog has none); `1` refused or failed: a deploy key for any deployment but a dev one, a deployment that bills in production, a refused billing sync (nothing is cleared then), a table that could not be cleared, or a free plan that could not be queued.

```bash
npx nuxt-backend billing reset
```

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document (<code>
        { sync, cleared, freePlan }
      </code>
      
      ); progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

In order, it:

1. refuses a `CONVEX_DEPLOY_KEY` for any deployment but a dev one, and a deployment whose `BACKEND_ENVIRONMENT` is `production`. It has no `--prod`: on production, point `BILLING_ACCESS_TOKEN` back at the organization the billing data came from;
2. runs [`billing sync`](#billing-sync) for the sandbox, which creates the catalog in the token's organization, writes `backend/billing.generated.ts` and loads the deployment's products. A sync that is refused (no token, no catalog) clears nothing;
3. clears the billing provider component's `customers` and `subscriptions` tables (an empty `npx convex import --replace` of each, since the component has no mutation that deletes its rows) and the `backend` component's `billingEntitlements` cache (`billing:clear`);
4. puts every billing entity back on the free plan, when the catalog has one: `npx convex run billing:startFreePlan '{}'`, with `--push` first when the sync rewrote the id map, so the deployment subscribes the new organization's free product.

Paid subscriptions of the old organization stay there: the reset forgets them, it cancels nothing.

## `billing resync`

Read the billing entities' entitlements again from the billing provider into the deployment's cache, as `syncEntitlements` does for one signed-in entity: every workspace, or every account with `billTo: 'user'`, or the entities `--entity` names. Run it when the cache may have missed what the provider holds: the webhook endpoint was off or its secret changed while purchases went through, or the deployment was restored from a backup. The webhooks keep the cache current otherwise, so a healthy app never needs it.

**Side effects:** writes the dev deployment; --prod: writes production. **--json:** `{ deployment: "dev" | "production", status: "queued" | "synced" | "custom_entities" | "refused" | "missing" | "failed", queued, more, entities: [{ id, outcome: "synced" | "gone" | "failed" }], note? }`: `queued` counts the billing entities of the first page, and `more` says further pages follow; the deployment logs each entity it gives up on (`billing.resync_failed`) and the tally at the end (`billing.resync_done`); `entities` lists each one `--entity` named that was read. **Exit codes:** `0` queued: every billing entity's entitlements are read again on the deployment, in turn, paced under the provider's rate limit; or synced: each entity `--entity` named was read again; `1` refused or not run: a deploy key for another deployment than the flags name, an `--entity` list that is empty or names more than 100, an app that bills entities of its own (`billTo: "user"` with its own `resolveEntity`) resynced without `--entity`, a deployment whose billing.ts does not export resyncEntitlements (scaffolded before it), one that refused the resync, or an entity `--entity` named that the provider kept refusing.

```bash
npx nuxt-backend billing resync          # the dev deployment
npx nuxt-backend billing resync --prod   # production
npx nuxt-backend billing resync --entity team_1,team_2   # these entities only
```

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Resync the production deployment instead of the dev one. A dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
       is refused; without <code>
        --prod
      </code>
      
      , so is a key for anything but a dev deployment, since the Convex CLI follows the key whatever the flags say.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --entity <id>[,<id>…]
      </code>
    </td>
    
    <td>
      Read only these billing entities again, by the id billing knows them by, at most 100, one at a time, and wait for each. <code>
        entities
      </code>
      
       lists them, each <code>
        synced
      </code>
      
      , <code>
        gone
      </code>
      
       while an erasure deletes it, or <code>
        failed
      </code>
      
       when the provider kept refusing it; one failed fails the command, after the rest were read.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document (<code>
        { deployment, status, queued, more, entities, note? }
      </code>
      
      ), a refusal included; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

Without `--entity` it runs the scaffold's `billing:resyncEntitlements '{}'` on the deployment and returns. The deployment pages its billing entities (workspaces, or accounts with `billTo: 'user'`) a hundred at a time and reads them in turn, at most one a second, under the provider's rate limit (Polar's sandbox allows 100 requests a minute, shared with the app's own). A read the rate limit refuses waits as long as the provider's `Retry-After` asks, eight tries in all; any other refusal gets three. A wait that would outlast the run is never started: the entity and the rest of the page go to the next run, scheduled after the wait, with the tries spent. With `--entity`, each entity's tries fit in five minutes, and a wait past them gives up on it. `queued` counts the first page; with `more`, the rest follow after the command ends. An entity an erasure is deleting is left alone.

The outcome is in the deployment's logs (`npx convex logs --history 100`, `--prod` for production): `billing.resync_failed` names each entity it gave up on, and `billing.resync_done` closes the sweep with how many were read again, left to an erasure and given up on. Read the ones it gave up on again with `--entity`. A sweep runs until that last line: running the command again before it starts a second sweep beside the first, which reads every entity again and doubles the requests, so wait for it.

An app whose own `resolveEntity` bills entities of its own with `billTo: 'user'` (a team in its own tables) has entities the deployment cannot list, and its accounts are not them. The sweep queues nothing there and says so (`status: "custom_entities"`), and the command fails: name the entities with `--entity`. With `billTo: 'workspace'` a resolver of your own still returns workspaces, so the sweep covers them.

An app scaffolded before `resyncEntitlements` existed lacks it: the command says so (`status: "missing"`) and fails. Add `resyncEntitlements` to the names `backend/billing.ts` re-exports from `billing.api`, push the backend, and run it again. `doctor` does not ask for it: no composable calls it.

## `access admit`

Let addresses sign up while the app is closed: an invitation by address for each, as the admin console's Access tab gives one, for a drill, an end-to-end test or a first tester, with nobody signed in to the console. No email is sent. It goes through the `backend` component's `access:admit`, so the app's own `backend/access.ts` needs no change.

**Side effects:** writes the dev deployment; --prod: writes production. **--json:** `{ deployment: "dev" | "production", status: "admitted" | "refused" | "missing" | "failed", admitted, skipped: [{ email, reason: "malformed" | "reserved" | "account" }], expiresAt, note? }`: `expiresAt` is epoch ms, or `null` when refused. **Exit codes:** `0` the admission ran: each address named holds an invitation, or was skipped with its reason; `1` refused or not admitted: no address or too many, a label or a lifetime out of range, a deploy key for another deployment than the flags name, a deployment without launch access, or one that refused.

```bash
npx nuxt-backend access admit ada@acme.dev
npx nuxt-backend access admit ada@acme.dev grace@acme.dev --label drill --days 2
npx nuxt-backend access admit ada@acme.dev --prod
```

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        <email>…
      </code>
    </td>
    
    <td>
      The addresses to admit: several, or separated by commas, at most 500. Each is trimmed and lower-cased; a malformed one, or one on a domain reserved for documentation and tests (<code>
        example.com
      </code>
      
      , <code>
        .test
      </code>
      
      ), is skipped, as the Access tab skips it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --label <text>
      </code>
    </td>
    
    <td>
      What the Access tab lists the invitations under, 1 to 64 characters. Default: <code>
        command line
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --days <n>
      </code>
    </td>
    
    <td>
      How many days the invitations admit, from 1 to 365. Default: 30, the Access tab's.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Admit on the production deployment. A dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
       is refused; without <code>
        --prod
      </code>
      
      , so is a key for anything but a dev deployment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document (<code>
        { deployment, status, admitted, skipped, expiresAt, note? }
      </code>
      
      ), a refusal included (<code>
        status: "refused"
      </code>
      
      , <code>
        expiresAt: null
      </code>
      
      ); progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

An address that has an account already is skipped (`reason: "account"`): it signs in whatever the phase. One admitted before and not used yet keeps the later of its two expiry dates. The invitation is not on the activity trail, since no account made it; the Access tab lists it under its label, where an administrator revokes it. [Invite people by address](https://nuxt-backend.dev/docs/build/growth/launch/invites#invite-people-by-address) covers the Access tab's side, and [Launch in phases](https://nuxt-backend.dev/docs/build/growth/launch) every other ticket.

## `email sync`

Push what `backend/email.ts` declares to the email provider, as [`billing sync`](#billing-sync) does for the catalog. The deployment does the provider's side with its own `EMAIL_API_KEY` (`email:syncEmail`, which `backend/email.ts` re-exports from `setupEmail(…).api`), so the key never leaves it. It creates the topics under `topics`, the segment that holds your app's accounts, and the contact properties under `contactProperties`. It points the deployment's `/email/events` webhook at every event the package reads; a webhook it creates has its signing secret stored on the deployment as `EMAIL_WEBHOOK_SECRET`, never printed. It reads each sender's domain for its region and DMARC policy. The ids it creates stay on the deployment, so no provider id sits in your code.

**Side effects:** writes provider accounts; writes the dev deployment; writes production. **--json:** `{ deployment, dryRun, log: [{ action, kind, key, id?, note? }], webhook: { url, action, secret: "stored" | "not-stored" | "none" }, senders, region, inbound: { support, inbox, domain, webhook, todo } | null }`, the secret never in it. **Exit codes:** `0` synced, or a dry run; `1` refused or failed: no `EMAIL_API_KEY`, a key restricted to sending, a deploy key for the other kind of deployment, no `email:syncEmail` on the deployment, a provider error, a webhook secret that could not be stored, or a support inbox sync that failed.

```bash
npx nuxt-backend email sync
npx nuxt-backend email sync --prod
npx nuxt-backend email sync --dry-run
npx nuxt-backend email sync --webhook off
```

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Sync production's email account and write the production deployment. Refuses a dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
      , as every command that writes production does.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --dry-run
      </code>
    </td>
    
    <td>
      Print each step it would take, and change nothing.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --webhook <url>
      </code>
    </td>
    
    <td>
      Point the webhook at this URL (default: <code>
        <site>/email/events
      </code>
      
       of the deployment written; <code>
        off
      </code>
      
       to leave the webhook alone).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

- **Finds before it creates.** A second run changes nothing that is already right, and it never deletes a topic, a segment or a property.
- **A topic's default is set once.** The provider can't change `subscribedByDefault` after it creates the topic, so a changed default is reported as `drift`, not applied.
- **A full-access key.** A key restricted to sending can't manage topics, segments or webhooks.
- **The senders.** Each of `EMAIL_FROM` and `EMAIL_MARKETING_FROM` is listed with its domain's sending region and DMARC policy, and a region that differs from `EMAIL_REGION` is reported.
- **One email account per app and stage.** The provider sends every event of an account to each of its webhooks, so a dev or demo app syncs to an account of its own ([Develop with real sandboxes](https://nuxt-backend.dev/docs/develop/sandboxes#email-on-resends-test-addresses)).

`doctor` reports what the provider lacks (`email-topics`, `email-webhook-events`, `email-key-permission`), and `doctor --fix` runs `email sync` once you confirm its dry run at a terminal, or with `--yes`. The question names every change: a new webhook's signing secret stored on the deployment, the provider ids it would store for topics it finds there, a lifecycle flow the deployment still runs though `backend/email.ts` dropped it, and what the support inbox's own dry run would create or add. When neither dry run finds one, it asks nothing. [Let people choose their emails](https://nuxt-backend.dev/docs/build/email/preferences) covers the topics it creates.

## `inbox`

Print the sign-in codes a dev deployment sent to one of Resend's test addresses. A coding agent or a script uses it to finish an email-code sign-in with no mailbox and no terminal to read. It reads the sent messages back through Resend's emails API, with the dev deployment's own `EMAIL_API_KEY`: the backend component's `email:inbox` action makes the calls (`npx convex run --component backend email:inbox`), so the key never leaves the deployment and the deployment stores no copy ([Dev inbox](https://nuxt-backend.dev/docs/develop/dev-inbox)).

```bash
npx nuxt-backend inbox                               # delivered@resend.dev
npx nuxt-backend inbox delivered+agent@resend.dev --json
```

**Side effects:** reads only. **--json:** `{ address, deployment, messages: [{ from, subject, receivedAt, code }], code }`: newest first, `code` the newest message's; bodies are never printed. **Exit codes:** `0` the inbox was read; it may be empty (`code` null); `1` refused — `--prod`, a deploy key for anything but a dev deployment, a deployment that is not dev-class, an address with no dev inbox — or the read failed.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        [address]
      </code>
    </td>
    
    <td>
      The test address to read: <code>
        delivered@resend.dev
      </code>
      
       (the default), or <code>
        delivered+<label>@resend.dev
      </code>
      
      . Any other address is refused.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the inbox as one JSON document.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Refused: the inbox is read on dev deployments only.
    </td>
  </tr>
</tbody>
</table>

It reads dev-class deployments only (`dev:`, `local:` and `anonymous:`) and refuses everything else: `--prod`, a `CONVEX_DEPLOY_KEY` for anything but a dev deployment (the Convex CLI would follow it), a `CONVEX_DEPLOYMENT` of another kind, and a self-hosted deployment, which does not say what it is. Only a test address receives mail outside `production`, and with no `EMAIL_API_KEY` nothing is sent: the sign-in code prints in the `convex dev` console instead, since `BACKEND_ENVIRONMENT` is `development` there.

## `upgrade`

Move the app to the version installed. It repairs the scaffold, as `doctor --fix` does, runs the package's own data migrations on the deployment, and starts the workpool backfill on every pool there. It rewrites no code: a release's renamed names are in the [changelog](https://nuxt-backend.dev/docs/ship/releases/changelog) and, for the previews of `main`, on the [Upgrade page](https://nuxt-backend.dev/docs/ship/releases/upgrade), and no release ships codemods. Run it after installing a new version, and again whenever it says so: every step is safe to repeat, and a second run changes nothing the first one finished.

```bash
npx nuxt-backend upgrade --dry-run      # each scaffold change as a diff, and where the migrations stand; writes nothing
npx nuxt-backend upgrade                # the scaffold and the dev deployment's data
npx nuxt-backend upgrade --prod --yes   # production's data, where its deploy did not run them
npx nuxt-backend upgrade --json         # the report as one JSON document
```

**Side effects:** writes project files; writes the dev deployment; --dry-run: reads only; --diff: reads only; --prod --yes: writes project files, writes production. **--json:** `{ to, dryRun, scaffold: { written, changes, diffs }, ejected: [{ target, file, from, to, changes }], data: { deployment, state, reason, migrations }, pools: { state, pools, failed: [{ component, reason }], reason }, next }`: `data.state` is `done`, `running`, `pending`, `none`, `skipped`, `needs-push` or `failed`; `pools.state` is `started`, `none`, `pending`, `skipped` or `failed`; `scaffold.diffs` comes with `--dry-run` only; with `--diff`, `[{ target, file, from, to, changes, diff }]` alone; progress goes to stderr. **Exit codes:** `0` done: the scaffold repaired; the data migrated, still migrating, waiting for a push, or skipped with no dev deployment; the workpool backfill started on every pool, or none needs it; `1` refused, a data migration or a pool's backfill failed, or with `--prod`, production could not be migrated.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --dry-run
      </code>
    </td>
    
    <td>
      Plan every step and write nothing: each scaffold file it would change, as a unified diff, the files it would write, and where each data migration stands on the deployment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --diff [name]
      </code>
    </td>
    
    <td>
      Print the upstream changes to each ejected file, or to the one named, as a unified diff between the version in its stamp and the installed one, and write nothing (<a href="https://nuxt-backend.dev/docs/build/ui/customize/eject#upgrade-an-ejected-file">
        Eject a part, page or email
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Run the data migrations on the production deployment instead of the dev one. Needs <code>
        --yes
      </code>
      
      , except with <code>
        --dry-run
      </code>
      
      , and refuses a dev or preview <code>
        CONVEX_DEPLOY_KEY
      </code>
      
      . Without <code>
        --prod
      </code>
      
      , a deploy key for anything but a dev deployment is refused: the Convex CLI follows the key whatever the flags say.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --yes
      </code>
    </td>
    
    <td>
      Confirm <code>
        --prod
      </code>
      
      . No command asks a question, so this flag is the confirmation.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the report as one JSON document; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

In order, it:

1. **repairs the scaffold**, exactly as [`doctor --fix`](#doctor) does before it pushes env: the scaffold files this version adds, the mounts, forwarded env names and route groups `convex.config.ts` and `http.ts` lack, and a `dev` script that stalls. It pushes no env.
2. **lists the ejected files**: each file whose stamp names an older version, with a count of upstream changes and the `upgrade --diff <name>` command that shows them.
3. **migrates the data.** The package's own migrations run on the migrations component nested in `backend`, which records how far each one got. A finished one is skipped, one that stopped, failed or was canceled resumes where it stopped, and they run one after another. It follows them for up to two minutes; past that they go on in the deployment, and a later run reports them. A deployment runs the code it was last pushed, so one that predates this version has no migrations to run yet: the data step reports `needs-push`, and the run after `npx nuxt-backend dev` (or production's deploy) migrates it. With no dev deployment configured, the step is skipped.
4. **backfills every workpool.** `@convex-dev/workpool` records on each piece of queued work the start entry it waits on, and its 0.5 line expects every entry to carry it; work queued before a pool recorded it does not. So the step runs the pool's own one-off `migrations:backfillPendingStartIds` on every pool the deployment mounts: the app's `workpool`, and the ones other components nest (the email component's two, the workflow component's, the `backend` component's waitlist mirror). The deployment lists its component paths, each is asked (four at a time), and one without the backfill, not a pool or a pool from before it, is left out. The backfill pages itself on the deployment and the command does not wait for it; running it again is harmless. A dry run starts nothing (`pools.state: "pending"`), and with no dev deployment the step is skipped with the data one.

It ends with the commands to run next: `init --agents` when the agent files are missing or name another version, `dev` and `upgrade` again while the dev data waits for a push (production's deploy, then `upgrade --prod --yes`, for production), then `doctor` and the app's type check.

<table>
<thead>
  <tr>
    <th>
      <code>
        data.state
      </code>
    </th>
    
    <th>
      Means
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        done
      </code>
    </td>
    
    <td>
      Every package migration finished on the deployment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        running
      </code>
    </td>
    
    <td>
      Started, and still going on the deployment's scheduler.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pending
      </code>
    </td>
    
    <td>
      Not started: a dry run reads where they stand and starts none.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        none
      </code>
    </td>
    
    <td>
      This version has no data migration.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        skipped
      </code>
    </td>
    
    <td>
      No dev deployment is configured, it did not answer, or a file of the app could not be written.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        needs-push
      </code>
    </td>
    
    <td>
      The deployment runs a backend older than this version.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        failed
      </code>
    </td>
    
    <td>
      A migration stopped on an error (<code>
        migrations[].error
      </code>
      
      ), or production did not answer.
    </td>
  </tr>
</tbody>
</table>

<table>
<thead>
  <tr>
    <th>
      <code>
        pools.state
      </code>
    </th>
    
    <th>
      Means
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        started
      </code>
    </td>
    
    <td>
      The backfill started on every pool in <code>
        pools
      </code>
      
      , and goes on in the deployment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        none
      </code>
    </td>
    
    <td>
      No pool on the deployment has the backfill: none is mounted, or each predates it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pending
      </code>
    </td>
    
    <td>
      A dry run: nothing started.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        skipped
      </code>
    </td>
    
    <td>
      The deployment was not reached, or did not list its components (<code>
        reason
      </code>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        failed
      </code>
    </td>
    
    <td>
      A pool refused it (<code>
        failed[]
      </code>
      
      , each with its <code>
        component
      </code>
      
       and <code>
        reason
      </code>
      
      ); the others still started, and the command exits <code>
        1
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

## `deploy`

Take production from nothing to a passing `doctor --prod` in one command. Each step looks before it writes, so a second run changes nothing that is already right, and a run that stopped halfway picks up where it stopped. [One-command production](https://nuxt-backend.dev/docs/ship/deploy/one-command) walks through it.

```bash
npx nuxt-backend deploy --dry-run   # every step it would take; writes nothing
npx nuxt-backend deploy             # production
npx nuxt-backend deploy --sandbox   # a demo or staging app on the test modes
```

**Side effects:** writes production; writes provider accounts; writes project files; --dry-run: reads only; --build: writes production, writes a preview deployment. **--json:** `{ dryRun, environment, host, steps: [{ id, capability, title, outcome, detail }], doctor }`: `outcome` is `done`, `unchanged`, `planned`, `skipped` or `failed`, `doctor` is `{ pass, warn, fail, failing }` or null; values never appear. **Exit codes:** `0` production passes `doctor --prod`, or a dry run; a step that waits on a key only you hold is skipped, not failed; `1` refused, a step failed, or `doctor --prod` fails.

The project file it writes is `backend/billing.generated.ts`, as `billing sync` does.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --dry-run
      </code>
    </td>
    
    <td>
      Print every step it would take, and change nothing.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --sandbox
      </code>
    </td>
    
    <td>
      Set <code>
        BACKEND_ENVIRONMENT=sandbox
      </code>
      
       instead of <code>
        production
      </code>
      
      , publish the <a href="https://nuxt-backend.dev/docs/develop/dev-inbox">
        dev inbox
      </a>
      
       (<code>
        EMAIL_DEV_INBOX=1
      </code>
      
      ), and sync to the providers' test modes (<a href="https://nuxt-backend.dev/docs/ship/deploy/staging">
        Deploy a demo or staging app
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --build
      </code>
    </td>
    
    <td>
      Run as the host's build command, as the <a href="https://nuxt-backend.dev/docs/ship/deploy/template">
        deploy template
      </a>
      
       does: put what the first push needs on production where it lacks it (a generated <code>
        AUTH_SECRET
      </code>
      
      , and <code>
        SITE_URL
      </code>
      
       from the host's production URL), then run <code>
        convex deploy --cmd '<package manager> run build'
      </code>
      
      , the backend first and the app against it. The package manager is the one <code>
        package.json
      </code>
      
      's <code>
        packageManager
      </code>
      
       pins, else the one whose lockfile sits in the project or above it in the repository (a workspace's root), else npm; it runs the build and the package's CLI (<code>
        pnpm exec nuxt-backend
      </code>
      
      , <code>
        yarn nuxt-backend
      </code>
      
      , <code>
        bunx nuxt-backend
      </code>
      
      , <code>
        npx nuxt-backend
      </code>
      
      ). With a preview deploy key it fills the preview's env as <a href="#preview-deployments">
        <code>
          env push --preview
        </code>
      </a>
      
       does, its <code>
        SITE_URL
      </code>
      
       from <code>
        VERCEL_BRANCH_URL
      </code>
      
      , else <code>
        VERCEL_URL
      </code>
      
       for a deployment made outside Git, and a new preview loads the billing products once pushed (<code>
        --preview-run billing:syncProducts
      </code>
      
      ) when the build's env holds <code>
        BILLING_ACCESS_TOKEN
      </code>
      
      ; without one it says so and skips it, since the sync would be refused and fail the build. With a production key, once <code>
        convex deploy
      </code>
      
       pushed the backend, it runs the package's data migrations and the workpool backfill there, as <code>
        upgrade --prod --yes
      </code>
      
       does. A migration that fails fails the build. When production does not answer them, or a pool refuses the backfill, it warns and the build passes: the new backend is up already, and a failed build would only keep the previous app live against it (<code>
        upgrade --prod --yes
      </code>
      
       finishes them). A preview has none to run. It never sets <code>
        BACKEND_ENVIRONMENT
      </code>
      
      , so a new app stays on the test modes until <code>
        deploy
      </code>
      
       makes it live.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the outcome as one JSON document; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

In order, it:

1. links the project's production deployment, or creates it with your Convex login (`convex deployment create --type prod --default`);
2. sets `BACKEND_ENVIRONMENT` to `production`, unless the deployment already holds `sandbox`, which it keeps, or `--sandbox` is given. A value it cannot read stops the run: it never guesses;
3. pushes production's own env: a generated `AUTH_SECRET`, the app's public origin as `SITE_URL`, the billing token and the email key, and on Vercel a generated bot-check proof secret. On a sandbox it also sets `EMAIL_DEV_INBOX=1`, so the demo's visitors read their sign-in codes off the page. Nothing is copied from `.env.local`, which holds development's;
4. deploys the backend with `convex deploy`;
5. syncs the billing catalog to the environment production bills in, as [`billing sync`](#billing-sync) does, registering the billing webhook and storing its signing secret on production, and deploys the backend again when the sync wrote new ids;
6. runs the package's data migrations and the workpool backfill on production, as [`upgrade --prod --yes`](#upgrade) does, once the backend went up (a dry run reads where they stand). A migration that fails fails the run, and the steps after it still run. When production does not answer them, or a pool refuses the backfill, the step is `skipped`, not `failed`, so the run goes on and exits `0` unless another step fails: `upgrade --prod --yes` finishes them;
7. registers the email provider's webhook, storing its signing secret on production. The email topics and segments come with [`email sync`](#email-sync);
8. writes the env the Nuxt app needs into the Vercel project's production environment, through your own Vercel login: `NUXT_PUBLIC_BACKEND_URL`, a production `CONVEX_DEPLOY_KEY` it creates for the build, and the proof secret. It stores no token. On another host, it names what to set there;
9. runs [`doctor --prod`](#doctor), and prints what fails and what bot protection, monitoring and hosting still lack.

A key only you hold, such as the billing token, comes from the shell (`BILLING_ACCESS_TOKEN`, `EMAIL_API_KEY`, `SITE_URL`), or at a terminal `deploy` asks for it, without echoing a secret. In CI, without a terminal or with `--json`, it asks nothing: it names that step and skips it, and the next run picks it up. It refuses a dev or preview `CONVEX_DEPLOY_KEY`, as every command that writes production does.

## `analyze`

Measure the backend's Convex bundle and the Nuxt app's client and server bundles, with the share `nuxt-backend` and your own code take in each, and the insights that would shrink them. The Convex half runs [`@convex-dev/bundle-analyzer`](https://www.npmjs.com/package/@convex-dev/bundle-analyzer), which is in alpha, and the Nuxt half reads the build `nuxi analyze` makes ([See what is inside your bundles](https://nuxt-backend.dev/docs/develop/analyze)).

```bash
npx nuxt-backend analyze
npx nuxt-backend analyze --only convex --max-convex 8MB --json
```

**Side effects:** reads only. **--json:** `{ version, ranAt, bundles: [{ id, title, bytes, gzipBytes, sourceMapBytes, parts, packages, shares, insights, notes }], budgets: [{ bundle, flag, limit, bytes, over, grew }], failures: [{ half, message }] }`: `id` is `convex`, `client` or `server`, and `bytes` is the code without source maps; progress goes to stderr. **Exit codes:** `0` measured, and within every budget given; `1` a bundle is over its budget, `backend/_generated/` is missing, a build failed, or a flag was refused.

It bundles the backend and builds the Nuxt app locally and writes nothing to the deployment; the run is kept in `node_modules/.cache/nuxt-backend/analyze.json`, which the DevTools Bundles panel and `doctor`'s `bundle-duplicates` read. Each bundle's `bytes` is its code without source maps, the size a budget is held to: for Convex, your functions and each component added up; for Nuxt, the client's minified chunks and the server's modules before minification. A half that cannot run is listed under `failures` and the other half is still measured.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --only <convex|nuxt>
      </code>
    </td>
    
    <td>
      Measure one half. <code>
        convex
      </code>
      
       skips the Nuxt build.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --max-convex <size>
      </code>
    </td>
    
    <td>
      Fail when the Convex bundle's code (without source maps) is larger. A size is a number with a unit: <code>
        8MB
      </code>
      
      , <code>
        350kB
      </code>
      
      , <code>
        2MiB
      </code>
      
      , or bytes alone.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --max-client <size>
      </code>
    </td>
    
    <td>
      Fail when the Nuxt client bundle is larger.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --max-server <size>
      </code>
    </td>
    
    <td>
      Fail when the Nuxt server bundle is larger.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print the report as one JSON document; progress goes to stderr.
    </td>
  </tr>
</tbody>
</table>

A budget for a bundle the run doesn't measure is refused (`--max-client` with `--only convex`), as is a size that isn't one. Over a budget, it names the packages that grew most since the run before, or else the bundle's largest package.

## `eject`

Copy the source of a part, a packaged page or an email into the app, so you own it outright. It is the last rung of the [customization ladder](https://nuxt-backend.dev/docs/build/ui/customize): reach for it once tokens, labels, slots, swapping a part and the headless composables can't make the change ([Eject a part, page or email](https://nuxt-backend.dev/docs/build/ui/customize/eject)).

```bash
npx nuxt-backend eject AuthFormCode        # a part, by its registered name
npx nuxt-backend eject page:pricing        # a packaged page, by its page key
npx nuxt-backend eject email:invite        # an email template, by its name
npx nuxt-backend eject --list              # everything that can be ejected
```

**Side effects:** writes project files; --list: reads only. **--json:** `each file it wrote, with the version stamped in it: `{ target, version, written, todo? }`; with `--list`, `[{ target, kind, ejected }]``. **Exit codes:** `0` the source was copied; `1` the name is unknown, or a file is in the way and `--force` was not given.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        <target>
      </code>
    </td>
    
    <td>
      A part's name from <a href="https://nuxt-backend.dev/docs/reference/components/parts">
        Parts
      </a>
      
       or a packaged component's, such as <code>
        AuthForm
      </code>
      
      , <code>
        page:<key>
      </code>
      
       for a packaged page, or <code>
        email:<name>
      </code>
      
       for one of the <a href="https://nuxt-backend.dev/docs/build/email/templates">
        email templates
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --list
      </code>
    </td>
    
    <td>
      Print every name it can eject, and change nothing.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --force
      </code>
    </td>
    
    <td>
      Overwrite a file of that name already in the app.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --json
      </code>
    </td>
    
    <td>
      Print what it wrote as one JSON document.
    </td>
  </tr>
</tbody>
</table>

What it writes:

- **A part** lands in `app/components/` as a `.vue` file with its CSS, under the part's own name. A same-named app component replaces the packaged one everywhere, packaged pages included, so the copy takes over at once.
- **A page** lands in `app/pages/` at its mounted path, where an app page always wins.
- **An email** lands in `backend/emails/` as a template function, and `eject` adds it to `setupEmail`'s `templates` in `backend/email.ts`, so it is sent in place of the packaged one. An app whose `convex.json` names another functions directory gets both there.

Each file starts with a comment that names the package version it came from. [`upgrade`](#upgrade) diffs every ejected file against the new version's source and lists the changes you may want to carry over. It never rewrites an ejected file.

## `mcp`

Run the developer MCP server, one stdio server that gives your coding agent the project and the services it runs on. [`init`](#init) writes it into `.mcp.json`, so an agent that reads that file starts it on its own ([Developer MCP server](https://nuxt-backend.dev/docs/develop/agents/developer-mcp)).

```json [.mcp.json]
{
  "mcpServers": {
    "nuxt-backend": { "command": "npx", "args": ["nuxt-backend", "mcp"] }
  }
}
```

**Side effects:** writes the dev deployment; writes provider accounts; --prod: reads only. **--json:** none: it speaks MCP on stdin and stdout until the client closes it. **Exit codes:** `0` the client closed the connection; `1` it could not start: no such project directory, @modelcontextprotocol/sdk not installed, or --prod refused for a deploy key of another deployment.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --prod
      </code>
    </td>
    
    <td>
      Read production: the project, billing, email and hosting tools read it, the Convex tools read only its logs and insights, and no tool that writes is listed. Refused with a <code>
        CONVEX_DEPLOY_KEY
      </code>
      
       for a dev or preview deployment.
    </td>
  </tr>
</tbody>
</table>

Its tools:

- **Project state:** `doctor`'s findings, the capabilities, the env names (never their values), the billing catalog and the function contract.
- **Docs:** a search of these docs, and page reads.
- **Pass-through tools** for Convex, Polar, Resend and Vercel. They reuse the logins and keys your project and your own CLIs already hold, and store none. Polar's tools act on the sandbox unless the server runs with `--prod`.

Each tool that writes asks you to confirm first, through your agent's own prompt, and is refused by a client that cannot ask.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
