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

# Setup command and skill

> The start and wait commands of npx @uselemma/setup, the files they write, and the lemma-setup skill that runs them

`npx @uselemma/setup` connects an app and its coding agent to Lemma through one browser approval. Your coding agent runs it when it follows the `lemma-setup` skill from the setup prompt in Lemma. This page lists the two commands, their flags, what they write for each coding agent, how the agent signs in to the Lemma Model Context Protocol (MCP) server, when an existing key or server is kept, and the exit codes.

## Start, then wait

Setup runs as two commands, so `start` returns at once and a pending `wait` ends within a coding agent’s default command timeout. With `--sign-in`, an approved `wait` also waits for the sign-in. Run both from the app’s root directory, where the app loads `.env`:

1. `start` checks every file it will write, starts the approval, prints the approval URL and a code, opens the browser, and returns at once
2. `wait` checks for the approval for up to 90s. While the approval is pending it exits with `5`; run it again. Once you approve, it writes the ingest key and the coding agent’s `lemma` server, runs or prints the agent’s sign-in, and exits with `0`

```bash theme={null}
npx --yes @uselemma/setup@0.2.0 start \
  --harness claude-code \
  --project-name "Support bot" \
  --agent-name support-bot \
  --org acme-inc-x1y2
npx --yes @uselemma/setup@0.2.0 wait
```

Between the two, `start` keeps the approval in a file under `~/.lemma/setup/pending/` that only you can read, one per app directory. `wait` deletes it once the approval ends. The approval code expires 10 minutes after `start`. Both commands need Node.js 20 or later.

## Flags for start

The coding agent passes the names it inferred from the codebase. When the setup prompt names a project, it passes that project’s name instead, with its ID. On the approval page you confirm or edit the agent name and pick the project, new or existing:

| Flag | Required | Value |
| - | - | - |
| `--harness` | Yes | The coding agent: `claude-code`, `cursor`, `codex`, `opencode`, `pi`, `hermes`, `openclaw`, or `other` for any other agent |
| `--project-name` | Yes | The proposed project name, up to 200 characters |
| `--agent-name` | Yes | The proposed agent name, the root trace `name`. Lemma stores it in lowercase with dashes, for example `support-bot`. `trace` isn’t allowed |
| `--org` | No | The organization’s slug from the setup prompt, for example `acme-inc-x1y2`. The approval page selects that organization when you belong to it, and then offers no **Switch organization** link. To choose another organization, run `start` again without `--org` |
| `--project-id` | No | The ID of an existing project, from the setup prompt’s `Lemma project:` line. The approval page selects that project when your organization has it, and a new project otherwise. The command refuses a value that isn’t a UUID with exit code `2` before it sends a request |
| `--repository` | No | The repository, for example `acme/support-bot`. The command removes credentials from a URL before sending it |
| `--framework` | No | The agent framework, for example `vercel-ai` or `langgraph` |
| `--api-url` | No | The Lemma API. Defaults to `https://api.uselemma.ai`. The command accepts only HTTPS on `uselemma.ai` or a subdomain, or HTTP/HTTPS on `localhost`, `127.0.0.1` or `[::1]` on any port, and refuses any other URL with exit code `2` before it sends a request. For an API other than production, `wait` also writes `LEMMA_BASE_URL`, so the app sends traces to that API. `wait` uses the API `start` was given |
| `--no-browser` | No | Print the approval URL without opening a browser |

## Flags for wait

`wait` takes one flag:

| Flag | Required | Value |
| - | - | - |
| `--sign-in` | No | Run the coding agent’s sign-in command once setup writes the `lemma` server, even when `wait` doesn’t run in a terminal. Without the flag, `wait` runs the sign-in only in a terminal, and otherwise prints the command. The `lemma-setup` skill passes it on every `wait` |

## What one approval creates

An owner or admin of your Lemma organization approves the request on the page `start` opens, after choosing a plan if the organization has none. The approval creates the project, or uses an existing project you pick, and `wait` then receives one new key once: an **ingest key** limited to the project. It can only send traces, so a leaked copy can’t read your data or write to another project.

The key is named for the coding agent and the day, for example `Setup: Claude Code, Nov 18`. Find and revoke earlier ones under **Developer → API keys** in your organization settings. Setup creates no key for MCP: your coding agent signs in to the Lemma MCP server as you, so it can do what your role allows in the organization you choose.

## Files written to the app directory

`wait` writes two files in the directory it runs in. `start` checks both before the approval begins, and `wait` checks them again before it polls. Each says what it will skip or save elsewhere:

* **`.env`**: sets `LEMMA_API_KEY` and `LEMMA_PROJECT_ID`, and `LEMMA_BASE_URL` when `--api-url` names an API other than production. Both SDKs read `LEMMA_BASE_URL` when you don’t pass `baseUrl` / `base_url`. When Lemma keeps the key already in `.env`, `wait` still sets `LEMMA_BASE_URL`. A production setup removes a `LEMMA_BASE_URL` left in `.env`, so a production key never goes to another API. A new file is readable only by you. In an existing file, other lines, `export` prefixes, and the file’s permissions stay as they are; the command warns when the file’s group or other users can read it. Setup never writes through a symlinked `.env`, replaces one that isn’t a regular file, or writes one that git tracks: `start` and `wait` say so, and `wait` saves the values to a file in `~/.lemma/setup/` that only you can read
* **`.env.example`**: adds empty `LEMMA_API_KEY=` and `LEMMA_PROJECT_ID=` lines, plus `LEMMA_BASE_URL=` for an API other than production, and creates the file if it’s missing. A `.env.example` that is a symlink or isn’t a regular file stays unchanged, and `start` and `wait` say so. A failed write is reported and never fails setup

If git neither tracks nor ignores `.env`, the command prints a warning. Add `.env` to `.gitignore` before you commit. A `.env` that git already tracks stays in every commit whatever `.gitignore` says, so setup saves the values to the private file instead and tells you to add `.env` to `.gitignore` and run `git rm --cached .env`. Once you commit that, pulling the commit deletes `.env` from each teammate’s working copy. To keep `.env` tracked, copy the values into a gitignored file your app loads, such as `.env.local` for Next.js.

Untracking `.env` doesn’t remove a key already in git history. When the tracked `.env` holds a `LEMMA_API_KEY`, setup also tells you to revoke that key, in case it was pushed. Revoke it under **Developer → API keys** in your organization settings.

`start` and `wait` also warn when `.env.development.local`, `.env.local`, `.env.development`, or the environment they run in already sets a variable setup writes, even to an empty value, or a `LEMMA_BASE_URL` that a production setup removes. The app would use those values instead of the new ones:

* **A file**: in development, Next.js and Vite-based frameworks load these files ahead of `.env`, and wrangler loads `.env.local` ahead of it. Remove the variables from the file
* **The environment**: dotenv, `node --env-file`, python-dotenv, Next.js, and Vite keep a variable the environment already sets. Run the app without it, and remove the export where it’s set

The warning names the variables, never their values.

In a Cloudflare Workers app, one with `wrangler.json`, `wrangler.jsonc`, or `wrangler.toml` in the directory, `wrangler dev` reads `.dev.vars` when it exists, and the app’s `.env` files otherwise. So setup writes `.dev.vars` when it exists or the app has no `.env` file, and `.env` otherwise, which keeps the app’s `.env` files reaching the Worker. With `CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV=false`, set in the shell or the app’s `.env` or `.env.local`, wrangler loads no `.env` file into the Worker, so setup writes `.dev.vars`. `start` says which before the approval.

Not every app with a Wrangler config is a Worker: Next.js (including through OpenNext), SvelteKit, and Nuxt run their dev server in Node and load `.env` themselves, so setup keeps `.env` when one of their config files is beside a Wrangler config. Astro and React Router on Cloudflare run their dev server in the Workers runtime, so setup treats them as Workers.

When setup writes `.dev.vars`, what this page says about `.env` applies to `.dev.vars`, including a tracked file and the key to revoke. Unlike `.env`, a tracked `.dev.vars` can’t hand its values to a gitignored file, since `wrangler dev` loads no `.env` file into the Worker once `.dev.vars` exists: untrack it. Setup still adds the placeholders to `.env.example`.

For a Worker, `start` and `wait` check only what wrangler loads ahead of or in place of the file setup writes:

* **`.env.local`**: when setup writes `.env`, as in the list above
* **The environment**: when setup writes `.env` and either the Wrangler config declares `secrets` or the shell, the app’s `.env`, or its `.env.local` sets `CLOUDFLARE_INCLUDE_PROCESS_ENV=true`. Otherwise wrangler doesn’t pass the environment to the Worker
* **`.env.<environment>` and `.env.<environment>.local`**: when setup writes `.env`, for each environment the Wrangler config names. With `wrangler dev --env <environment>`, or `CLOUDFLARE_ENV=<environment>` with the Cloudflare Vite plugin, the dev server loads them ahead of `.env`
* **`.dev.vars.<environment>`**: wrangler loads it in place of the file setup writes for that environment, so `start` and `wait` warn whenever one exists and say to add the variables to it too

In a Pages project, `wrangler pages dev` takes no `--env`, so `start` and `wait` check neither `.env.<environment>` files nor `.dev.vars.<environment>`.

When a Worker’s Wrangler config declares `secrets`, `start` and `wait` warn to add the variables setup writes to `secrets.required`, since wrangler then loads them from the file only when `secrets.required` lists them.

With any Wrangler config, `wait` ends with an `npx wrangler secret put` command for each variable, in place of the line that says to add the variables to your deployment’s environment variables or secrets. For a Pages project it gives `npx wrangler pages secret put` instead, and says to redeploy, since Pages secrets reach only later deployments. When the config’s `vars` sets a variable setup writes, `start` and `wait` warn to remove it, and to redeploy first if your deployment has it, before you run the secret commands: wrangler refuses a secret whose name a var uses, and deploying the var deletes the secret. On a production setup, they also warn about `LEMMA_BASE_URL` under `vars`, which would send the Worker’s traces to another API.

Lemma returns the new key once, so `wait` never drops it. When `.env` can’t take the ingest key although neither `start` nor `wait` found anything wrong before polling, `wait` saves `LEMMA_API_KEY` and `LEMMA_PROJECT_ID`, with `LEMMA_BASE_URL` for an API other than production, to that private file, says where, finishes the other steps, and exits with `1`. Copy the values where the app loads its environment, then delete that file. When `wait` can’t set `LEMMA_BASE_URL` beside a key Lemma kept, or can’t remove a leftover one on a production setup, it says what to change by hand and exits with `1`.

When setup runs in a cloud sandbox or remote virtual machine, the key it saves exists only there and goes away with the environment. Setup recognizes these environments by the variable each one documents:

| Environment | Variable |
| - | - |
| Claude Code cloud session | `CLAUDE_CODE_REMOTE=true` |
| GitHub Codespaces | `CODESPACES=true` |
| GitHub Actions | `GITHUB_ACTIONS=true` |

In one of them, setup says so before the approval. Once it saves a new key, it prints a link to **Developer → API keys** in your organization settings. There, create an ingest key for the approved project to use in your deployment and on your own machine.

The `lemma-setup` skill has the coding agent tell you the same in a remote environment that sets none of these, such as Codex cloud or a Cursor cloud agent.

## Where the lemma server goes for each coding agent

`wait` adds a server named `lemma` to your coding agent’s user-level MCP config, pointing at `/mcp/` on the Lemma API (`https://api.uselemma.ai/mcp/` by default). The entry holds only the URL, with no key. Setup replaces a `lemma` entry that sends no key and leaves other servers and settings as they are:

| Coding agent | Where setup writes the `lemma` server | How to load it |
| - | - | - |
| Claude Code | `claude mcp add-json lemma '<entry>' --scope local`, run from the repository root, so the server stays in your Claude Code config for this project and out of the repository | `/mcp`, or restart |
| Cursor | `~/.cursor/mcp.json`, under `mcpServers` | Reload MCP servers in Settings |
| Codex | A `[mcp_servers.lemma]` table in `config.toml` under `CODEX_HOME` (default `~/.codex`) | Start a new session |
| OpenCode | `opencode.json` in `~/.config/opencode` (or `OPENCODE_CONFIG_DIR`), under `mcp.servers` when the file already uses it, otherwise under `mcp` | Restart OpenCode |
| Pi | `~/.pi/agent/mcp.json`, under `mcpServers` | `/reload` |
| Hermes | `config.yaml` under `HERMES_HOME` (default `~/.hermes`), under `mcp_servers`, with `auth: oauth`. Comments stay as they are | `/reload-mcp` |
| OpenClaw | `~/.openclaw/openclaw.json` (or `OPENCLAW_CONFIG_PATH`), under `mcp.servers` with the `streamable-http` transport and `"auth": "oauth"` | The gateway applies it; restart it if the tools don’t appear |
| Any other agent | Nothing: `wait` prints the entry for you to add to your agent’s MCP config | Your agent’s own step |

A new config file is readable only by you, since agents keep other servers’ keys there. Setup never changes an existing config’s permissions.

When a config is a symlink, has contents setup can’t edit safely (for example a JSON5 file with comments, or a Codex `lemma` server written inline instead of as a `[mcp_servers.lemma]` table), or the `claude` command isn’t on your `PATH`, `start` says why and that setup will print the server instead. `wait` says so too before it polls, including for a config that changed after `start`, then prints the entry in the agent’s own config format and exits with `0`.

When an MCP write fails after approval instead (for example the config’s directory isn’t writable, or Claude Code refuses the new server), `wait` prints the entry the same way and exits with `1`. Either way, add the entry yourself, then sign in.

For Claude Code, `start` reads the project’s local `lemma` entry. Without one, `wait` adds the server once, and removes nothing if Claude Code refuses. With one that sends no key, `wait` removes it and adds the new server; if that add fails, it restores the old entry.

When `wait` prints Claude Code’s server instead, it prints the same `claude mcp add-json` command, run from the repository root. When the project had a local `lemma` entry that sends no key, the command runs `claude mcp remove lemma --scope local` first and ignores a removal that finds nothing. It also prints the entry to set as `projects["<repository root>"].mcpServers.lemma` in `~/.claude.json` (or `.claude.json` in `CLAUDE_CONFIG_DIR`) with Claude Code closed. Never add it to the committed `.mcp.json`.

## How the coding agent signs in

Once the `lemma` server is in place, the coding agent signs in to Lemma with OAuth: Lemma opens in your browser, you choose the organization and allow the connection, and the agent then acts as you. `wait` runs the agent’s sign-in command when it runs in a terminal, or with `--sign-in`, which the `lemma-setup` skill always passes. Otherwise it prints the command, with the step inside the agent where there is one:

| Coding agent | Sign-in command | Inside the agent |
| - | - | - |
| Claude Code | `claude mcp login lemma` | `/mcp`, select `lemma`, and authenticate |
| Cursor | `agent mcp login lemma` (the Cursor CLI) | Sign in to `lemma` from Cursor’s MCP settings |
| Codex | `codex mcp login lemma` | None |
| OpenCode | `opencode mcp auth lemma` | `/mcps`, select `lemma`, and sign in |
| Pi | `pi mcp login lemma` | `/mcp`, select `lemma`, and choose **Sign in** |
| Hermes | `hermes mcp login lemma` | None |
| OpenClaw | `openclaw mcp login lemma` | None |
| Any other agent | None | Your agent’s sign-in for an MCP server that uses OAuth |

Setup prints each command with the directory to run it from: the repository root for Claude Code, whose local scope holds the server, and the app’s directory for the others. A sign-in that doesn’t finish leaves the server in place, and `wait` prints how to sign in later; it doesn’t change the exit code. [What a signed-in agent can do](https://docs.uselemma.ai/connections/mcp.md#what-a-signed-in-agent-can-do) covers the organization, role, and when access ends.

## When an existing key or server is kept

A re-run keeps an ingest key only when Lemma confirms what it’s allowed to do, and keeps an MCP server that already sends a key:

* **Ingest key in `.env`**: `start` asks Lemma’s `GET /auth/key` about it before the approval begins. It’s kept when Lemma confirms an `ingest` key limited to the project in `LEMMA_PROJECT_ID`, and you approve that same project. Any other key, including a read or admin key for that project, gets a new ingest key, and `wait` replaces both values in `.env`. For an API other than production, `wait` also sets `LEMMA_BASE_URL`, beside a kept key too. A key Lemma rejects, or an answer that doesn’t arrive, counts as unconfirmed. Setup doesn’t check a key in a `.env` it won’t write (a symlink, not a regular file, or tracked by git), so the approval always creates a new one
* **`lemma` server that sends an API key**: kept as it is, since API keys keep working for MCP. That covers a literal key or a reference such as an environment variable, in an `Authorization` header, in Claude Code’s `headersHelper`, or in Codex’s `bearer_token_env_var` or `env_http_headers`. `start` and `wait` say so, and `wait` skips the sign-in. To sign in as yourself instead, remove that server and run setup again

## Exit codes

The `lemma-setup` skill uses the exit code to decide the next step:

| Code | Command | Meaning |
| - | - | - |
| `0` | `start`, `wait` | `start`: the approval started. `wait`: approved; the ingest key is written, kept, or saved to a private file, and the `lemma` server is written, kept, or printed for you to add, as `start`, or `wait` before it polled, announced. The output names any private file, includes `Project ID:` and `Agent name:`, and says how the agent signs in, unless setup kept a `lemma` server that sends an API key |
| `5` | `wait` | The approval is still pending. Run `wait` again, with the same flags |
| `1` | `start`, `wait` | Setup failed. The message says why, for example no pending setup in this directory, or no coding-agent setup on this Lemma environment. After approval, `wait` also exits with `1` when the ingest key went to a private file because a write failed, no key was saved, the `lemma` server was printed because a write failed, or `LEMMA_BASE_URL` couldn’t be set or removed beside a kept key (the output says what to change); it finishes every other step first |
| `2` | `start`, `wait` | A command or flag is missing or invalid |
| `3` | `wait` | The approval code expired. Run `start` again |
| `4` | `wait` | The approver canceled, or is no longer an owner or admin. Run `start` again |

While a Lemma environment doesn’t offer coding-agent setup yet, its setup endpoints answer 404. `start` and `wait` then print one line saying so and exit with `1` without writing anything. Use [manual setup](https://docs.uselemma.ai/tracing/instrumentation/setup.md#set-up-manually) instead.

The commands never print a key or the device code. The approval code they print is the one the browser page shows, so you can match the two.

## The lemma-setup skill

The setup prompt in Lemma tells your coding agent to fetch and follow [`skills/lemma-setup/SKILL.md`](https://github.com/uselemma/lemma/blob/main/skills/lemma-setup/SKILL.md). The skill runs these steps in order:

1. Infer the project name, agent name, framework, and repository from the codebase, and read the organization slug from the prompt. When the prompt has a `Lemma project:` line, take the project name and ID from it, and when it has a `Lemma API:` line, take that URL
2. Ask the Approach question (which integration path) and the Scope question (which agent paths), before any code changes
3. Run `start`, show you the approval URL and code, then run `wait --sign-in` until it exits with `0`. `start` gets `--project-id` when the prompt names a project, and `--api-url` when it names a Lemma API
4. Instrument the agent with the `lemma-tracing` skill, using the approved agent name as the root trace `name`
5. Send a first trace, after you agree to run the agent, and check that the debug log reports the approved project’s ID and the Lemma API setup used
6. Make sure the agent is signed in to the Lemma MCP server. When setup writes the server, step 3’s `wait --sign-in` signs the agent in; if setup printed the server, or that sign-in didn’t finish, the agent asks you to sign in with the command or step `wait` printed. Then it loads the server and records the agent’s context with the `lemma-artifacts` skill
7. Report the files it changed and the build or deploy steps that need attention, such as adding both variables to your deployment’s secrets

## Related pages

> [card] [Send your first trace](https://docs.uselemma.ai/tracing/instrumentation/setup.md)
>
> Set up with the agent prompt or manually, then check the first trace.

> [card] [Lemma MCP server](https://docs.uselemma.ai/connections/mcp.md)
>
> The MCP endpoint, OAuth sign-in for people, and API keys for machines.


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