Based on Clerk's and Anthropic's official docs, checked
How to add Clerk authentication with Claude Code
Clerk scores 5/5 on our Claude Code fit scale: it ships an official plugin that bundles Clerk skills with the Clerk MCP server. Clerk handles sign-up, sign-in, sessions, and user management, so you do not have to build auth yourself. Its official Claude Code plugin bundles Clerk skills with the Clerk MCP server, so Claude can read the docs, create a Clerk application, and wire the SDK into your project while you watch. This guide takes you from installing the plugin to a working sign-in button, using only Clerk's and Anthropic's official instructions.
1. Install the official Clerk plugin
Clerk ships its own plugin marketplace on GitHub, clerk/skills. It bundles the Clerk skills with the Clerk MCP server, so one install gives Claude both the instructions and the live tools. Run these two commands inside a Claude Code session. The first adds Clerk's marketplace, the second installs the clerk plugin from it.
/plugin marketplace add clerk/skills /plugin install clerk@clerk-skillsIf you want the skills without the plugin, run
npx skills add clerk/skillsinstead. The plugin is the better pick for Claude Code, because it also connects the MCP server, which is what lets Claude work with your live Clerk account.Source: https://github.com/clerk/skills
2. Connect the Clerk MCP server and sign in
The plugin connects Claude Code to Clerk's remote MCP server at https://mcp.clerk.com/mcp. The server uses OAuth, so your AI client never handles your Clerk password. When it first connects, your browser opens and you sign in to Clerk, pick the workspace the agent may access, and review the requested permissions before you allow them.
The server then acts as you in that workspace, so it can only do what your workspace role allows. Check the connection with /mcp inside a Claude Code session. It lists your connected servers and their status, and it is where you complete sign-in for servers that use OAuth.
Source: https://clerk.com/docs/guides/ai/mcp/clerk-mcp-server
3. Run the Clerk CLI setup in your project
With the plugin installed, ask Claude to set up Clerk, or run the Clerk CLI yourself. The quickstart's setup command is
npx -y clerk@latest init. It detects your framework and package manager, provisions a claimable application, writes development keys to .env.local, and configures the SDK, provider, middleware, and auth routes.You do not need a Clerk account first. Signed out, init provisions a claimable application, and signing in later claims it. If you already have a Clerk application, sign in first with
npx -y clerk@latest auth login, list your applications, and pass the one you want with --app. Never paste keys into the chat: init writes them to .env.local for you.npx -y clerk@latest init4. Check the middleware file and the provider
Init creates the middleware file and wraps your app in the provider. The filename depends on your Next.js version: proxy.ts on Next.js 16 and later, middleware.ts on 15 and below. The contents are identical. The file exports clerkMiddleware() from @clerk/nextjs/server, with a matcher that skips Next.js internals and static files and always runs for API routes.
import { clerkMiddleware } from '@clerk/nextjs/server' export default clerkMiddleware() export const config = { matcher: [ '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', '/(api|trpc)(.*)', '/__clerk/(.*)', ], }In app/layout.tsx, <ClerkProvider> sits inside <body>, not wrapping <html>. Add the prebuilt buttons so sign-in is visible: <SignInButton> and <SignUpButton> when signed out, and <UserButton> when signed in, wrapped in <Show> inside <Suspense>. You do not write sign-in forms yourself. Clerk ships them.
5. Protect a route and read the signed-in user
By default, clerkMiddleware() protects nothing. Every route stays public until you protect it, so protect resources close to where they are used, not only in middleware. In a Server Component or Route Handler, call auth() from @clerk/nextjs/server and await it. It returns the userId and sessionId for the current request.
To block signed-out visitors, call await auth.protect(), which redirects a document request to sign-in. Use currentUser() only when you need the full user object, since it makes a network call to Clerk's API while auth() reads the session token. A simple protected page looks like this:
import { auth } from '@clerk/nextjs/server' export default async function DashboardPage() { const { userId } = await auth() if (!userId) { return <p>Sign in to see your dashboard.</p> } return <p>Welcome back.</p> }6. Verify with clerk doctor and a test sign-up
After init finishes, run the CLI's health check. It reports setup problems for you to fix before you change anything else.
npx -y clerk@latest doctor npm run devThen start your app and confirm the sign-in, sign-up, and signed-in user controls are visible. Test the full sign-in and sign-up flow. Sign up as your first test user in the nav: after signup succeeds and a profile icon appears, the setup works. If a "Configure your application" callout appears, click it and follow it.
What the Clerk MCP server can do for you
Once connected, the MCP server gives Claude account tools and SDK snippet tools. The account tools list, inspect, and create applications, list and create users, list Organizations and memberships, read and change instance configuration, and check the DNS records a domain needs. The snippet tools return ready-to-use code patterns for common Clerk features, or a bundle of snippets for a setup such as B2B SaaS or Organizations.
The server never returns your instances' secret keys, including when it creates an application or a production instance, and it redacts sensitive values when it reads instance configuration. To add your keys to a project, copy them from the API keys page in the Clerk Dashboard or run clerk env pull. Tools that make changes are marked as such, so your AI client can ask you before it runs them.
Keep your secret key off the client
Init writes two keys to .env.local: NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY. The publishable key is public by design, and the secret key is server-only. Never expose CLERK_SECRET_KEY in client code, and never put it in a variable with a NEXT_PUBLIC_ prefix. Use @clerk/nextjs for your app, not @clerk/clerk-react. And never commit .env.local to git: it holds real credentials, even in development.
Then just ask
With the plugin installed, you can hand the whole job to Claude in plain words. Try this prompt, and ask Claude to show you the plan before it changes files:
"Help me add Clerk authentication in this project. Follow the Clerk docs, keep secrets in environment variables, and show me the plan before changing files."
Next steps
How to add Stripe payments with Claude Code
How to add a Supabase database with Claude Code
How to set up Neon Postgres with Claude Code
How to deploy to Vercel with Claude Code
How to deploy to Railway with Claude Code
How to install Claude Code on macOS, Linux and Windows
Frequently asked questions
No. The Clerk CLI works signed out: npx -y clerk@latest init provisions a claimable application and writes development keys to .env.local, and signing in later claims it. Sign in first only when you want to use an existing Clerk application.
Sources
- https://clerk.com/docs/quickstarts/nextjs · checked 2026-11-15
- https://clerk.com/docs/guides/ai/mcp/clerk-mcp-server · checked 2026-11-15
- https://github.com/clerk/skills · checked 2026-11-15
- https://code.claude.com/docs/en/mcp · checked 2026-11-15
- https://code.claude.com/docs/en/discover-plugins · checked 2026-11-15