@dex-ai/claude-code
v0.3.0
Published
Claude Code provider for @dex-ai/sdk — drive Claude models through a Claude.ai (Pro/Max) subscription using local Claude Code CLI credentials.
Readme
@dex-ai/claude-code
Drive Claude models through your Claude.ai (Pro / Max) subscription instead of
a metered ANTHROPIC_API_KEY. This provider reuses the OAuth credentials that the
Claude Code CLI writes to
~/.claude/.credentials.json, refreshes them when they expire, and calls the
Anthropic Messages API as the official Claude Code client.
Setup
Install the Claude Code CLI and sign in with your Claude.ai account. Either launch Claude Code and complete the browser sign-in, or use the
/logincommand from inside Claude Code:claude # then complete the browser sign-in # or, from inside an existing Claude Code session: /loginEither path creates
~/.claude/.credentials.json.Configure the provider in dex (type
claude-code), or construct it directly:import { claudeCodeExtension } from "@dex-ai/claude-code"; const ext = claudeCodeExtension(); // models: claude-opus-4-8, claude-sonnet-4-6, claude-haiku-4-5 (defaults)
No API key is required or read — auth comes entirely from the local credentials file, and tokens are refreshed automatically.
Options
| Option | Default | Description |
|-------------------|----------------------------------|-------------|
| name | "claude-code" | Provider name used in Agent.create. |
| credentialsPath | ~/.claude/.credentials.json | Claude Code OAuth credentials file. |
| baseUrl | https://api.anthropic.com | Messages API base URL. |
| models | built-in defaults | Static model IDs. When set, discovery is skipped. |
| clientId | pinned Claude Code client id | OAuth client id for token refresh. |
| tokenUrl | Anthropic OAuth token endpoint | Refresh endpoint. |
| headers | — | Extra request headers (cannot override identity headers). |
| systemPreamble | Claude Code identity line | Override the required first system block. |
| rawChunks | false | Emit raw-chunk stream parts. |
How it works
- Auth — reads
claudeAiOauthfrom the credentials file; if the access token is within ~5 minutes ofexpiresAt, it refreshes viagrant_type=refresh_tokenand writes the rotated tokens back with0600permissions. - Client identity — every request sends the OAuth bearer token (not
x-api-key), theanthropic-beta: oauth-…flag that bills the subscription, aclaude-cliuser-agent (version resolved fromclaude --version), andx-app: cli. The required Claude Code system preamble is injected as the first system block. - Streaming — the Messages API wire translation is shared with
@dex-ai/anthropic(text, tool calls, extended thinking, prompt caching), so behavior matches the standard Anthropic provider.
⚠️ Terms of service
This provider authenticates as the Claude Code client using your subscription
credentials. Using a Claude.ai subscription for programmatic access outside the
official Claude Code client may violate Anthropic's terms of service, and the
client headers / beta flags it relies on can change without notice, which would
break this provider until updated. Use at your own risk. For production or
commercial use, prefer a standard ANTHROPIC_API_KEY with @dex-ai/anthropic.
