clerk

clerk is a cursor rule for Cursor from nedcodes-ok/cursorrules-collection. It costs 611 tokens per session, scanned A, original, MIT.

Rules for adding Clerk, a service that handles user sign-in, accounts, sessions, and organizations, to an application. They cover both browser-side and server-side authentication.

In plain words
What is it for?
Use it to configure sign-in and sign-up pages, protect routes, read the current user on the server, manage organizations, and connect authentication to API requests.
Why use it?
They help keep protected pages and APIs from trusting user data supplied by the browser. They also provide consistent patterns for middleware, routes, environment settings, and account management.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc). Also seen: mentions Cursor.

Good fit Use it to configure sign-in and sign-up pages, protect routes, read the current user on the server, manage organizations, and connect authentication to API requests.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/nedcodes-ok/cursorrules-collection/clerk
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collection

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for clerk

README.md
[![agentmods](https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/clerk/github.svg)](https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/clerk)
Your own site
<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/clerk"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/clerk/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for clerk

Your own site · 80×15
<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/clerk"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/clerk.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 611 This file is loaded in full into every session.
When invoked 611 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00611 $0.00611
Opus 5.5 $0.00244 $0.00244
Sonnet 5.5 $0.00122 $0.00122
Haiku 4.5 $0.00061 $0.00061

Measured 2mo ago against content hash 1f27e16be262, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

clerk scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules-mdc/tools/clerk.mdc · 56 lines

How it starts

The opening of the file, as written. The whole thing — 56 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Clerk Cursor Rules

You are an expert in Clerk authentication. Follow these rules:

Setup

  • Wrap the app with ClerkProvider at the root layout
  • Set publishableKey from env: NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
  • Configure sign-in/sign-up routes in env: NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
  • Use Clerk's pre-built components (, ) unless custom UI is required

Middleware

  • Use clerkMiddleware() in middleware.ts for all auth protection
  • Protect routes with createRouteMatcher: const isProtected = createRouteMatcher(['/dashboard(.*)'])
  • Call auth().protect() inside the middleware for protected routes
  • Public routes (marketing, auth pages) don't need explicit configuration — they're unprotected by default
  • Place middleware.ts at project root (or src/ if using src directory)

Server-Side Auth

  • Use auth() in server components and API routes to get { userId, sessionId, orgId }
  • Use currentUser() when you need the full user object (name, email, metadata)
  • Check auth().userId — it's null for unauthenticated requests
  • Never trust client-sent user IDs — always derive from auth() server-side

Client-Side Auth

  • Use useAuth() for { userId, isSignedIn, isLoaded } in client components
  • Use useUser() for full user object in client components
  • Always check isLoaded before rendering auth-dependent UI
  • Use and components for conditional rendering

User Management

  • Store Clerk userId as the foreign key in your database — not email
  • Sync user data via webhooks (user.created, user.updated) not on every request
  • Use publicMetadata for role/permissions (readable by client, writable only by backend)
  • Use privateMetadata for sensitive flags (server-only, never sent to client)
  • Use unsafeMetadata only for user-editable preferences

Organizations

  • Use useOrganization() for current org context
  • Check orgId in middleware for org-scoped routes
  • Use org roles for permission checks: auth().orgRole === 'admin'
  • Create org-scoped data by storing orgId alongside records

Read the full file on GitHub · 56 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 56 lines · 611 tokens per session scan A 1f27e16be262

Subscribe to this mod's changes

clerk is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (38 stars, last pushed 9mo ago), licensed MIT. It adds 611 tokens to every session, about $0.0024 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

clerk compared with cursor rules from other repositories

clerk next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
clerknedcodes-ok/cursorrules-collectionCursor rule389mo agoMITA611Cursor
expressnedcodes-ok/cursor-lint-rulesCursor rule19mo agononeA101Cursor
10-backend-fastapiaiagentwithdhruv/ai-dev-stackCursor rule115mo agoMITA0Cursor
23-app-startuporbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
29-screen-startuporbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
21-ads-billingorbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor
22-platform-firebaseorbitalsonic/AndroidPilotCursor rule11mo agononeA0Cursor