jwt-encode — Claude Code skill: sign JWTs for testing
Builds and signs JSON Web Tokens for testing and development, with HMAC, RSA and ECDSA. Handy when you need a valid token inside the agent session.
npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a claude-codeWhat jwt-encode does
The skill takes your claims, algorithm, secret and lifetime, builds the header and payload, signs the token and prints the full string next to a decoded view of header and payload. Defaults are HS256 and a 1 hour expiry, and iat with exp go into the payload unless you opt out.
Signing uses the first method available: Node.js with jose (installed globally only with your consent), then Python, then plain Bash through openssl — that last one handles HMAC-SHA256 only. The secret travels as an environment variable, since command-line arguments show up in shell history and ps output. With no secret supplied, the skill generates a random one via openssl rand -base64 32 and labels it test-only.
Asymmetric setups get key generation too: RSA at 2048 bits and ECDSA P-256. Test keys should be deleted afterwards and kept out of version-controlled directories. A request for alg: none is honoured only after explicit confirmation, because that token is unsigned and therefore exploitable.
What it helps with
- build a test access token with specific claims
- sign a payload with a secret from an environment variable
- generate an RSA or ECDSA key pair to verify signatures
- read the decoded header and payload of a finished token
- get a token without installing libraries, using
opensslalone
Example prompts for the agent
- create a JWT with claim sub=1234567890, HS256, 1 hour expiry
- sign this payload with my secret from the environment variable
- generate a test ECDSA P-256 key pair
How to install jwt-encode
1Skills CLI (Vercel)
npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a claude-code2Manually: put the files in place
~/.claude/skills/jwt-encode/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/jwt-encode/
1Skills CLI (Vercel)
npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a codex2Manually: put the files in place
.agents/skills/jwt-encode/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a cursor2Manually: put the files in place
.cursor/skills/jwt-encode/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install jsonwebtoken/jwt-skills jwt-encode2Manually: put the files in place
.github/skills/jwt-encode/SKILL.md1Skills CLI (Vercel)
npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a gemini-cli2Platform CLI
gemini skills install https://github.com/jsonwebtoken/jwt-skills --path jwt-encodeManually: put the files in place
.devin/skills/jwt-encode/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about jwt-encode
How do I install jwt-encode in Claude?
Run npx skills add jsonwebtoken/jwt-skills --skill jwt-encode -a claude-code. The skill file then sits at ~/.claude/skills/jwt-encode/SKILL.md.
What does jwt-encode do?
It creates and signs JSON Web Tokens for testing and development: it takes claims, algorithm, secret and expiry, then returns the token string with a breakdown of header and payload.
Which algorithms does it support?
HMAC, RSA and ECDSA. The Bash path covers HMAC-SHA256 only, so anything else needs Node.js with jose or Python.
Source text
SKILL.md · Apache-2.0
---
name: jwt-encode
description: Create and sign JSON Web Tokens (JWTs) for testing and development. Use when the user wants to generate, create, build, or sign a JWT — e.g. "create a JWT", "generate a test token", "sign this payload", "make a JWT with these claims", "build an access token". Supports HMAC, RSA, and ECDSA algorithms.
---
# JWT Encode
Create and sign JWTs for testing and development.
## Steps
1. **Gather inputs**: claims/payload, algorithm (default: HS256), secret or key, expiration (default: 1 hour).
2. **Build header**: `{"alg": "HS256", "typ": "JWT"}`. Add `kid` if provided.
3. **Build payload**: Always include `iat` and `exp` unless the user opts out. Add user-specified claims.
4. **Sign the token** using the best available method (see below).
5. **Display the result**: the full JWT string and a decoded breakdown of header + payload.
## Signing Methods
Pick the first available. Use the user's claims, secret, and algorithm — the examples below are templates only. Always pass the secret via an inline env var to avoid shell history exposure.
**Node.js** (preferred):
First, ensure `jose` is available — install it globally if missing:
```bash
node --input-type=module -e "await import('jose')" 2>/dev/null || npm install -g jose
```
Then sign the token:
```bash
JWT_SECRET='user-provided-secret' node --input-type=module -e "import {SignJWT} from 'jose'; console.log(await new SignJWT({sub:'1234567890'}).setProtectedHeader({alg:'HS256'}).setIssuedAt().setExpirationTime('1h').sign(new TextEncoder().encode(process.env.JWT_SECRET)))"
```
**Python**:
```bash
JWT_SECRET='user-provided-secret' python3 -c "import jwt,time; print(jwt.encode({'sub':'1234567890','iat':int(time.time()),'exp':int(time.time())+3600}, __import__('os').environ['JWT_SECRET'], algorithm='HS256'))"
```
**Bash** (HMAC-SHA256 only):
```bash
header=$(printf '{"alg":"HS256","typ":"JWT"}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '=')
payload=$(printf '{"sub":"1234567890","iat":1700000000,"exp":1700003600}' | openssl base64 -e -A | tr '+/' '-_' | tr -d '=')
signature=$(printf '%s.%s' "$header" "$payload" | openssl dgst -sha256 -hmac "$JWT_SECRET" -binary | openssl base64 -e -A | tr '+/' '-_' | tr -d '=')
printf '%s.%s.%s\n' "$header" "$payload" "$signature"
```
## Generating Test Keys
Only when the user needs asymmetric keys:
```bash
# RSA
openssl genrsa -out private.pem 2048 && openssl rsa -in private.pem -pubout -out public.pem
# ECDSA P-256
openssl ecparam -genkey -name prime256v1 -noout -out private-ec.pem && openssl ec -in private-ec.pem -pubout -out public-ec.pem
```
## Security Rules
- **Never pass secrets as literal command-line arguments.** Use environment variables (`$JWT_SECRET`) or file input (`--secret-file`). Command args are visible in shell history and `ps` output.
- **Never install packages without user consent.** Do not use `npx -y` or `pip install` silently.
- **If the user doesn't provide a secret**, generate a random one with `openssl rand -base64 32` and clearly label it as a test-only secret.
- **`alg: none`** — If the user requests it, warn that this creates an unsigned token exploitable via CVE-2015-9235. Only create it after explicit confirmation.
- **Generated key files** — Remind the user to delete test keys when done. Never write keys to version-controlled directories.
---
© jsonwebtoken · Apache-2.0 · jsonwebtoken/jwt-skills