content/providers/03-community-providers/10-claude-code.mdx
The ai-sdk-provider-claude-code community provider allows you to access Claude models through the official Claude Agent SDK. It's particularly useful for developers who want to use their existing Claude Pro/Max subscription without managing API keys.
| Provider Version | AI SDK Version | NPM Tag | Status |
|---|---|---|---|
| 3.x | v6 | latest | Stable |
| 2.x | v5 | ai-sdk-v5 | Maintenance |
| 0.x | v4 | ai-sdk-v4 | Legacy |
# AI SDK v6 (default)
npm install ai-sdk-provider-claude-code ai
# AI SDK v5
npm install ai-sdk-provider-claude-code@ai-sdk-v5 ai@^5.0.0
# AI SDK v4
npm install ai-sdk-provider-claude-code@ai-sdk-v4 ai@^4.0.0
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}> <Tab> <Snippet text="pnpm add ai-sdk-provider-claude-code" dark /> </Tab> <Tab> <Snippet text="npm install ai-sdk-provider-claude-code" dark /> </Tab> <Tab> <Snippet text="yarn add ai-sdk-provider-claude-code" dark /> </Tab> <Tab> <Snippet text="bun add ai-sdk-provider-claude-code" dark /> </Tab> </Tabs>
You can import the default provider instance claudeCode from ai-sdk-provider-claude-code:
import { claudeCode } from 'ai-sdk-provider-claude-code';
If you need a customized setup, you can import createClaudeCode and create a provider instance with your settings:
import { createClaudeCode } from 'ai-sdk-provider-claude-code';
const claudeCode = createClaudeCode({
allowedTools: ['Read', 'Write', 'Edit'],
disallowedTools: ['Bash'],
mcpServers: {
'my-server': {
command: 'node',
args: ['server.js'],
},
},
permissionMode: 'default',
});
You can use the following optional settings to customize the provider instance:
['Bash(rm:*)']).You can create models that call Claude through the Claude Agent SDK using the provider instance:
const model = claudeCode('sonnet');
Supported model shortcuts:
You can also use full model identifiers directly:
const model = claudeCode('claude-opus-4-5');
const model = claudeCode('claude-sonnet-4-5-20250514');
import { claudeCode } from 'ai-sdk-provider-claude-code';
import { generateText } from 'ai';
const { text } = await generateText({
model: claudeCode('sonnet'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
opus | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
sonnet | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
haiku | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
The provider uses your existing Claude Pro or Max subscription through the Claude Code CLI:
claude login
This opens a browser window for authentication. Once authenticated, the provider will use your subscription automatically.
npm install -g @anthropic-ai/claude-code)For more details, see the provider documentation.