Skip to main content

Accountless setup for Clerk in Next.js

Category
Company
Published

One command provisions a claimable Clerk app and writes your development keys. No need to stop and create an account.

Accountless setup for Clerk, showing development keys configured with no account required

Agents stall on account creation. Asking you for permission to create an account for a service slows you and your agent down. That's why we made Clerk setup accountless: you can build without signing up, logging in, or creating an app in the Dashboard.

The blocker is API keys. Every app needs them, and until now that meant a person creating an account and copying and pasting keys by hand. Starting in @clerk/nextjs 7.8.0, an app without Clerk keys throws an error that tells you and your agent to run npx clerk@latest init. That command writes the keys without a signup or a login, so the agent keeps going. If it handles setup end to end, you may never see the error.

Let's show you how it works.

The error is the onboarding

The error itself is deliberate. We wrote it for both humans and agents: plain instruction, no jargon, and the exact commands to run.

The error @clerk/nextjs 7.9.6 and later shows in local development when Clerk keys are missing from your environment

When you or your agent hit it, the next step is in the message: npx clerk@latest init.

One command, no account

npx clerk@latest init detects your framework, installs the SDK, scaffolds the integration, and writes your keys in one command. Run it while signed out and it creates an accountless application. It's a real Clerk app with development keys, not attached to any account yet.

While signed out, every agent run on a supported framework is accountless. In a terminal, new projects are accountless, and an existing project opens the interactive login instead. Pass --accountless to force it, including while signed in, or --login to force the authenticated flow.

If you already have a Clerk app, link it instead. npx clerk@latest link opens an app picker, or takes --app <id> so an agent can run it, and npx clerk@latest env pull then writes that app's development keys. Once you claim an accountless app, its keys are also on the API keys page in the Clerk Dashboard.

How accountless works

Start to finish, a run looks like this.

  1. Run the command. In an agent environment the CLI detects the non-interactive context and runs end to end without prompting. Run it yourself on a new project and it confirms the framework, the package manager, and the project name, then previews the file changes before writing them.

    npx clerk@latest init
  2. Read what it wrote. <ClerkProvider> goes inside <body> in your root layout, and clerkMiddleware() is imported from @clerk/nextjs/server. If your project already has a middleware or proxy file, the CLI writes into that one; otherwise it names the file for your Next.js version (proxy.ts on 16 and later, middleware.ts on 15 and below, and proxy.ts when the version can't be determined). Where it finds existing non-Clerk middleware, it composes clerkMiddleware() with what's there rather than rewriting the file. One exception: a non-i18n middleware file that exports its own config matcher is marked SKIP in the preview, and you add clerkMiddleware() yourself.

  3. Start the dev server. The application runs against the development keys in .env.local. In server code, auth() and currentUser() are imported from @clerk/nextjs/server. Both are async.

  4. Check the setup. npx clerk@latest doctor inspects your CLI session, the linked application, and the project, and reports each failing check with a remedy where it has one. --fix offers to apply the remedies it can automate, which are signing in, linking the project, and running env pull, and reports the rest without offering to fix them. It is skipped entirely under --json or outside a TTY, which is why agents run npx clerk@latest doctor --json and read the remedy field instead.

Claim it and go to production

Keeping the app is two more steps.

  1. Claim the application. npx clerk@latest auth login signs you in and attaches the unclaimed application to your account. Unclaimed applications and development keys are not production-ready.

  2. Go to production. Run npx clerk@latest deploy yourself. It's an interactive wizard that creates the production instance and walks you through DNS records and OAuth providers, so an agent gets a read-only handoff from it, not a deploy. Then put the production keys where your deployment reads them. npx clerk@latest env pull --instance prod writes the production publishable key and secret key into the env file it detects, usually .env.development.local or .env.local, replacing the development values in place with no prompt and no backup. Pass --file with a path of your own to keep production keys out of the file your dev server reads.

Read the Clerk CLI docs for the full command reference.

Agent-first, human-ready

Our onboarding was built for a person who lands on the signup page and creates an application in the Dashboard. More of that work happens inside an agent session now. The entry point for getting started moved to the command line. Signing up still exists. It happens after your app is already running.

Point your agent at a Next.js project and tell it to add authentication.

Ready to get started?

Start building
Authors
Drew Sing
Devin Gould

Share this article

Share to socials: