Claude-skill-registry clerk-token-ops
Automates Clerk JWT token generation, validation, and export for FastAPI integration tests. Use when an agent must refresh tokens, verify JWT templates, or unblock authentication workflows without breaking environment state.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/clerk-token-ops" ~/.claude/skills/majiayu000-claude-skill-registry-clerk-token-ops && rm -rf "$T"
manifest:
skills/data/clerk-token-ops/SKILL.mdsource content
Clerk Token Operations
Overview
This skill gives Claude Code agents a repeatable, zero-surprise playbook for generating Clerk JWTs, exporting them into the Windows PowerShell environment, and validating authentication against the FastAPI backend. It encodes the exact fixes from the November 2025 incidents (missing templates, parser errors, stale tokens) so future runs avoid the same failures.
Activation Signals
Use this skill whenever the task involves:
- Minting or refreshing Clerk JWTs for integration, smoke, or load tests.
- Investigating 401 responses due to expired or malformed tokens.
- Ensuring
and PowerShell sessions stay in sync (.env.local
,CLERK_SECRET_KEY
).CLERK_TOKEN - Listing or validating Clerk JWT templates (e.g.,
).server-token - Teaching another agent how to run
orscripts/get_clerk_token.py
safely.Set-ClerkToken.ps1
Guardrails (Do This Before Anything Else)
- Never copy Markdown links into the terminal. Always use raw paths like
.scripts/Set-ClerkToken.ps1 - Use real Clerk user IDs (e.g.,
). Angle brackets or placeholders break PowerShell parsing.user_35KgiAcvIC0tdtFvJUN1vDkrNYc - Confirm
exists and contains.env.local
,CLERK_SECRET_KEY
,CLERK_ISSUER
, andCLERK_PEM_PUBLIC_KEY
.CLERK_ISSUER_ID - Restart FastAPI after changing
; environment variables load only once per process..env.local - Tokens expire in ~60 seconds. Chain generation and testing without delay.
Core Workflow
- Validate Environment
- Run
and open the file if missing keys.Test-Path .env.local - Ensure
stays commented out; session tokens lackCLERK_JWT_AUDIENCE
.aud
- Run
- Inspect Available JWT Templates
powershell -File .\scripts\Set-ClerkToken.ps1 -ListTemplates- Confirm
exists; if missing, create it in the Clerk dashboard with RS256 signing.server-token
- Generate & Export Token
powershell -File .\scripts\Set-ClerkToken.ps1 -UserId <ACTUAL_USER_ID> -Template server-token [-Persist]- Expect: "CLERK_TOKEN exported..." and optional persistence notice.
- Verify Token Availability
echo $env:CLERK_TOKEN- Optional:
for debugging.python scripts/get_clerk_token.py --env-file .env.local --user-id ... --template server-token --print-session
- Run Target Tests or API Calls Immediately
- Example test harness:
uv run python main/scripts/test_clerk_auth.py "$env:CLERK_TOKEN" fixtures/test_urs.txt - For curl:
curl -H "Authorization: Bearer $env:CLERK_TOKEN" http://localhost:8000/jobs -d @payload.json -H "Content-Type: application/json"
- Example test harness:
- Audit & Log Verification
- Tail
to ensure thelogs/audit/jobs/audit_*.jsonl
(user ID) andsub
fields are captured (ALCOA+ compliance).token_iat
- Tail
Quality Checklist
-
contains correct Clerk keys and issuer URLs..env.local -
runs without HTTP errors and prints JWT.scripts/get_clerk_token.py -
outputs success messages (noscripts/Set-ClerkToken.ps1
errors).[System.Char] -
is non-empty and recent ($env:CLERK_TOKEN
within 60 seconds).token_iat - FastAPI endpoint returns 201/200 with token, 401 without token (negative test).
- Audit log entry includes
from JWTuser_id
claim.sub
Troubleshooting Matrix
| Symptom | Root Cause | Fix |
|---|---|---|
| PowerShell treated helper output as char array | Use the patched (Nov 2025). If issue recurs, wrap extraction with and ensure token line exists. |
| Helper didnt emit token (HTTP error, wrong template, or env vars missing) | Re-run helper with and check secrets; confirm template name matches exactly. |
| Audience verification enabled | Comment out and ensure JWT decode options set . |
| Delay between generation and use | Regenerate token and chain tests immediately (<60s). Automate generation/test pipeline if needed. |
| FastAPI didnt load | Load dotenv at the top of before other imports; restart server. |
Example Session (Copy/Paste Ready)
# 1. List templates (sanity check) powershell -File .\scripts\Set-ClerkToken.ps1 -ListTemplates # 2. Export fresh token for known test user powershell -File .\scripts\Set-ClerkToken.ps1 -UserId user_35KgiAcvIC0tdtFvJUN1vDkrNYc -Template server-token -Persist # 3. Verify environment $env:CLERK_TOKEN # 4. Exercise FastAPI endpoint (token expires fast!) uv run python main/scripts/test_clerk_auth.py "$env:CLERK_TOKEN" fixtures/test_urs.txt # 5. Tail audit logs for attribution Get-Content logs/audit/jobs/audit_$(Get-Date -Format yyyyMMdd).jsonl -Tail 3
Extension Hooks
- If tests require Docker Compose: run
after refreshing tokens.docker compose -f docker-compose.dev.yml up --build api worker - CI usage: Wrap helper invocation inside a temporary PowerShell profile so
is available to downstream$env:CLERK_TOKEN
orpytest
commands.uv run - Documentation updates: When procedures change, sync with
and note version in this skill.main/docs/guides/CLERK_INTEGRATION_TESTING.md
References
- Python helper hitting Clerk Backend API.scripts/get_clerk_token.py
- PowerShell wrapper for Windows devs.scripts/Set-ClerkToken.ps1
- Deep dive guide.main/docs/guides/CLERK_INTEGRATION_TESTING.md- Anthropic Agent Skills best practices (2025-10-02 spec) for structure and activation cues.
Maintainer: Compliance/Test Enablement Team
Last Updated: 2025-11-16
Status: ✅ Ready for Claude Code agents