Command Palette

Search for a command to run...

Back to skills
skill № 61862

clerk-clock-skew-jwt

Use for Clerk JWT and session token clock-skew issues. PROACTIVELY activate for "token-not-active-yet", "JWT cannot be used prior to not before"…

FreeNo executable scripts
JosiahSiegelby JosiahSiegel★ 67 GitHub stars

Install clerk-clock-skew-jwt in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

Clerk JWT and Clock Skew

Overview

Clerk session tokens and custom JWT templates are signed JSON Web Tokens. The verifier always checks three time-based claims:

Claim Meaning Failure error
iat (issued at) When the token was minted (rare) invalid-iat or iat must be in the past
nbf (not before) Earliest moment the token is valid token-not-active-yet (Clerk error reason)
exp (expiration) Latest moment the token is valid token-expired (Clerk error reason)

Clock skew occurs when the verifier's wall clock is offset from the issuer's wall clock. If the verifier is behind, even freshly minted tokens fail nbf. If the verifier is ahead, long-lived tokens can fail exp early. Both directions break auth.

Clerk's own backend SDK applies a small tolerance (clockSkewInMs default 5000 ms) and the Dashboard exposes a session-level "Allowed Clock Skew" / nbf offset setting for JWT templates. Third-party libraries used to verify Clerk-issued JWTs have their own leeway settings; the safe defaults differ by library.

Time Claims in Clerk Tokens

A decoded Clerk session token typically contains numeric epoch-second values for iat, nbf, and exp. Decode the JWT (without verification) at a tool like jwt.io to inspect them when diagnosing failures.

The verifier must check nbf <= now + leeway and exp >= now - leeway. A token that is "active" must satisfy both bounds. If nbf > now even by one second, the token is rejected with token-not-active-yet. If exp < now, the token is rejected with token-expired.

iat is informational; most libraries do not require it. Clerk's tokens do include iat, and some libraries (for example golang-jwt/jwt v5) require WithIssuedAt() to enable iat validation.

Clerk SDK Clock Skew Configuration

Clerk's verifyToken() (in @clerk/backend, @clerk/nextjs/server, and equivalent) accepts a clockSkewInMs option. Documented default: 5000 (5 seconds). The same option is exposed to authenticateRequest for HTTP requests.

Conceptual shape (Node, TypeScript):

import { verifyToken } from '@clerk/backend'

const payload = await verifyToken(token, {
  secretKey: process.env.CLERK_SECRET_KEY!,
  clockSkewInMs: 5000,        // 5s tolerance for nbf/exp
  audience: 'my-api',
  authorizedParties: ['https://app.example.com'],
})

The Clerk Dashboard also exposes a session-token "Allowed Clock Skew" / nbf offset. Treat the Dashboard setting as the user-facing knob; treat clockSkewInMs in code as the same concept. Do not stack them to a large effective tolerance.

Why Clock Skew Happens in Local Dev

Local development environments are the most common source of clock skew failures because clocks are sometimes virtualized, suspended, or never NTP-synced.

Environment Typical cause Symptom
Bare-metal host NTP disabled, firewall blocks UDP 123 Host clock drifts seconds per day
WSL2 (Windows) Hyper-V time sync not exposed; hwclock diverges from Windows host Container time lags Windows time after sleep/resume
Docker Desktop (macOS/Windows) VM clock paused while laptop sleeps Containers wake with a stale clock
Linux container (Docker Engine) No NTP inside the container; bind-mounts host time as a path If host is wrong, container is wrong
Kubernetes pod Some runtime images lack chrony/systemd-timesyncd Drift after long-lived pods
CI runners (GitHub Actions, etc.) Ephemeral VMs with no synced clock between jobs iat may be milliseconds in the future
Serverless cold start (Lambda, Vercel, Cloudflare Workers) Provider clock can differ slightly from yours; GC pauses cause skew First request after cold start occasionally fails
Suspended/paused VM (VMware, VirtualBox, Hyper-V) Wall clock stops on suspend, may jump on resume Large skew after wake
Manual clock changes Admin sets time forward or backward Token issued at the new time is then re-verified against the old time

Clerk mints tokens on its own servers (so its clock is NTP-disciplined). The local server verifying them is the variable side. Fix the verifying side's clock first; only adjust leeway as a secondary control.

Fixing Container and Local Clocks

The remediation order matters. Always start with the clock; only add leeway after the clock is known-good.

Verify the skew first

Capture the host time and the in-container time:

# Host
date -u +%s
date -u --iso-8601=seconds

# Inside a container
docker exec <container> date -u +%s
docker exec <container> date -u --iso-8601=seconds

If they differ by more than a few seconds, the container is the source of the problem. The same script works for kubectl exec against a pod.

WSL2

WSL2 runs in a lightweight VM; its clock is independent of Windows unless explicitly synchronized. After the Windows host sleeps, WSL2 may resume with a stale clock.

# Inside WSL2
sudo hw
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the clerk-clock-skew-jwt skill do?

Use for Clerk JWT and session token clock-skew issues. PROACTIVELY activate for "token-not-active-yet", "JWT cannot be used prior to not before", token-expired, nbf/iat/exp claim failures, clockSkewInMs in verifyToken/authenticateRequest, local dev container/WSL2/Docker Desktop time drift, NTP misconfiguration, paused VM clock, serverless cold-start clock issues, custom JWT template verification leeway across Node/Python/Go/Ruby/Java/.NET/PHP, debugging iat vs server-time delta, and separating real expiry from clock skew. Provides nbf/iat/exp semantics, Clerk and library clock-tolerance defaults, container time fix recipes, multi-language leeway patterns, diagnostics, and gotchas.

How do I install the clerk-clock-skew-jwt skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the clerk-clock-skew-jwt skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare clerk-clock-skew-jwt with