---
title: Set up an environment
description: Link or create a personal stage, then reuse it safely across Workbench worktrees.
owner: engineering
sourceFiles:
  - apps/cli/src/wizard.ts
  - apps/cli/src/environments.ts
  - apps/cli/src/development.ts
  - apps/cli/src/client-config.ts
  - apps/cli/src/workflow.ts
  - scripts/dev.ts
---

## First run

From the repo root, run `bun run onboard` in an interactive terminal. It first [clones missing reference repositories](/reference/cli#reference-repositories), then opens environment setup:

1. Choose **Link existing environment** or **Create new environment**, then enter its exact `dev-*` stage name.
2. Connect Cloudflare with **OAuth** and select `Sriket@wurthy.co’s Account`. For PlanetScale, choose **Service Token**, enter the ID/token provided privately by your administrator, and enter organization `workbench`. Obtain [access and a token](/operations/credentials#developer-access) before starting.
3. Linking verifies saved outputs and API readiness, then saves the connection. Creating runs a fresh plan and requires typing the stage name before deploying.

Escape/Ctrl+C cancels a question; Enter without the stage name declines deployment. Failed or cancelled setup keeps the previous selection. See [stage limits](/reference/cli#stages-and-profiles).

## Fix an earlier setup

Run the two [authentication commands](/operations/credentials#alchemy-profiles) to replace incorrect accounts or PlanetScale OAuth. Rerun `bun run onboard` and link your existing `dev-*` stage. If none exists, create one. Do not delete profiles or databases to retry setup.

## Returning to setup

Guided setup first validates development configuration, including any [shared Proton secrets](/operations/credentials#shared-development-secrets-with-proton-pass). With no secret references configured, Proton access is optional. Existing configured references must resolve before setup continues.

Setup checks connections, saved outputs, and API readiness. **Done** is the read-only default.

| Choice | Effect |
| --- | --- |
| Check connections | Repeat read-only checks |
| Check development secrets | Resolve development references and validate configuration without saving values or deploying |
| Refresh API connection for this checkout | Save the verified URL, stage, and profile without deploying; offered only when the API is ready |
| Review infrastructure updates | Plan, then require the typed stage before deployment |
| Switch environment | Verify and link another existing stage without provisioning |
| Create another environment | Choose a different stage, then plan and confirm |
| Reconnect accounts | Open provider sign-in |

## New worktree

Run `bun run dev`. It uses this checkout's `WORKBENCH_DEV_STAGE` when set, otherwise the environment remembered by onboarding for `ALCHEMY_PROFILE` (default: `default`). New worktrees reuse that selection automatically. With no selection, an interactive picker lists existing personal environments; if none exist, run `bun run onboard` once.

To override both profile and environment for one session:

```sh
ALCHEMY_PROFILE=team WORKBENCH_DEV_STAGE=dev-yourname bun run dev
```

For frontend-only `bun run dev:web`, run onboarding's **Refresh API connection for this checkout** to verify readiness and write the verified API URL, stage, and profile to this checkout’s `.env.local` without deploying. Ignored `.env.local` files are not copied into new worktrees; restart any running dev server after refreshing.

Worktrees have separate local ports, URLs, and runtime state. Selecting the same stage shares database records and schema; provision another stage for database isolation.

## What is saved

Linking, refreshing, and successful provisioning preserve unrelated `.env.local` settings and write:

| Setting               | Purpose                                            |
| --------------------- | -------------------------------------------------- |
| `API_PROXY_TARGET`    | Hosted API URL from the stage's `serverUrl` output |
| `WORKBENCH_DEV_STAGE` | Personal database stage                            |
| `ALCHEMY_PROFILE`     | Credential profile                                 |

The wizard remembers `profile` and `stage` in `workbench-onboarding.json` in the Git common directory (`git rev-parse --path-format=absolute --git-common-dir`). It contains no credentials. Separate clones link independently. Scripted `provision` saves local settings; the wizard remembers its selection after readiness succeeds.

## Start the application

Run `bun run dev` and open the frontend URL printed by Portless. Nx starts the frontend and local API against the existing personal database; startup does not deploy or apply migrations.

Use `bun run dev:web` for frontend-only development with the saved hosted API target. Detailed Portless and Nx instructions remain in `onboarding/README.md`. See [authentication setup](/architecture/authentication#routing-and-cookies) for origin, cookie, and personal-stage migration requirements.

Continue with the [local-to-production workflow](/development/workflow) for automatic hosted PR previews and cleanup.
