@sylphx/ai-sdk-provider-claude-code
Claude Code provider for Vercel AI SDK with universal tool support - works with ANY standard Vercel AI SDK tool without MCP servers.

✨ Key Features
- 🔧 Universal Tool Support - Use ANY Vercel AI SDK tool via XML-based schema translation
- 🚀 Battle-Tested Streaming - Custom XML parser with event queue for robust streaming
- 🎯 Zero MCP Configuration - Tools executed by Vercel framework, not Claude Code CLI
- 🧠 Extended Thinking - Full support for Claude Opus 4's reasoning capabilities
- 📦 Type-Safe - Built with strict TypeScript and comprehensive type guards
- ⚡ AI SDK v5 Ready - Full
LanguageModelV2 implementation
🆚 Why This Provider?
| Tool Support | ✅ ANY Vercel AI SDK tool | ❌ MCP servers only |
| Setup Complexity | ✅ Zero config | ⚠️ Requires MCP setup |
| Tool Execution | ✅ Vercel framework | ⚠️ Separate MCP process |
| Streaming | ✅ Custom parser, debugged | ✅ Standard |
| Type Safety | ✅ Strict with guards | ✅ Standard TypeScript |
The key difference: While other providers lock you into MCP servers, our provider seamlessly translates standard Vercel AI SDK tools into Claude Code's format, giving you access to the vast AI SDK ecosystem without additional setup.
📦 Installation
npm install @sylphx/ai-sdk-provider-claude-code ai
🔑 Prerequisites
-
Claude Code CLI - Install and authenticate:
npm install -g @anthropic-ai/claude-agent-sdk
claude
-
Claude Pro/Max Subscription - Required for API access via Claude Code
🚀 Quick Start
Basic Text Generation
import { generateText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
const { text } = await generateText({
model: claudeCode('sonnet'),
prompt: 'Explain quantum computing in simple terms',
});
console.log(text);
Streaming Text
import { streamText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
const { textStream } = await streamText({
model: claudeCode('sonnet'),
prompt: 'Write a story about a robot learning to paint',
});
for await (const chunk of textStream) {
process.stdout.write(chunk);
}
Using Tools (The Magic! ✨)
import { generateText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
import { z } from 'zod';
const { text, toolCalls } = await generateText({
model: claudeCode('sonnet'),
prompt: 'What is the weather in San Francisco and Tokyo?',
tools: {
getWeather: {
description: 'Get the weather for a location',
parameters: z.object({
city: z.string().describe('The city name'),
}),
execute: async ({ city }) => {
return {
city,
temperature: 72,
condition: 'sunny',
};
},
},
},
});
console.log('Tool calls:', toolCalls);
console.log('Response:', text);
No MCP server needed! The tool is automatically converted to XML format and results are seamlessly integrated.
Extended Thinking (Opus 4)
import { generateText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
const { text, reasoning } = await generateText({
model: claudeCode('opus', {
maxThinkingTokens: 2000,
}),
prompt: 'Solve this complex logic puzzle: ...',
});
console.log('Reasoning:', reasoning);
console.log('Answer:', text);
Streaming with Tools
import { streamText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
import { z } from 'zod';
const { textStream, toolCallStreams } = await streamText({
model: claudeCode('sonnet'),
prompt: 'Search for the latest AI news and summarize',
tools: {
search: {
description: 'Search the web',
parameters: z.object({
query: z.string(),
}),
execute: async ({ query }) => {
return { results: [...] };
},
},
},
});
for await (const chunk of textStream) {
process.stdout.write(chunk);
}
for await (const toolCall of toolCallStreams) {
console.log('Tool called:', toolCall);
}
🎨 Available Models
claudeCode('opus')
claudeCode('sonnet')
claudeCode('haiku')
🔧 Advanced Usage
Provider Options
import { generateText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
const { text } = await generateText({
model: claudeCode('sonnet'),
prompt: 'Your prompt',
providerOptions: {
'claude-code': {
maxThinkingTokens: 1000,
},
},
});
Custom System Prompts
import { generateText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
const { text } = await generateText({
model: claudeCode('sonnet'),
messages: [
{
role: 'system',
content: 'You are a helpful AI assistant specialized in TypeScript.',
},
{
role: 'user',
content: 'How do I use generics?',
},
],
});
Multi-Turn Conversations
import { generateText } from 'ai';
import { claudeCode } from '@sylphx/ai-sdk-provider-claude-code';
const conversation = [
{ role: 'user', content: 'Hello!' },
{ role: 'assistant', content: 'Hi! How can I help you today?' },
{ role: 'user', content: 'Tell me about TypeScript.' },
];
const { text } = await generateText({
model: claudeCode('sonnet'),
messages: conversation,
});
🏗️ Architecture
How It Works
- Tool Schema Translation - Converts Vercel AI SDK tool schemas to XML format
- XML Parsing - Custom streaming XML parser handles tool calls in text
- Event Queue - Ensures proper event ordering during streaming
- Framework Delegation - Tool execution handled by Vercel framework
- Result Integration - Tool results formatted and fed back to Claude
Components
ClaudeCodeLanguageModel - Main LanguageModelV2 implementation
StreamingXMLParser - Custom parser for XML-based tool calls
text-based-tools - Tool schema → XML translation utilities
Why XML?
Claude Code CLI uses XML for tool calls. By translating standard JSON schemas to XML, we enable universal tool support without requiring MCP servers.
🧪 Examples
Check out the examples directory for more:
- 📝 Simple chat
- 🔧 Tool calling
- 🌊 Streaming
- 🧠 Extended thinking
- 💬 Multi-turn conversations
- 🖼️ Image analysis (coming soon)
⚠️ Current Limitations
- 📷 Image support - Not yet tested (AI SDK supports it, needs validation)
- 🧪 Test coverage - Test suite in development
- ⚙️ Advanced callbacks - No
canUseTool or abort signals yet
- 🚨 Tool errors - Basic error handling (no specialized tool-error events)
🗺️ Roadmap
🤝 Contributing
Contributions welcome! Please read our contributing guidelines first.
📄 License
MIT © 2025 Sylph X Ltd
🙏 Acknowledgments
📚 Related
🆘 Support
Made with ❤️ by Sylph X Ltd
If you find this provider helpful, please consider giving it a ⭐ on GitHub!