2.3 KiB
Usage: claude self-hosted-runner decode-token [token] [options]
Decode a session-ingress JWT (CLAUDE_CODE_SESSION_ACCESS_TOKEN) and print its claims as JSON to stdout. Strips any sk-ant-cc- / sk-ant-si- prefix automatically. Pipe to jq to extract a single claim.
Token source (first non-empty wins):
- Positional argument
- $CLAUDE_CODE_SESSION_ACCESS_TOKEN
- Piped stdin
Signature verification against /v1/code/.well-known/jwks.json is ON by default, as is the exp/nbf check (60s skew). Prints "verified (kid=…, sig+exp)" to stderr on success; exits 1 on verification failure, expiry, or JWKS fetch error. Does NOT pin iss/aud/token-type — compare those from the decoded claims if your auth model depends on them.
Options: --header Print the JWT header instead of the claims. --no-verify Skip signature verification and the JWKS fetch. For offline inspection only — do NOT feed the output to an auth decision. --no-check-expiry Skip the exp/nbf check (signature still verified). For forensics ("was this token ever issued by us?"). --api-url API base URL for JWKS fetch (default: $ANTHROPIC_BASE_URL or the built-in default). --verify (Deprecated — verification is the default. Kept so older wrapper scripts don't break.) --help, -h Show this help.
Examples:
In an --exec-path wrapper: who created this session? Signature is
verified by default, so a tampered token exits non-zero here.
Use jq -re (not -r) when the claim gates an auth decision — jq -r prints
the literal string "null" and exits 0 when the claim is missing.
creator=$(claude self-hosted-runner decode-token | jq -re .act.email)
|| { echo "session JWT: no creator identity or verification failed" >&2; exit 1; }
Offline inspection (no network, no auth decision)
claude self-hosted-runner decode-token --no-verify
Decode a different token by piping it (unset the env var first)
echo "$SOME_TOKEN" | env -u CLAUDE_CODE_SESSION_ACCESS_TOKEN
claude self-hosted-runner decode-token --no-verify