What it does
Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook
Skills ZICQ category:Agent Workflows clerk-webhooks
Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook
Official URL:skills.sh
Intro in this page language first. The official description stays in its original wording; we do not rewrite SKILL.md.
Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook
Webhooks
Per Agent Skills progressive disclosure: name and description load at startup (~100 tokens); the full SKILL.md body loads when the skill activates; scripts/, references/, and assets/ load only as needed. This file's sections: Webhooks; When to Use Webhooks; Verify Every Webhook; Keep the Webhook Route Unprotected; Complete Webhook Handler (Next.js App Router); Full Example: Welcome Email (Resend) + Slack Notification on user.created. It includes spec-recommended sections: input/output examples.
File analysis: besides SKILL.md, the body references references/frameworks.md. Those resources load on demand.
WebhooksWhen to Use WebhooksVerify Every WebhookKeep the Webhook Route UnprotectedComplete Webhook Handler (Next.js App Router)Full Example: Welcome Email (Resend) + Slack Notification on user.createdFull Example: Organization Membership Sync to DatabaseOther FrameworksType Narrowing for `evt.data`Payload Field ReferenceUser events (`user.created`, `user.updated`, `user.deleted`)Organization events (`organization.created`, `organization.updated`, `organization.deleted`)
Compatibility:Requires CLERK_WEBHOOK_SIGNING_SECRET (svix signing secret from Clerk dashboard) · License:MIT · allowed-tools:WebFetch
Source category:skills.sh agent-skill
nameclerk-webhooksdescriptioncompatibilityallowed-toolsreferences/frameworks.mdThese paths are extracted from the text. Check the upstream package to verify the files exist.
Invocation syntax and available tools depend on your Agent client. Client integration guide ↗
Choose the target agent and installation scope, keep referenced package files, then verify the skill appears in the client's catalog.
This skill references supporting files. Retrieve the complete directory from the source; copying SKILL.md alone may leave missing dependencies.
Copy these instructions to a compatible agent and confirm the target directory matches your client.
Install the agent skill "clerk-webhooks" into my project. The full SKILL.md and official description are at https://zicq.com/en/skills/skl-fe21136ee27c215b-Clerk-Webhooks.html Save it as .cursor/skills/clerk-webhooks/SKILL.md or .claude/skills/clerk-webhooks/SKILL.md and keep the frontmatter name and description exactly as-is. This skill also ships scripts/, references/, or assets/ — fetch the whole folder from https://github.com/clerk/skills instead of creating only a SKILL.md.
Requires Node.js and npx. First inspect the repository's skill list to confirm the name.
npx skills add 'https://github.com/clerk/skills' --list
npx skills add 'https://github.com/clerk/skills' --skill 'clerk-webhooks'
The CLI lets you choose the agent interactively. The default scope is the project; use -g for user scope. Confirm package availability with the discovery command, then use npx skills list to inspect installed skills.
Hi ${name}, welcome to our app!
`, }) // Step 5: Post notification to Slack channel await fetch(process.env.SLACK_WEBHOOK_URL!, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: `New user signed up: ${name} (${email})`, }), }) } // Always return 200 to acknowledge receipt return new Response('OK', { status: 200 }) } ``` ## Full Example: Organization Membership Sync to Database ```typescript // app/api/webhooks/route.ts import { verifyWebhook } from '@clerk/nextjs/webhooks' import { NextRequest } from 'next/server' import { db } from '@/lib/db' // your database client export async function POST(req: NextRequest) { // ALWAYS verify signature - never skip, even for simple handlers let evt try { evt = await verifyWebhook(req) // uses CLERK_WEBHOOK_SIGNING_SECRET env var } catch (err) { console.error('Webhook verification failed:', err) return new Response('Verification failed', { status: 400 }) } if (evt.type === 'organization.created') { const { id, name } = evt.data await db.workspaces.create({ data: { orgId: id, name, createdAt: new Date() }, }) } if (evt.type === 'organizationMembership.created') { // Extract organization ID, user ID, and role from payload const { organization, public_user_data, role } = evt.data const orgId = organization.id const userId = public_user_data.user_id // Add to team_members table await db.team_members.create({ data: { orgId, userId, role }, }) // Create workspace record for new member await db.workspaces.create({ data: { orgId, userId, createdAt: new Date() }, }) } if (evt.type === 'organizationMembership.deleted') { // Extract organization ID and user ID from payload const { organization, public_user_data } = evt.data const orgId = organization.id const userId = public_user_data.user_id // Remove from team_members table await db.team_members.delete({ where: { orgId, userId }, }) // Remove workspace record await db.workspaces.deleteMany({ where: { orgId, userId }, }) } // Return 200 status on success return new Response('OK', { status: 200 }) } ``` ## Other Frameworks For Express, Astro, Fastify, Nuxt, React Router, and TanStack Start, use the framework-specific `verifyWebhook` adapter. Each Clerk SDK package ships its own (`@clerk/express/webhooks`, `@clerk/astro/webhooks`, `@clerk/fastify/webhooks`, etc.). See `references/frameworks.md` for full handler examples per framework. ## Type Narrowing for `evt.data` `verifyWebhook` returns `WebhookEvent`, a discriminated union of all event types. Narrow with `evt.type` to get type-safe access to `evt.data`: ```typescript const evt = await verifyWebhook(req) if (evt.type === 'user.created') { // evt.data is now UserJSON, autocompletes id, email_addresses, etc. console.log(evt.data.id) } ``` For manual typing of nested payloads, import the JSON types from your framework's webhook subpath: `DeletedObjectJSON`, `EmailJSON`, `OrganizationInvitationJSON`, `OrganizationJSON`, `OrganizationMembershipJSON`, `SessionJSON`, `SMSMessageJSON`, `UserJSON`. ## Payload Field Reference ### User events (`user.created`, `user.updated`, `user.deleted`) ```typescript const { id, // Clerk user ID email_addresses, // array; [0].email_address is primary email first_name, last_name, image_url, public_metadata, } = evt.data ``` ### Organization events (`organization.created`, `organization.updated`, `organization.deleted`) ```typescript const { id, // org ID name, // org name slug, } = evt.data ``` ### Organization Membership events (`organizationMembership.created`, `organizationMembership.updated`, `organizationMembership.deleted`) ```typescript const { organization, // { id, name, ... } public_user_data, // { user_id, first_name, last_name, ... } role, // e.g. 'org:admin', 'org:member' } = evt.data // Access: organization.id, public_user_data.user_id, role ``` ## Supported Events (Full Catalog) **User**: `user.created` `user.updated` `user.deleted` **Session**: `session.created` `session.ended` `session.removed` `session.revoked` **Organization**: `organization.created` `organization.updated` `organization.deleted` **Organization Membership**: `organizationMembership.created` `organizationMembership.updated` `organizationMembership.deleted` **Organization Domain**: `organizationDomain.created` `organizationDomain.updated` `organizationDomain.deleted` **Organization Invitation**: `organizationInvitation.accepted` `organizationInvitation.created` `organizationInvitation.revoked` **Communication**: `email.created` `sms.created` **Waitlist**: `waitlistEntry.created` `waitlistEntry.updated` **Permission**: `permission.created` `permission.updated` `permission.deleted` **Role**: `role.created` `role.updated` `role.deleted` **Subscription**: `subscription.created` `subscription.updated` `subscription.active` `subscription.pastDue` **Subscription Item**: `subscriptionItem.created` `subscriptionItem.active` `subscriptionItem.updated` `subscriptionItem.canceled` `subscriptionItem.upcoming` `subscriptionItem.ended` `subscriptionItem.abandoned` `subscriptionItem.incomplete` `subscriptionItem.pastDue` `subscriptionItem.freeTrialEnding` **Payment**: `paymentAttempt.created` `paymentAttempt.updated` ## Webhook Reliability **Retries**: Svix retries failed webhooks on a set schedule (see [Svix Retry Schedule](https://docs.svix.com/retries)). Return 2xx to succeed, 4xx/5xx to retry. Use the `svix-id` header as an idempotency key to deduplicate retried events. **Replay**: Failed webhooks can be replayed from Dashboard. ## Common Pitfalls | Symptom | Cause | Fix | |---------|-------|-----| | Verification fails (Next.js) | Wrong import or usage | Use `@clerk/nextjs/webhooks`, pass `req` directly | | Verification fails (Express) | Using `express.json()` | Use `express.raw({ type: 'application/json' })` for webhook route | | Route not found (404) | Wrong path | Use `/api/webhooks` or preserve existing path | | 401 or 404 on every delivery | `auth.protect()` covers the webhook route (in middleware or in the handler) | Remove that check; `verifyWebhook()` is the only check the route needs | | No data in DB | Async job pending | Wait/check logs | | Duplicate entries | Only handling `user.created` | Also handle `user.updated` | | Timeouts | Handler too slow | Queue async work, return 200 first | ## Testing & Deployment **Local**: Use the Clerk CLI's first-party tunnel — no auth or linked project needed: ```sh clerk webhooks listen --token "$(clerk webhooks token)" --forward-to http://localhost:3000/api/webhooks ``` Add the printed relay URL (`https://webhooks.clerk.com/in/c_.../`) as a webhook endpoint in the Dashboard — events don't flow until you do. `svix-*` headers are preserved, so `verifyWebhook()` works against that endpoint's signing secret as usual. Flags, offline signature checks (`clerk webhooks verify`), and agent-mode behavior are in the `clerk-cli` skill. Without the CLI, tunnel `localhost:3000` yourself (`ngrok`, `localtunnel`, `Cloudflare Tunnel`) and add the public URL to the Dashboard endpoint. **Production**: Update webhook endpoint URL to production domain. Copy `CLERK_WEBHOOK_SIGNING_SECRET` to production env vars. ## References | Reference | Description | |-----------|-------------| | `references/frameworks.md` | Webhook handler examples for Express, Astro, Fastify, Nuxt, React Router, TanStack Start | ## See Also - `clerk-cli` - `clerk webhooks listen`/`verify` for local webhook testing - `clerk-setup` - Initial Clerk install - `clerk-orgs` - Org membership events - `clerk-billing` - Subscription, subscription item, and payment attempt events - `clerk-backend-api` - Sync via direct API callsAgent Workflows
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that exte…
Agent Workflows
Use the ClawdHub CLI to search, install, update, and publish agent skills from clawdhub.com. Use when you need to fetch new skills on the fl…
Agent Workflows
Orchestrate multi-agent teams with defined roles, task lifecycles, handoff protocols, and review workflows. Use when: (1) Setting up a team …
Agent Workflows
Spec-first, TDD, subagent-driven software development workflow. Use when: (1) building any new feature or app — triggers brainstorm → plan →…