Agent skill

Clerk Performance Tuning

by jeremylongshore in jeremylongshore/tons-of-skills-marketplace

Optimize Clerk authentication performance. An agent skill from jeremylongshore/tons-of-skills-marketplace.

MITAuto-check passedBackend & APIs

Install Clerk Performance Tuning

skills CLI
$ npx skills add jeremylongshore/tons-of-skills-marketplace --skill clerk-performance-tuning -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install jeremylongshore/tons-of-skills-marketplace clerk-performance-tuning --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/jeremylongshore/tons-of-skills-marketplace.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/.curated/clerk-performance-tuning .claude/skills/clerk-performance-tuning && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
clerk-performance-tuning
GitHub stars
2.8k
Token cost
~1.7k tokens
SKILL.md length
209 words
Files
2 (incl. references)
Skills in repo
3,342
Repo updated
First seen
Licence
MIT

At a glance

Optimize Clerk authentication performance. An agent skill from jeremylongshore/tons-of-skills-marketplace.

  • Works in 6 steps: Optimize Middleware (Skip Static Assets) → Cache User Data → Optimize Token Handling → …
  • Improving auth response times
  • SKILL.md covers Overview, Prerequisites, Instructions and Output, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Clerk Performance Tuning is an agent skill from jeremylongshore/tons-of-skills-marketplace. Optimize Clerk authentication performance. Use when improving auth response times, reducing latency, or optimizing Clerk SDK usage. Trigger with phrases like "clerk performance", "clerk optimization", "clerk slow", "clerk latency", "optimize clerk".

Its SKILL.md is about 1.7k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files, including reference files (for example `references/implementation-guide.md`). Compatibility notes: Designed for Claude Code

It sits in Backend & APIs, covering Serverless. It works with Next.js. The repository describes itself as: Model-agnostic agent-skills platform with a harness-free canonical layer, verified adapters, and the ccpi package manager. Explore at tonsofskills.com. The licence is MIT.

When your agent uses it

  • Improving auth response times
  • Reducing latency
  • Optimizing Clerk SDK usage
  • With phrases like clerk performance

Example prompts

  • “clerk performance”
  • “clerk optimization”
  • “clerk slow”
  • “/clerk-performance-tuning”

Requirements

  • Node.js
  • Compatibility (from SKILL.md): Designed for Claude Code
  • Pre-approved tools (allowed-tools): Read, Write, Edit, Grep

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Optimize Middleware (Skip Static Assets)
  2. Cache User Data
  3. Optimize Token Handling
  4. Lazy Load Auth Components
  5. Optimize Server Components
  6. Edge Runtime for Middleware

What it can do on your machine

Read from SKILL.md and the folder at commit cfae287. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Grep

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • nextjs.org
    • clerk.com
    • vercel.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Designed for Claude Code

    From compatibility in the SKILL.md frontmatter.

Context cost

Clerk Performance Tuning loads about 1.7k tokens when it runs, and up to ~3.4k if it reads all its reference files. Until then it costs about 69 tokens; SKILL.md has 209 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~69
When it runs · the whole SKILL.md, loaded when a task matches
~1.7k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~3.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from jeremylongshore/tons-of-skills-marketplace at commit cfae287, republished under its MIT licence (© jeremylongshore). 209 words, ~1,680 tokens.

Download SKILL.mdSave it as .claude/skills/clerk-performance-tuning/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
clerk-performance-tuning
description
Optimize Clerk authentication performance. Use when improving auth response times, reducing latency, or optimizing Clerk SDK usage. Trigger with phrases like "clerk performance", "clerk optimization", "clerk slow", "clerk latency", "optimize clerk".
allowed-tools
Read, Write, Edit, Grep
compatibility
Designed for Claude Code
version
1.15.0
license
MIT
author
Jeremy Longshore <jeremy@intentsolutions.io>
tags
saas, clerk, performance, authentication

Clerk Performance Tuning

Overview

Optimize Clerk authentication for best performance. Covers middleware optimization, user data caching, token handling, lazy loading, and edge runtime configuration.

Prerequisites

  • Clerk integration working
  • Performance monitoring in place (Lighthouse, Web Vitals)
  • Understanding of Next.js rendering strategies

Instructions

Step 1: Optimize Middleware (Skip Static Assets)
typescript
// middleware.ts — avoid running auth on static files
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

const isPublicRoute = createRouteMatcher(['/', '/sign-in(.*)', '/sign-up(.*)', '/api/webhooks(.*)'])

export default clerkMiddleware(async (auth, req) => {
  if (!isPublicRoute(req)) {
    await auth.protect()
  }
})

// Restrict matcher to avoid processing static assets
export const config = {
  matcher: [
    // Skip _next, static files, and images
    '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico)).*)',
    '/(api|trpc)(.*)',
  ],
}
Step 2: Cache User Data
typescript
// lib/cached-user.ts
import { auth, currentUser } from '@clerk/nextjs/server'
import { cache } from 'react'

// React cache: deduplicates within a single request
export const getAuthUser = cache(async () => {
  const { userId } = await auth()
  if (!userId) return null
  return currentUser()
})

// Usage in multiple server components (only one Clerk API call per request):
// const user = await getAuthUser()

For cross-request caching with unstable_cache:

typescript
import { unstable_cache } from 'next/cache'
import { clerkClient } from '@clerk/nextjs/server'

export const getCachedUserProfile = unstable_cache(
  async (userId: string) => {
    const client = await clerkClient()
    const user = await client.users.getUser(userId)
    return {
      id: user.id,
      name: `${user.firstName} ${user.lastName}`,
      email: user.emailAddresses[0]?.emailAddress,
      imageUrl: user.imageUrl,
    }
  },
  ['user-profile'],
  { revalidate: 300 } // Cache for 5 minutes
)
Step 3: Optimize Token Handling
typescript
// lib/token-cache.ts
let tokenCache: { token: string; expiresAt: number } | null = null

export async function getOptimizedToken(getToken: () => Promise<string | null>) {
  // Reuse token if it has more than 30 seconds remaining
  if (tokenCache && tokenCache.expiresAt > Date.now() + 30_000) {
    return tokenCache.token
  }

  const token = await getToken()
  if (token) {
    const payload = JSON.parse(atob(token.split('.')[1]))
    tokenCache = { token, expiresAt: payload.exp * 1000 }
  }

  return token
}
Step 4: Lazy Load Auth Components
typescript
// components/lazy-auth.tsx
'use client'
import dynamic from 'next/dynamic'

// Only load UserButton when needed (saves ~15KB)
const UserButton = dynamic(
  () => import('@clerk/nextjs').then((mod) => mod.UserButton),
  { ssr: false, loading: () => <div className="w-8 h-8 rounded-full bg-gray-200 animate-pulse" /> }
)

const SignInButton = dynamic(
  () => import('@clerk/nextjs').then((mod) => mod.SignInButton),
  { ssr: false }
)

export { UserButton, SignInButton }
Step 5: Optimize Server Components
typescript
// app/dashboard/page.tsx — parallel data fetching
import { auth } from '@clerk/nextjs/server'
import { Suspense } from 'react'

export default async function Dashboard() {
  const { userId } = await auth()
  if (!userId) return null

  return (
    <div>
      {/* Parallel loading with Suspense boundaries */}
      <Suspense fallback={<div>Loading profile...</div>}>
        <UserProfile userId={userId} />
      </Suspense>
      <Suspense fallback={<div>Loading activity...</div>}>
        <RecentActivity userId={userId} />
      </Suspense>
    </div>
  )
}

async function UserProfile({ userId }: { userId: string }) {
  const profile = await getCachedUserProfile(userId)
  return <div>{profile.name}</div>
}

async function RecentActivity({ userId }: { userId: string }) {
  const activity = await db.activity.findMany({ where: { userId }, take: 10 })
  return <ul>{activity.map((a) => <li key={a.id}>{a.description}</li>)}</ul>
}
Step 6: Edge Runtime for Middleware
typescript
// middleware.ts — runs on Vercel Edge (cold start <50ms vs ~250ms Node)
import { clerkMiddleware } from '@clerk/nextjs/server'

export default clerkMiddleware()

// Clerk middleware is Edge-compatible by default on Vercel
export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
  runtime: 'edge', // Explicitly opt into Edge Runtime
}

Output

  • Middleware skipping static assets (fewer auth checks)
  • React cache() deduplicating user fetches within requests
  • Cross-request user profile caching (5-minute TTL)
  • Lazy-loaded auth components reducing bundle size
  • Parallel Suspense boundaries for dashboard rendering
  • Edge Runtime middleware for faster cold starts

Error Handling

IssueCauseSolution
Slow initial page loadBlocking auth callsUse Suspense boundaries for parallel loading
High Clerk API latencyNo cachingUse cache() and unstable_cache()
Large JS bundleAll Clerk components loadedUse dynamic() imports for auth UI components
Slow middleware cold startNode.js runtimeSwitch to Edge Runtime on Vercel
Stale cached user dataCache not invalidatedInvalidate on user.updated webhook

Examples

Measure Clerk Auth Overhead
typescript
// lib/perf-measure.ts
export async function measureAuthTime() {
  const start = performance.now()
  const { userId } = await auth()
  const authMs = performance.now() - start
  console.log(`[Perf] auth() took ${authMs.toFixed(1)}ms, userId: ${userId}`)
  return { userId, authMs }
}

Resources

Next Steps

Proceed to clerk-cost-tuning for cost optimization strategies.

© jeremylongshore, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file (references) in skills/.curated/clerk-performance-tuning of jeremylongshore/tons-of-skills-marketplace.

  • SKILL.md
  • references/implementation-guide.md

Open the folder on GitHubat commit cfae287

Compare with similar skills

Clerk Performance Tuning next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Clerk Performance Tuning compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Clerk Performance Tuning this skilljeremylongshore/tons-of-skills-marketplace2.8k—~1.7kAutomated safety check: PassMIT
Qstash JSupstash/qstash-js269—~746Automated safety check: PassMIT
Nextjs Ssrasmyshlyaev177/test-proxy-recorder78—~4.5kAutomated safety check: PassMIT
Edgeone Pages Website SkeletonTencentEdgeOne/awesome-website-prompts-and-skills185—~2.2kAutomated safety check: NotesMIT
Deploy Verceljohnku2011/boilerplates-with-ai-skills240—~660Automated safety check: NotesMIT
Inngestpedronauck/skills6344 repos~3.1kAutomated safety check: PassNone

Similar skills

  • Qstash JS

    upstash/qstash-js

    Official

    Work with the QStash JavaScript/TypeScript SDK for serverless messaging, scheduling.

    269 GitHub stars~746 tokensUpdated 5 days ago
    Backend & APIsAuto-check passed
  • Nextjs Ssr

    asmyshlyaev177/test-proxy-recorder

    Tag server-side fetches with the x-test-rcrd-id session header so SSR is recorded under the correct Playwright test session.

    78 GitHub stars~4.5k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Edgeone Pages Website Skeleton

    TencentEdgeOne/awesome-website-prompts-and-skills

    基于 EdgeOne Pages 的全栈网站生成方案。用户说一句话(如「帮我建一个电商站」「做一个AI客服站」「做个管理后台」),AI 自动组合 Auth、Cart、Payment、AI Chat、Admin 五大模块,生成完整 Next.js 前后端代码并部署到 EdgeOne Pages 全球 CDN。支持电商、AI 助手、SaaS 管理后台三大模板。底层使用 Edge…

    185 GitHub stars~2.2k tokensUpdated 4 mo ago
    Backend & APIsAuto-check: notes
  • Deploy Vercel

    johnku2011/boilerplates-with-ai-skills

    A skill your agent uses when deploying or configuring this project on Vercel — env vars, build settings, serverless limits, and production checks for Next.js or Express.

    240 GitHub stars~660 tokensUpdated 1 mo ago
    Backend & APIsAuto-check: notes
  • Inngest

    pedronauck/skills

    Inngest expert for serverless-first background jobs, event-driven workflows, and durable execution without managing queues or workers.

    634 GitHub starsUsed in 4 repos~3.1k tokens
    Backend & APIsAuto-check passed
  • Upstash Redis

    github/awesome-copilot

    Official

    Use Redis over HTTP from serverless and edge runtimes with @upstash/redis, and add rate limiting with @upstash/ratelimit.

    40k GitHub stars~1.7k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed

More from jeremylongshore/tons-of-skills-marketplace

All 3,342 skills in this repo
  • Performing Security Code Review

    jeremylongshore/tons-of-skills-marketplace

    Execute this skill enables AI assistant to conduct a security-focused code review using the security-agent plugin.

    2.8k GitHub starsUsed in 2 repos~1.3k tokens
    Auto-check: notes
  • Adapting Transfer Learning Models

    jeremylongshore/tons-of-skills-marketplace

    Build this skill automates the adaptation of pre-trained machine learning models using transfer learning techniques.

    2.8k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Agent Context Loader

    jeremylongshore/tons-of-skills-marketplace

    Execute proactive auto-loading: automatically detects and loads agents.md files.

    2.8k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Aggregating Performance Metrics

    jeremylongshore/tons-of-skills-marketplace

    Aggregate and centralize performance metrics from applications, systems, databases, caches, and services.

    2.8k GitHub stars~1.2k tokensUpdated today
    Auto-check passed
  • Analyzing Capacity Planning

    jeremylongshore/tons-of-skills-marketplace

    Execute this skill enables AI assistant to analyze capacity requirements and plan for future growth.

    2.8k GitHub stars~947 tokensUpdated today
    Auto-check passed
  • Analyzing Database Indexes

    jeremylongshore/tons-of-skills-marketplace

    Process use when you need to work with database indexing. An agent skill from jeremylongshore/tons-of-skills-marketplace.

    2.8k GitHub stars~2k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Clerk Performance Tuning

What does Clerk Performance Tuning do?

Optimize Clerk authentication performance. An agent skill from jeremylongshore/tons-of-skills-marketplace. Clerk Performance Tuning is an agent skill from jeremylongshore/tons-of-skills-marketplace. Optimize Clerk authentication performance.

When should I use Clerk Performance Tuning?

Clerk Performance Tuning fits situations like: improving auth response times; reducing latency; optimizing Clerk SDK usage; with phrases like clerk performance.

How do I install Clerk Performance Tuning in Claude Code?

Run `npx skills add jeremylongshore/tons-of-skills-marketplace --skill clerk-performance-tuning -a claude-code`. Or copy the skill folder (skills/.curated/clerk-performance-tuning in jeremylongshore/tons-of-skills-marketplace) into .claude/skills/clerk-performance-tuning in your project. Claude Code loads it when a task matches its description.

How do I install Clerk Performance Tuning in Codex?

Run `npx skills add jeremylongshore/tons-of-skills-marketplace --skill clerk-performance-tuning -a codex`. Or copy the skill folder (skills/.curated/clerk-performance-tuning in jeremylongshore/tons-of-skills-marketplace) into .agents/skills/clerk-performance-tuning in your project. Codex loads it when a task matches its description.

Can I use Clerk Performance Tuning in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add jeremylongshore/tons-of-skills-marketplace --skill clerk-performance-tuning -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/clerk-performance-tuning, .gemini/skills/clerk-performance-tuning, .github/skills/clerk-performance-tuning and .opencode/skills/clerk-performance-tuning in your project.

What does Clerk Performance Tuning need to run?

SKILL.md names no scripts, command-line tools or credentials: Clerk Performance Tuning is instructions for the agent only. Our summary lists: Node.js. Its frontmatter pre-approves these tools: Read, Write, Edit, Grep. Compatibility (from SKILL.md): Designed for Claude Code.

Does Clerk Performance Tuning access the network?

SKILL.md names 3 domains. As links in the text: nextjs.org, clerk.com and vercel.com. This is read from the text; nothing was executed.

Is Clerk Performance Tuning safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Clerk Performance Tuning use?

Clerk Performance Tuning is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Clerk Performance Tuning use?

About 1.7k tokens (SKILL.md is roughly 6.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.7k tokens, read only when the agent opens those files.

What are the alternatives to Clerk Performance Tuning?

Skills that share tags, products or a category with Clerk Performance Tuning: Qstash JS (upstash/qstash-js, 269 stars), Nextjs Ssr (asmyshlyaev177/test-proxy-recorder, 78 stars), Edgeone Pages Website Skeleton (TencentEdgeOne/awesome-website-prompts-and-skills, 185 stars) and Deploy Vercel (johnku2011/boilerplates-with-ai-skills, 240 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Clerk Performance Tuning?

jeremylongshore (a GitHub user) maintains it in jeremylongshore/tons-of-skills-marketplace, which has 2,827 GitHub stars. The repository holds 3,342 skills in this directory. The repository was last updated on October 10, 2026.

Source: jeremylongshore/tons-of-skills-marketplace on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.