clerk-nextjs-patterns

clerk-nextjs-patterns is a skill for Claude Code from sutchan/Agent-Skills-Hub. It costs 41 tokens per session (3,085 once invoked), scanned A, a copy of clerk-nextjs-patterns, MIT.

A collection of implementation patterns for adding Clerk authentication to Next.js applications. Clerk is a service that manages user accounts and login sessions.

In plain words
What is it for?
Use it for middleware, server-versus-client authentication, protected Server Actions, API-route access checks, and user-scoped caching.
Why use it?
It helps avoid mistakes when authentication code runs on the server or in the browser, protects server-side actions and API routes, and caches user-specific data safely.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it for middleware, server-versus-client authentication, protected Server Actions, API-route access checks, and user-scoped caching.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/sutchan/agent-skills-hub/clerk-nextjs-patterns
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.

Any agent
npx skills add sutchan/Agent-Skills-Hub --skill clerk-nextjs-patterns
Clone the repo
git clone --depth 1 https://github.com/sutchan/Agent-Skills-Hub

Made for: Claude Code.

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-nextjs-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/sutchan/agent-skills-hub/clerk-nextjs-patterns/github.svg)](https://agentmods.dev/skills/sutchan/agent-skills-hub/clerk-nextjs-patterns)
Your own site
<a href="https://agentmods.dev/skills/sutchan/agent-skills-hub/clerk-nextjs-patterns"><img src="https://agentmods.dev/badge/skills/sutchan/agent-skills-hub/clerk-nextjs-patterns/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-nextjs-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/sutchan/agent-skills-hub/clerk-nextjs-patterns"><img src="https://agentmods.dev/badge/skills/sutchan/agent-skills-hub/clerk-nextjs-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 41 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,085 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 88% copy Near-identical to another mod 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.00041 $0.03085
Opus 5.5 $0.00016 $0.01234
Sonnet 5.5 $0.00008 $0.00617
Haiku 4.5 $0.00004 $0.00309

Measured 25d ago against content hash 8129bb2fe27f, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

clerk-nextjs-patterns 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 25d ago.

The scan reads SKILL.md. This mod also ships 2 executable files (templates/nextjs-basic-auth/next.config.ts, templates/nextjs-basic-auth/proxy.ts), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

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.

Origin

This is a copy

88% identical to clerk-nextjs-patterns — 137 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

skills/clerk-nextjs-patterns/SKILL.md · 290 lines

How it starts

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

Next.js Patterns

Version: Check package.json for the SDK version — see clerk skill for the version table. Core 2 differences are noted inline with > **Core 2 ONLY (skip if current SDK):** callouts.

For basic setup, see clerk-setup skill.

Route protection: call await auth.protect() in each page, Route Handler, and Server Function. Keep clerkMiddleware() bare. createRouteMatcher is deprecated in @clerk/nextjs 7 and will be removed in the next major version. Don't add it. If a project already uses it, leave it working and point the user to the migration guide.

What Do You Need?

Task Reference
Server vs client auth (auth() vs hooks) references/server-vs-client.md
Protect routes (check in each page, handler, and Server Function) references/middleware-strategies.md
Protect Server Actions references/server-actions.md
API route auth (401 vs 403) references/api-routes.md
Cache auth data (user-scoped caching) references/caching-auth.md
Fix next build errors under Cache Components Cache Components

References

Reference Description
references/server-vs-client.md await auth() vs hooks
references/middleware-strategies.md auth.protect() in each resource, bare clerkMiddleware() in proxy.ts (Next.js <=15: middleware.ts)
references/server-actions.md Protect mutations
references/api-routes.md 401 vs 403
references/caching-auth.md User-scoped caching with 'use cache'

Mental Model

Server vs Client = different auth APIs:

  • Server: await auth() from @clerk/nextjs/server (async!)
  • Client: useAuth() hook from @clerk/nextjs (sync)

Never mix them. Server Components use server imports, Client Components use hooks.

Key properties from auth():

  • isAuthenticated — boolean, replaces the !!userId pattern
  • sessionStatus — 'active' | 'pending', for detecting incomplete session tasks
  • userId, orgId, orgSlug, has(), protect() — unchanged

Read the full file on GitHub · 290 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. 25d ago Changed · -1 lines · +41 tokens per session 8129bb2fe27f
  2. 26d ago Changed · +34 lines · -41 tokens per session 5c56348ba9c6
  3. 1mo ago Changed · +4 lines 77d897e3ee70
  4. 1mo ago Changed · +20 tokens per session 92b8935fe2f0
  5. 2mo ago Changed · -2 lines · -20 tokens per session 51a833e5f5ed
  6. 3mo ago First seen · 255 lines · 41 tokens per session scan A d8d1c45f42c1

Subscribe to this mod's changes

clerk-nextjs-patterns is a skill published in the GitHub repository sutchan/Agent-Skills-Hub (3 stars, last pushed 6d ago), licensed MIT. It adds 41 tokens to every session and 3,085 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 88% identical to clerk-nextjs-patterns, differing in 137 lines, and is treated as a copy.

Related

clerk-nextjs-patterns compared with skills from other repositories

clerk-nextjs-patterns next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
clerk-nextjs-patternssutchan/Agent-Skills-HubSkill36d agoMITA41Claude Code
frontend-best-practicesWade-DevCode/awesome-coding-skills-cnSkill75mo agoMITA29Claude Code, Codex
slide-authoringshennawardana23/skillmeSkill41mo agoApache-2.0A146Claude Code
afrexai-react-productionLeoYeAI/openclaw-master-skillsSkill2.2k8d agoMITA32Claude Code, Codex
remotion-best-practicesguanyang/open-agent-hubSkill1.0kyesterdayMITA116Claude Code
skill-index-updaterluongnv89/asmSkill976yesterdayMITB59Claude Code
react-native-expoWrongStack/WrongStackSkill444yesterdayMITA95Claude Code