ai-sdk-provider-claude-code 2.0.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  # AI SDK Provider for Claude Code SDK
11
11
 
12
- > **Latest Release**: Version 2.x uses the Claude Agent SDK with explicit configuration defaults. Version 1.x is the previous stable release. For AI SDK v4 support, use the `ai-sdk-v4` tag or version 0.2.x.
12
+ > **Latest Release**: Version 2.x uses the Claude Agent SDK with native structured outputs support (v2.2.0+). For AI SDK v4 support, use the `ai-sdk-v4` tag or version 0.2.x.
13
13
 
14
14
  **ai-sdk-provider-claude-code** lets you use Claude via the [Vercel AI SDK](https://sdk.vercel.ai/docs) through the official `@anthropic-ai/claude-agent-sdk` and the Claude Code CLI.
15
15
 
@@ -45,12 +45,69 @@ npm install ai-sdk-provider-claude-code@ai-sdk-v4 ai@^4.3.16
45
45
 
46
46
  ## Zod Compatibility
47
47
 
48
- This package supports both **Zod 3** and **Zod 4**:
48
+ This package is **tested and compatible with both Zod 3 and Zod 4**, but there's an important peer dependency consideration:
49
49
 
50
- - **Zod 4** (Recommended): `npm install zod@^4.0.0`
51
- - ✅ **Zod 3** (Still supported): `npm install zod@^3.0.0`
50
+ ### Current Status
52
51
 
53
- The package uses Zod for schema validation and works seamlessly with both versions. All 302 tests pass with both Zod 3 and Zod 4. See `examples/zod4-compatibility-test.ts` for comprehensive compatibility tests.
52
+ - **Zod 3** (fully supported, no warnings)
53
+ - ⚠️ **Zod 4** (functional, but requires `--legacy-peer-deps`)
54
+
55
+ While this package declares support for both versions (`peerDependencies: "zod": "^3.0.0 || ^4.0.0"`), the underlying `@anthropic-ai/claude-agent-sdk` currently only declares support for Zod 3 (`peerDependencies: "zod": "^3.24.1"`).
56
+
57
+ **All 302 tests pass with both Zod 3 and Zod 4.** See `examples/zod4-compatibility-test.ts` for comprehensive compatibility verification.
58
+
59
+ ### Installation Instructions
60
+
61
+ **With Zod 3 (recommended for now):**
62
+
63
+ ```bash
64
+ npm install ai-sdk-provider-claude-code ai zod@^3.0.0
65
+ ```
66
+
67
+ **With Zod 4 (requires package manager-specific flags):**
68
+
69
+ For **npm**:
70
+
71
+ ```bash
72
+ npm install ai-sdk-provider-claude-code ai zod@^4.0.0 --legacy-peer-deps
73
+ ```
74
+
75
+ For **pnpm**:
76
+
77
+ ```bash
78
+ pnpm install ai-sdk-provider-claude-code ai zod@^4.0.0 --no-strict-peer-dependencies
79
+ # Or configure it project-wide:
80
+ pnpm config set strict-peer-dependencies false
81
+ ```
82
+
83
+ For **Yarn** (Berry/v2+):
84
+
85
+ ```bash
86
+ yarn add ai-sdk-provider-claude-code ai zod@^4.0.0
87
+ # Yarn's peer resolution typically doesn't error here
88
+ ```
89
+
90
+ ### For Package Developers
91
+
92
+ If you're developing with this package in your repository, add a configuration file to avoid needing the flag on every install:
93
+
94
+ **For npm** (`.npmrc`):
95
+
96
+ ```ini
97
+ # .npmrc
98
+ legacy-peer-deps=true
99
+ ```
100
+
101
+ **For pnpm** (`.npmrc`):
102
+
103
+ ```ini
104
+ # .npmrc
105
+ strict-peer-dependencies=false
106
+ ```
107
+
108
+ > **Note**: The `.npmrc` file in this repository is committed for CI/development consistency but is **not included in the published package** (it's excluded via the `files` field in `package.json`). End users will still need to use the appropriate flags when installing with Zod 4.
109
+
110
+ > **Temporary Workaround**: This configuration is needed until `@anthropic-ai/claude-agent-sdk` adds official Zod 4 support to their peer dependencies. Track progress in the [claude-agent-sdk repository](https://github.com/anthropics/anthropic-sdk-typescript).
54
111
 
55
112
  ## Installation
56
113
 
@@ -207,12 +264,44 @@ If you're upgrading from version 1.x:
207
264
  - Explicit configuration over implicit defaults
208
265
  - Future-proof alignment with Claude Agent SDK design
209
266
 
267
+ ## Structured Outputs
268
+
269
+ This provider supports **native structured outputs** via the Claude Agent SDK (v0.1.45+). When using `generateObject()` or `streamObject()`, the SDK guarantees schema-compliant JSON responses through constrained decoding.
270
+
271
+ ```typescript
272
+ import { generateObject } from 'ai';
273
+ import { claudeCode } from 'ai-sdk-provider-claude-code';
274
+ import { z } from 'zod';
275
+
276
+ const result = await generateObject({
277
+ model: claudeCode('sonnet'),
278
+ schema: z.object({
279
+ name: z.string(),
280
+ age: z.number(),
281
+ email: z.string().email(),
282
+ }),
283
+ prompt: 'Generate a user profile for a software developer',
284
+ });
285
+
286
+ console.log(result.object); // Guaranteed to match schema
287
+ // { name: "Alex Chen", age: 28, email: "alex@example.com" }
288
+ ```
289
+
290
+ **Benefits:**
291
+
292
+ - ✅ **Guaranteed schema compliance** - Constrained decoding ensures valid output
293
+ - ✅ **No JSON parsing errors** - SDK handles all validation
294
+ - ✅ **No prompt engineering** - Schema enforcement is native to the SDK
295
+ - ✅ **Better performance** - No retry/extraction logic needed
296
+
297
+ > **Note:** A schema is required for JSON output. Using `responseFormat: { type: 'json' }` without a schema is not supported by Claude Code (matching Anthropic's official provider behavior). An `unsupported-setting` warning will be emitted and the call will be treated as plain text. Always use `generateObject()` or `streamObject()` with a Zod schema for guaranteed JSON output.
298
+
210
299
  ## Core Features
211
300
 
212
301
  - 🚀 Vercel AI SDK compatibility
213
302
  - 🔄 Streaming support
214
303
  - 💬 Multi-turn conversations
215
- - 🎯 Object generation with JSON schemas
304
+ - 🎯 Native structured outputs with guaranteed schema compliance
216
305
  - 🛑 AbortSignal support
217
306
  - 🔧 Tool management (MCP servers, permissions)
218
307
  - 🧩 Callbacks (hooks, canUseTool)