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

> ## Agent Instructions
> Spree 6 (v6.x) is the current version. Pages with /v5/ in their URL document Spree 5: follow them in a project that runs Spree 5, or to see what an upgrade changes.
> Spree 6 differs greatly from Spree 4 and 5: it is fully headless, and older code and tutorials mostly do not apply. Before relying on what you remember about Spree, read https://spreecommerce.org/docs/developer/upgrades/spree-6-vs-older-versions.md
> The current REST APIs are the Store API (store.yaml), the Admin API (admin.yaml) and the Seller API (seller.yaml), all under /api/v3.
> The specs named legacy-v2-*, the Storefront API and Platform API pages and their tutorials document the older API v2, which Spree 5 and earlier serve. Read them to maintain or migrate an API v2 client, and build new work on the current APIs.

# CLI Commands

> Every @spree/cli command — boot and stop the stack, add extensions, generate code, migrate, run tests and upgrade Spree projects.

Run these from your project directory. See [Installation](https://spreecommerce.org/docs/developer/cli/installation.md) to set up the CLI, and [Admin API CLI](https://spreecommerce.org/docs/developer/cli/admin-api.md) for the `spree api` commands.

## Project commands

### `spree init`

First-run setup. Starts Docker services, seeds the database, generates an API key, and optionally loads sample data.

```bash theme={"theme":"night-owl"}
spree init
spree init --no-sample-data   # Skip sample data
spree init --no-open           # Skip opening browser
spree init --detach            # Exit when setup is done (scripts, CI); the stack keeps running
```

### `spree dev`

Run the app in the foreground — streams web + worker logs; `Ctrl+C` stops them. The databases keep running for a fast next boot (`spree stop` shuts everything down). The Admin Dashboard opens in your browser as soon as it is ready.

```bash theme={"theme":"night-owl"}
spree dev
spree dev --no-open            # Skip opening browser
```

### `spree stop`

Stop all services.

```bash theme={"theme":"night-owl"}
spree stop
```

### `spree restart`

Restart `web` and `worker` in place — same image, same volumes, fresh backend process. Good for configuration changes the backend doesn't reload on its own.

```bash theme={"theme":"night-owl"}
spree restart
```

Not appropriate for dependency changes (Ctrl+C and re-run `spree dev`), Dockerfile or runtime version changes (use `spree build`), or compose file changes (Ctrl+C and re-run `spree dev`).

### `spree build`

Rebuild the dev image after Dockerfile or runtime version changes. Only relevant after `spree eject`.

```bash theme={"theme":"night-owl"}
spree build
spree build --reset-deps     # Also drop the cached backend dependencies so they re-install
spree build --yes            # Skip confirmation prompts (for CI)
```

`spree add <extension>` does NOT require a rebuild — dependencies land in a cache volume which survives image rebuilds.

`--reset-deps` only drops that cache. Postgres, Redis, Meilisearch, and storage volumes are preserved.

### `spree upgrade`

Upgrade your project to the latest Spree release in one go. It works for both kinds of project:

1. **Update the server** — on a project that runs the prebuilt image, it pulls the latest Spree image. On an [ejected](#spree-eject) project, it updates the Spree gems with `bundle update`.
2. **Update the `@spree/*` packages** — `@spree/cli` and `@spree/docs` in the project root, and the dashboard packages and SDKs in `apps/dashboard` and `apps/seller-dashboard`. The docs, dashboard packages and SDKs carry the Spree version and move to a `^` range on the version your server now runs, so they can resolve to a later compatible release. `@spree/cli` moves to the newest release its range in `package.json` allows.
3. **Update the agent skills** — if the project has the [Spree agent skills](https://spreecommerce.org/docs/developer/agentic/agent-skills.md) (listed in `skills-lock.json`), it asks whether to update them, then installs every skill from the `spree/agent-skills` release for the Spree version your server now runs: the newest `v6.0.x` tag that is not newer than a 6.0.x server, for example. `skills-lock.json` records the release each skill came from. When there is no such tag yet, or the releases can't be listed, the skills come from the main branch. A Spree skill you removed is installed again; skills from other sources are left alone. Projects without the Spree skills are not asked; install them with [`spree add ai`](#spree-add).
4. **Migrate the database** — on a prebuilt-image project, it recreates the containers and the migrations run as they start. On an ejected project, it applies pending migrations.
5. **Run the upgrade steps** — the version-specific steps from the upgrade manifest: data backfills that convert existing records and, from Spree 6.1, a last step that adds the scheduled jobs the release needs to `config/recurring.yml` on a project that runs from its own source. Review that file and commit it. An ejected project's app is then restarted so it loads the new gems.

The packages and skills are updated before the database steps, so a failed migration or backfill no longer stops them from moving to the newest release their ranges allow. Fix the cause and run `spree upgrade` again.

```bash theme={"theme":"night-owl"}
spree upgrade                  # Run every step, asking before each one
spree upgrade --plan           # List the data backfills without running anything
spree upgrade --to 6.1         # Set the target version for the data backfills
spree upgrade --step <id>      # Re-run a single data backfill (runs nothing else)
spree upgrade --yes            # Skip the prompts
```

Your storefront is your own code, so `spree upgrade` does not change it — it tells you which `@spree/sdk` version to move to.

Production upgrades only need the data backfills — installing gems and migrating happen in your deploy pipeline. See [Upgrades](https://spreecommerce.org/docs/developer/upgrades) for the manual production path.

> [!NOTE]
>
> `spree update` is the old name for this command. It still works, prints a deprecation warning, and will be removed in a future release.

### `spree eject`

Switch from the prebuilt Docker image to building from your local `server/` directory. This lets you customize the backend — add extensions, override models, add migrations, etc.

```bash theme={"theme":"night-owl"}
spree eject
```

After ejecting, the Docker image is built from `server/Dockerfile`. Edit files in `server/` and run `spree dev` to rebuild and restart with your changes.

Your data comes with you. The ejected project uses its own development database, and `spree eject` fills it with a copy of the data you had: the admin account, products, orders, settings and API keys. The database you ran before is left untouched.

```bash theme={"theme":"night-owl"}
spree eject --fresh    # Do not copy the data: start with a new, empty development database
```

Two cases where nothing is copied:

* **A development database already exists**, from an earlier eject. It is kept as it is, with or without `--fresh`, and the command says so. To empty it, run `spree db:reset` once the eject has finished. If that database is newer than `server/`, the command stops and says how to remove it.
* **The current database is newer than `server/`.** This happens when `spree upgrade` moved the prebuilt image to a newer Spree than the code in `server/`. The older code cannot run on that data, so the command stops and asks you to run `spree eject --fresh`.

See [Customizing the Backend](https://spreecommerce.org/docs/developer/create-spree-app/quickstart.md#customizing-the-backend) for details on what you can customize.

### `spree add`

Add an optional part or an extension to an existing project.

```bash theme={"theme":"night-owl"}
spree add dashboard           # the Admin Dashboard app in apps/dashboard/, to customize it
spree add seller-dashboard    # the marketplace Seller Panel in apps/seller-dashboard/
spree add ai                  # Spree agent skills + the docs MCP server for coding agents
spree add stripe              # an extension, installed end to end
```

`spree add ai` installs the [Spree agent skills](https://spreecommerce.org/docs/developer/agentic/agent-skills.md) from the release for the CLI's Spree version (the newest tag on its minor line that is not newer than it; from the main branch when there is no such tag, or the releases can't be listed) and connects Claude Code, Cursor and VS Code to the [docs MCP server](https://spreecommerce.org/docs/developer/agentic/docs-mcp.md). It keeps the MCP servers your config files already list and is safe to re-run. Pass `--no-skills` or `--no-mcp` to set up only one of the two.

#### Extensions

`spree add <extension>` installs an official extension in one step: it adds the gem, runs the extension's installer if it has one, runs the migrations, installs its dashboard plugin if it has one, and restarts the server if it is running.

| Extension | Command |
| - | - |
| [Stripe](https://spreecommerce.org/docs/integrations/payments/stripe.md) | `spree add stripe` |
| [PayPal](https://spreecommerce.org/docs/integrations/payments/paypal.md) | `spree add paypal` |
| [Adyen](https://spreecommerce.org/docs/integrations/payments/adyen.md) | `spree add adyen` |
| [Avalara AvaTax](https://spreecommerce.org/docs/integrations/tax/avalara.md) | `spree add avatax` |
| [Klaviyo](https://spreecommerce.org/docs/integrations/marketing/klaviyo.md) | `spree add klaviyo` |
| [EasyPost](https://spreecommerce.org/docs/integrations/shipping/easypost.md) | `spree add easypost` |
| [Meilisearch](https://spreecommerce.org/docs/integrations/search/meilisearch.md) | `spree add meilisearch` |
| [MCP server](https://spreecommerce.org/docs/developer/mcp/quick-start.md) | `spree add mcp` |
| [OpenTelemetry](https://spreecommerce.org/docs/developer/providers/observability.md) | `spree add opentelemetry` |

A few things to know:

* **A project on the prebuilt image is ejected first.** The prebuilt image cannot load new gems, so the command offers to [eject](#spree-eject) the project. Ejecting takes a few minutes and changes how the project runs, so it asks before doing it; your data is copied to the new development database, unless one is left from an earlier eject. Pass `--yes` to agree up front, for example in a script.
* **New projects already include some extensions.** Stripe, EasyPost, Meilisearch and OpenTelemetry come with every new project. Until you eject, the command tells you there is nothing to install for those. After ejecting, it runs their installer and migrations again, which is harmless.
* **It is safe to run again.** If an install fails partway, the command puts your `Gemfile` and `config/` back as they were. Running it again finishes an install that stopped halfway, and keeps files the first run created.
* **Setup notes come from the extension.** If an extension needs anything else, such as an environment variable, it says so while it installs.

To install an extension that is not in this list, name its gem or dashboard plugin package. The command asks you to confirm, since Spree does not vouch for it:

```bash theme={"theme":"night-owl"}
spree add --gem spree_acme_loyalty
spree add --gem spree_acme_loyalty --npm @acme/loyalty-dashboard
```

### `spree logs`

Stream service logs.

```bash theme={"theme":"night-owl"}
spree logs         # Web service (default)
spree logs worker  # Worker service
```

### `spree console`

Open an interactive backend console.

```bash theme={"theme":"night-owl"}
spree console
```

### `spree shell`

Open an interactive bash shell inside the web container — the system-shell sibling of `spree console` and `spree db:console` (psql). If the web container is down, it starts a one-off container against the same volumes instead. For one-off non-interactive commands, use `spree exec`.

```bash theme={"theme":"night-owl"}
spree shell
spree bash    # alias
```

### `spree open`

Open the admin dashboard in the browser.

```bash theme={"theme":"night-owl"}
spree open
```

### `spree seed`

Seed the database.

```bash theme={"theme":"night-owl"}
spree seed
```

### `spree sample-data`

Load sample products, categories, and images.

```bash theme={"theme":"night-owl"}
spree sample-data
```

### `spree user create`

Create an admin user. Prompts for email and password interactively, or pass them as flags:

```bash theme={"theme":"night-owl"}
spree user create
spree user create --email admin@example.com --password secret123
```

### `spree api-key`

Manage Store and Admin API keys. Secret keys carry [scopes](https://spreecommerce.org/docs/api-reference/admin-api/authentication.md) and require at least one.

```bash theme={"theme":"night-owl"}
spree api-key list                                     # List all keys (--json for JSON)
spree api-key create                                   # Interactive
spree api-key create --name "Storefront" --type publishable             # Store API key
spree api-key create --name "Admin" --type secret --scopes read_all     # Admin API key
spree api-key revoke <id>                              # Revoke a key
```

`spree api-key list --json` prints `[{ id, name, type, token, token_prefix, created_at, status }]`. A secret key is stored only as a digest, so its `token` is `null` and `token_prefix` holds its first 12 characters.

### `spree encryption init`

Generate [Active Record encryption](https://spreecommerce.org/docs/developer/deployment/environment_variables.md#active-record-encryption) keys — Spree encrypts webhook signing secrets, payment gateway customer IDs and OAuth tokens with them. New projects already have keys; use this for projects created before they were generated at setup.

```bash theme={"theme":"night-owl"}
spree encryption init            # Add ACTIVE_RECORD_ENCRYPTION_* keys to the project's .env
spree encryption init --print    # Print a fresh set without writing anything (e.g. for your hosting provider)
```

It never overwrites keys `.env` already sets, and there is no `--force`: changing the keys makes data encrypted with them unreadable. Afterwards, recreate the containers so they load the new `.env` (`spree dev` — `spree restart` keeps the old environment), and back the keys up in your secret manager.

### `spree api`

Call the Admin API with generic `get`/`post`/`patch`/`delete` commands — zero-config inside a project (a read-only key is minted on first use), env vars or profiles for remote stores. See [Admin API CLI](https://spreecommerce.org/docs/developer/cli/admin-api.md) for the full guide.

```bash theme={"theme":"night-owl"}
spree api get /products -q status_eq=active --limit 10
spree api post /products -d '{"name":"Classic Tee","prices":[{"currency":"USD","amount":"29.99"}]}'
spree api endpoints --resource orders    # endpoints + required scopes, offline
spree api schema "POST /orders"          # request/response schema, offline
spree api status
```

### `spree auth`

Save Admin API credentials for remote stores as named profiles.

```bash theme={"theme":"night-owl"}
spree auth login --profile prod --base-url https://store.example.com
spree api get /orders --profile prod
spree auth status
spree auth list                  # saved profiles (--json: [{ name, base_url, key_prefix, default }])
spree auth logout --profile prod
```

### `spree docs`

Search the Spree docs installed with the project by the `@spree/docs` package, which match the project's Spree version. It works offline. With no words, it prints where the docs are, their sections and the online entry points. With words, it prints the best matching pages: a page must contain every word, and pages whose title or headings match come first. The [docs MCP server](https://spreecommerce.org/docs/developer/agentic/docs-mcp.md) searches the latest published docs instead.

```bash theme={"theme":"night-owl"}
spree docs                         # where the docs are and their sections
spree docs price list              # matching pages: path, title, heading, one line of context
spree docs order.placed --limit 5  # at most 5 matches (default 10)
spree docs price list --json       # { docs: { path, version }, query, results: [{ path, title, heading, excerpt }] }
```

It exits with 1 when nothing matches or `@spree/docs` is not installed, and with 2 on a usage error. With `--json`, standard output holds only the JSON, in every case but a usage error; messages go to standard error.

## Dev workflow commands

These commands run inside the project's containers against the running stack. The exceptions are `spree filters types --from`, which reads a saved file, and `spree sdk generate`, which runs against an extension's own bundle; neither needs a running stack.

### `spree generate`

Run a generator inside the container. Bare generator names are auto-prefixed with `spree:` — `model` runs `spree:model`, `api_resource` runs `spree:api_resource` — so you get the Spree conventions (`Spree::` namespace, `spree_`-prefixed table, prefixed IDs, `null: false`, no FK constraints) by default. Rails built-ins (`migration`, `scaffold`, `mailer`, `job`, …) and any name containing `:` are forwarded as-is.

```bash theme={"theme":"night-owl"}
spree generate model SizeGuide name:string slug:string:uniq --id-prefix sg          # runs spree:model
spree generate api_resource SizeGuide name:string slug:string:uniq --id-prefix sg   # runs spree:api_resource — model + v3 Store/Admin API
spree generate subscriber OmsOrderSync order.placed                                 # runs spree:subscriber — event subscriber + registration
spree generate migration AddPositionToSpreeSizeGuides position:integer              # Rails built-in, forwarded as-is
```

A model's prefixed IDs start with the lowercase letters of its name, without underscores or digits (`SizeGuide` → `sizeguide_…`). Pass `--id-prefix=sg` for a shorter one; a prefix is lowercase letters only. Boolean columns default to `false`; set another default in braces, as `active:boolean{true}`.

`spree:api_resource` scaffolds the full v3 surface: model, migration, Store + Admin controllers and serializers, factory, controller specs, routes, and the `read_<resources>` / `write_<resources>` permissions that let staff roles and secret API keys reach the Admin API.

The command prints a short summary instead of the generator's full output: the files it created, changed or skipped, anything the generator says on its own, and what to run next. File paths are relative to the directory you ran the command from, so from a project root they start with `server/`. The `spree test` paths are relative to the app, because that command runs inside the container.

```
spree:subscriber finished:
  created  server/app/subscribers/oms_order_sync_subscriber.rb
  changed  server/config/initializers/spree.rb
  created  server/spec/subscribers/oms_order_sync_subscriber_spec.rb

Next:
  spree restart  # server/config/initializers/spree.rb loads only at boot
  spree test spec/subscribers/oms_order_sync_subscriber_spec.rb
```

Pass `--verbose` before the generator name to see the full output (`spree generate --verbose model SizeGuide --id-prefix sg`). When a generator fails, the command prints everything it printed, including the Rails and Docker output, and exits with the generator's exit code. A generator's `--help` is always shown in full.

The prebuilt image never loads files from `server/`, so on a project that still runs it, the command offers to [eject](#spree-eject) the project first. Ejecting takes a few minutes and changes how the project runs, so it asks before doing it; your data is copied to the new development database, unless one is left from an earlier eject. Pass `--yes` before the generator name to agree up front (`spree generate --yes model SizeGuide --id-prefix sg`). With no terminal to ask in, for example when a coding agent runs it, the command stops and prints that `--yes` command.

### `spree filters types`

Generate TypeScript declarations for your app's list filters, so the SDKs accept and autocomplete the filters and sort fields your app adds. It reads them from the running app and writes `src/types/spree-filters.d.ts` into each app under `apps/` (storefront, dashboard, seller panel), for the SDK that app uses. Run it again after you change a filter.

```bash theme={"theme":"night-owl"}
spree filters types                                                    # every app under apps/
spree filters types --api store --out ../my-storefront/src/types/spree-filters.d.ts   # one app elsewhere
spree filters types --from filter-tables.json                         # from `spree task api:filter_tables` output
```

See [using your own filters from TypeScript](https://spreecommerce.org/docs/developer/core-concepts/search-filtering.md#using-your-own-filters-from-typescript).

### `spree sdk generate`

Generate the client of a package that [ships a client for an extension's endpoints](https://spreecommerce.org/docs/developer/sdk/extending.md#shipping-a-client-for-an-extension), from the extension itself. Run it in the package, with the extension named in its `package.json` (`"spree": { "extension": "../my_extension" }`). It runs the extension's `rake spree:openapi:generate` and `rake spree:sdk:serializer_types`, then writes `src/generated/<api>/`: one SDK extension per resource (`client.ts`), the request body types (`params/`), the list filters (`filters.ts`) and the response types (`types/`, `spree.ts`). Run it again after you change an endpoint or a serializer.

```bash theme={"theme":"night-owl"}
spree sdk generate                 # run the extension's rake tasks, then write everything
spree sdk generate --no-backend    # from the committed openapi/*.yaml and response types
spree sdk generate --check         # in CI: write nothing, fail when the files are out of date
```

The files import shared types from the SDK each API belongs to (`@spree/sdk`, `@spree/admin-sdk` or `@spree/seller-sdk`).

### `spree migrate`

Install pending Spree migrations, then run them — the canonical post-update sequence.

```bash theme={"theme":"night-owl"}
spree migrate
spree migrate:status               # show which migrations have run
spree migrate:rollback             # roll back the last migration
spree migrate:rollback --steps 2   # roll back the last two
```

`spree migrate:status` and `spree migrate:rollback` use the backend's own migration tooling, so they may change in a future major release. `spree migrate` itself stays the same.

### `spree db:reset`

Drop, recreate, migrate, and seed the database. **Destructive** — wipes everything. Asks for confirmation.

```bash theme={"theme":"night-owl"}
spree db:reset
spree db:reset --yes   # Skip confirmation (for CI)
```

### `spree db:console`

Open a `psql` session against the dev Postgres database (runs inside the `postgres` container).

```bash theme={"theme":"night-owl"}
spree db:console
```

### `spree test`

Run the backend test suite inside the web container against the test database — never your development data. Everything after `test` goes to the backend's test runner (RSpec today), so file paths, line numbers and flags follow that runner's format.

```bash theme={"theme":"night-owl"}
spree test                                          # full suite
spree test spec/models/spree/size_guide_spec.rb     # one file
spree test spec/models/spree/size_guide_spec.rb:15  # one example
spree test --format documentation
```

The test database is created on the first run. See the [Testing tutorial](https://spreecommerce.org/docs/developer/tutorial/testing.md) for writing specs.

## Running things inside the container

### `spree task`

Run a Spree maintenance task. The task names are stable; anything after the name goes to the task in the task runner's own format.

```bash theme={"theme":"night-owl"}
spree task load_sample_data
spree task search:reindex
spree task price_history:seed
spree task price_history:prune
```

### `spree exec`

Run an arbitrary command inside the `web` container. Use it for anything without a dedicated command.

```bash theme={"theme":"night-owl"}
spree exec ls -la
spree exec env
spree exec bin/rails runner "puts Spree::Product.count"
spree exec bundle outdated
```


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