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, sostart 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:
startchecks every file it will write, starts the approval, prints the approval URL and a code, opens the browser, and returns at oncewaitchecks for the approval for up to 90s. While the approval is pending it exits with5; run it again. Once you approve, it writes the ingest key and the coding agent’slemmaserver, runs or prints the agent’s sign-in, and exits with0
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:Flags for wait
wait takes one flag:
What one approval creates
An owner or admin of your Lemma organization approves the request on the pagestart 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: setsLEMMA_API_KEYandLEMMA_PROJECT_ID, andLEMMA_BASE_URLwhen--api-urlnames an API other than production. Both SDKs readLEMMA_BASE_URLwhen you don’t passbaseUrl/base_url. When Lemma keeps the key already in.env,waitstill setsLEMMA_BASE_URL. A production setup removes aLEMMA_BASE_URLleft 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,exportprefixes, 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:startandwaitsay so, andwaitsaves the values to a file in~/.lemma/setup/that only you can read.env.example: adds emptyLEMMA_API_KEY=andLEMMA_PROJECT_ID=lines, plusLEMMA_BASE_URL=for an API other than production, and creates the file if it’s missing. A.env.examplethat is a symlink or isn’t a regular file stays unchanged, andstartandwaitsay so. A failed write is reported and never fails setup
.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.localahead 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
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
.envand either the Wrangler config declaressecretsor the shell, the app’s.env, or its.env.localsetsCLOUDFLARE_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. Withwrangler dev --env <environment>, orCLOUDFLARE_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, sostartandwaitwarn whenever one exists and say to add the variables to it too
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:
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:
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 thelemma 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:
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 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:startasks Lemma’sGET /auth/keyabout it before the approval begins. It’s kept when Lemma confirms aningestkey limited to the project inLEMMA_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, andwaitreplaces both values in.env. For an API other than production,waitalso setsLEMMA_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.envit won’t write (a symlink, not a regular file, or tracked by git), so the approval always creates a new one lemmaserver 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 anAuthorizationheader, in Claude Code’sheadersHelper, or in Codex’sbearer_token_env_varorenv_http_headers.startandwaitsay so, andwaitskips the sign-in. To sign in as yourself instead, remove that server and run setup again
Exit codes
Thelemma-setup skill uses the exit code to decide the next step:
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 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 followskills/lemma-setup/SKILL.md. The skill runs these steps in order:
- 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 aLemma API:line, take that URL - Ask the Approach question (which integration path) and the Scope question (which agent paths), before any code changes
- Run
start, show you the approval URL and code, then runwait --sign-inuntil it exits with0.startgets--project-idwhen the prompt names a project, and--api-urlwhen it names a Lemma API - Instrument the agent with the
lemma-tracingskill, using the approved agent name as the root tracename - 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
- Make sure the agent is signed in to the Lemma MCP server. When setup writes the server, step 3’s
wait --sign-insigns 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 stepwaitprinted. Then it loads the server and records the agent’s context with thelemma-artifactsskill - 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
Send your first trace
Set up with the agent prompt or manually, then check the first trace.
Lemma MCP server
The MCP endpoint, OAuth sign-in for people, and API keys for machines.