ai-sdk-provider-claude-code 3.4.2 → 3.4.4

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/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LanguageModelV3, ProviderV3, APICallError, LoadAPIKeyError } from '@ai-sdk/provider';
2
- import { PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
3
- export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, TaskCompletedHookInput, TeammateIdleHookInput, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
2
+ import { ThinkingConfig, PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
3
+ export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, TaskCompletedHookInput, TeammateIdleHookInput, ThinkingAdaptive, ThinkingConfig, ThinkingDisabled, ThinkingEnabled, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
4
4
  import { ZodObject, ZodRawShape } from 'zod';
5
5
 
6
6
  type StreamingInputMode = 'auto' | 'always' | 'off';
@@ -85,8 +85,37 @@ interface ClaudeCodeSettings {
85
85
  maxTurns?: number;
86
86
  /**
87
87
  * Maximum thinking tokens for the model
88
+ *
89
+ * @deprecated Use `thinking` instead.
88
90
  */
89
91
  maxThinkingTokens?: number;
92
+ /**
93
+ * Controls Claude's thinking/reasoning behavior.
94
+ * Takes precedence over the deprecated `maxThinkingTokens`.
95
+ *
96
+ * - `{ type: 'adaptive' }` — Claude decides when and how much to think (Opus 4.6+, default)
97
+ * - `{ type: 'enabled', budgetTokens?: number }` — Fixed thinking token budget
98
+ * - `{ type: 'disabled' }` — No extended thinking
99
+ *
100
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/adaptive-thinking
101
+ */
102
+ thinking?: ThinkingConfig;
103
+ /**
104
+ * Controls how much effort Claude puts into its response.
105
+ *
106
+ * - `'low'` — Minimal thinking, fastest responses
107
+ * - `'medium'` — Moderate thinking
108
+ * - `'high'` — Deep reasoning (default)
109
+ * - `'max'` — Maximum effort (Opus 4.6 only)
110
+ *
111
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/effort
112
+ */
113
+ effort?: 'low' | 'medium' | 'high' | 'max';
114
+ /**
115
+ * Enable prompt suggestions. When true, the agent emits a predicted
116
+ * next user prompt after each turn (arrives after the result message).
117
+ */
118
+ promptSuggestions?: boolean;
90
119
  /**
91
120
  * Working directory for CLI operations
92
121
  */
@@ -476,6 +505,7 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
476
505
  private getModel;
477
506
  private getSanitizedSdkOptions;
478
507
  private getEffectiveResume;
508
+ private extractTextAndThinking;
479
509
  private extractToolUses;
480
510
  private extractToolResults;
481
511
  private extractToolErrors;
@@ -759,7 +789,7 @@ declare function createAPICallError({ message, code, exitCode, stderr, promptExc
759
789
  * @example
760
790
  * ```typescript
761
791
  * throw createAuthenticationError({
762
- * message: 'Please run "claude login" to authenticate'
792
+ * message: 'Please run "claude auth login" to authenticate'
763
793
  * });
764
794
  * ```
765
795
  */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LanguageModelV3, ProviderV3, APICallError, LoadAPIKeyError } from '@ai-sdk/provider';
2
- import { PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
3
- export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, TaskCompletedHookInput, TeammateIdleHookInput, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
2
+ import { ThinkingConfig, PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
3
+ export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, TaskCompletedHookInput, TeammateIdleHookInput, ThinkingAdaptive, ThinkingConfig, ThinkingDisabled, ThinkingEnabled, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
4
4
  import { ZodObject, ZodRawShape } from 'zod';
5
5
 
6
6
  type StreamingInputMode = 'auto' | 'always' | 'off';
@@ -85,8 +85,37 @@ interface ClaudeCodeSettings {
85
85
  maxTurns?: number;
86
86
  /**
87
87
  * Maximum thinking tokens for the model
88
+ *
89
+ * @deprecated Use `thinking` instead.
88
90
  */
89
91
  maxThinkingTokens?: number;
92
+ /**
93
+ * Controls Claude's thinking/reasoning behavior.
94
+ * Takes precedence over the deprecated `maxThinkingTokens`.
95
+ *
96
+ * - `{ type: 'adaptive' }` — Claude decides when and how much to think (Opus 4.6+, default)
97
+ * - `{ type: 'enabled', budgetTokens?: number }` — Fixed thinking token budget
98
+ * - `{ type: 'disabled' }` — No extended thinking
99
+ *
100
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/adaptive-thinking
101
+ */
102
+ thinking?: ThinkingConfig;
103
+ /**
104
+ * Controls how much effort Claude puts into its response.
105
+ *
106
+ * - `'low'` — Minimal thinking, fastest responses
107
+ * - `'medium'` — Moderate thinking
108
+ * - `'high'` — Deep reasoning (default)
109
+ * - `'max'` — Maximum effort (Opus 4.6 only)
110
+ *
111
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/effort
112
+ */
113
+ effort?: 'low' | 'medium' | 'high' | 'max';
114
+ /**
115
+ * Enable prompt suggestions. When true, the agent emits a predicted
116
+ * next user prompt after each turn (arrives after the result message).
117
+ */
118
+ promptSuggestions?: boolean;
90
119
  /**
91
120
  * Working directory for CLI operations
92
121
  */
@@ -476,6 +505,7 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
476
505
  private getModel;
477
506
  private getSanitizedSdkOptions;
478
507
  private getEffectiveResume;
508
+ private extractTextAndThinking;
479
509
  private extractToolUses;
480
510
  private extractToolResults;
481
511
  private extractToolErrors;
@@ -759,7 +789,7 @@ declare function createAPICallError({ message, code, exitCode, stderr, promptExc
759
789
  * @example
760
790
  * ```typescript
761
791
  * throw createAuthenticationError({
762
- * message: 'Please run "claude login" to authenticate'
792
+ * message: 'Please run "claude auth login" to authenticate'
763
793
  * });
764
794
  * ```
765
795
  */
package/dist/index.js CHANGED
@@ -428,6 +428,16 @@ var claudeCodeSettingsSchema = z.object({
428
428
  ]).optional(),
429
429
  maxTurns: z.number().int().min(1).max(100).optional(),
430
430
  maxThinkingTokens: z.number().int().positive().max(1e5).optional(),
431
+ thinking: z.union([
432
+ z.object({ type: z.literal("adaptive") }).strict(),
433
+ z.object({
434
+ type: z.literal("enabled"),
435
+ budgetTokens: z.number().int().positive().optional()
436
+ }).strict(),
437
+ z.object({ type: z.literal("disabled") }).strict()
438
+ ]).optional(),
439
+ effort: z.enum(["low", "medium", "high", "max"]).optional(),
440
+ promptSuggestions: z.boolean().optional(),
431
441
  cwd: z.string().refine(
432
442
  (val) => {
433
443
  if (typeof process === "undefined" || !process.versions?.node) {
@@ -754,6 +764,22 @@ function getBaseProcessEnv() {
754
764
  }
755
765
  var STREAMING_FEATURE_WARNING = "Claude Agent SDK features (hooks/MCP/images) require streaming input. Set `streamingInput: 'always'` or provide `canUseTool` (auto streams only when canUseTool is set).";
756
766
  var SDK_OPTIONS_BLOCKLIST = /* @__PURE__ */ new Set(["model", "abortController", "prompt", "outputFormat"]);
767
+ function isContentBlock(item) {
768
+ return typeof item === "object" && item !== null && "type" in item;
769
+ }
770
+ function filterContentBlocks(content, type) {
771
+ if (!Array.isArray(content)) return [];
772
+ const blocks = content.filter(
773
+ (item) => isContentBlock(item) && item.type === type
774
+ );
775
+ const mismatch = blocks.find((b) => b.type !== type);
776
+ if (mismatch) {
777
+ throw new Error(
778
+ `filterContentBlocks: block type '${mismatch.type}' passed filter for '${type}'`
779
+ );
780
+ }
781
+ return blocks;
782
+ }
757
783
  function createEmptyUsage() {
758
784
  return {
759
785
  inputTokens: {
@@ -1009,14 +1035,29 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1009
1035
  getEffectiveResume(sdkOptions) {
1010
1036
  return sdkOptions?.resume ?? this.settings.resume ?? this.sessionId;
1011
1037
  }
1012
- extractToolUses(content) {
1013
- if (!Array.isArray(content)) {
1014
- return [];
1038
+ extractTextAndThinking(content) {
1039
+ if (!Array.isArray(content)) return { text: "", thinking: [] };
1040
+ let text = "";
1041
+ const thinking = [];
1042
+ for (const part of content) {
1043
+ if (!isContentBlock(part)) continue;
1044
+ if (part.type === "text" && typeof part.text === "string") {
1045
+ text += part.text;
1046
+ } else if (part.type === "thinking" && typeof part.thinking === "string") {
1047
+ thinking.push(part.thinking);
1048
+ }
1049
+ }
1050
+ if (text.length > 0 && typeof text !== "string") {
1051
+ throw new Error("extractTextAndThinking: accumulated text must be a string");
1052
+ }
1053
+ if (thinking.some((t) => typeof t !== "string")) {
1054
+ throw new Error("extractTextAndThinking: all thinking entries must be strings");
1015
1055
  }
1016
- return content.filter(
1017
- (item) => typeof item === "object" && item !== null && "type" in item && item.type === "tool_use"
1018
- ).map((item) => {
1019
- const { id, name, input, parent_tool_use_id } = item;
1056
+ return { text, thinking };
1057
+ }
1058
+ extractToolUses(content) {
1059
+ return filterContentBlocks(content, "tool_use").map((block) => {
1060
+ const { id, name, input, parent_tool_use_id } = block;
1020
1061
  return {
1021
1062
  id: typeof id === "string" && id.length > 0 ? id : generateId(),
1022
1063
  name: typeof name === "string" && name.length > 0 ? name : _ClaudeCodeLanguageModel.UNKNOWN_TOOL_NAME,
@@ -1026,13 +1067,8 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1026
1067
  });
1027
1068
  }
1028
1069
  extractToolResults(content) {
1029
- if (!Array.isArray(content)) {
1030
- return [];
1031
- }
1032
- return content.filter(
1033
- (item) => typeof item === "object" && item !== null && "type" in item && item.type === "tool_result"
1034
- ).map((item) => {
1035
- const { tool_use_id, content: content2, is_error, name } = item;
1070
+ return filterContentBlocks(content, "tool_result").map((block) => {
1071
+ const { tool_use_id, content: content2, is_error, name } = block;
1036
1072
  return {
1037
1073
  id: typeof tool_use_id === "string" && tool_use_id.length > 0 ? tool_use_id : generateId(),
1038
1074
  name: typeof name === "string" && name.length > 0 ? name : void 0,
@@ -1042,13 +1078,8 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1042
1078
  });
1043
1079
  }
1044
1080
  extractToolErrors(content) {
1045
- if (!Array.isArray(content)) {
1046
- return [];
1047
- }
1048
- return content.filter(
1049
- (item) => typeof item === "object" && item !== null && "type" in item && item.type === "tool_error"
1050
- ).map((item) => {
1051
- const { tool_use_id, error, name } = item;
1081
+ return filterContentBlocks(content, "tool_error").map((block) => {
1082
+ const { tool_use_id, error, name } = block;
1052
1083
  return {
1053
1084
  id: typeof tool_use_id === "string" && tool_use_id.length > 0 ? tool_use_id : generateId(),
1054
1085
  name: typeof name === "string" && name.length > 0 ? name : void 0,
@@ -1172,6 +1203,9 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1172
1203
  pathToClaudeCodeExecutable: this.settings.pathToClaudeCodeExecutable,
1173
1204
  maxTurns: this.settings.maxTurns,
1174
1205
  maxThinkingTokens: this.settings.maxThinkingTokens,
1206
+ thinking: this.settings.thinking,
1207
+ effort: this.settings.effort,
1208
+ promptSuggestions: this.settings.promptSuggestions,
1175
1209
  cwd: this.settings.cwd,
1176
1210
  executable: this.settings.executable,
1177
1211
  executableArgs: this.settings.executableArgs,
@@ -1295,6 +1329,7 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1295
1329
  "auth failed",
1296
1330
  "please login",
1297
1331
  "claude login",
1332
+ "claude auth login",
1298
1333
  "/login",
1299
1334
  // CLI returns "Please run /login"
1300
1335
  "invalid api key"
@@ -1388,6 +1423,7 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1388
1423
  effectiveResume
1389
1424
  );
1390
1425
  let text = "";
1426
+ const thinkingTraces = [];
1391
1427
  let structuredOutput;
1392
1428
  let usage = createEmptyUsage();
1393
1429
  let finishReason = { unified: "stop", raw: void 0 };
@@ -1443,7 +1479,11 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1443
1479
  for await (const message of response) {
1444
1480
  this.logger.debug(`[claude-code] Received message type: ${message.type}`);
1445
1481
  if (message.type === "assistant") {
1446
- text += message.message.content.map((c) => c.type === "text" ? c.text : "").join("");
1482
+ const { text: messageText, thinking: messageThinking } = this.extractTextAndThinking(
1483
+ message.message.content
1484
+ );
1485
+ text += messageText;
1486
+ thinkingTraces.push(...messageThinking);
1447
1487
  } else if (message.type === "result") {
1448
1488
  done();
1449
1489
  this.setSessionId(message.session_id);
@@ -1510,7 +1550,13 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1510
1550
  }
1511
1551
  const finalText = structuredOutput !== void 0 ? JSON.stringify(structuredOutput) : text;
1512
1552
  return {
1513
- content: [{ type: "text", text: finalText }],
1553
+ content: [
1554
+ ...thinkingTraces.map((trace) => ({
1555
+ type: "reasoning",
1556
+ text: trace
1557
+ })),
1558
+ { type: "text", text: finalText }
1559
+ ],
1514
1560
  usage,
1515
1561
  finishReason,
1516
1562
  warnings,
@@ -1528,7 +1574,8 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1528
1574
  ...costUsd !== void 0 && { costUsd },
1529
1575
  ...durationMs !== void 0 && { durationMs },
1530
1576
  ...modelUsage !== void 0 && { modelUsage },
1531
- ...wasTruncated && { truncated: true }
1577
+ ...wasTruncated && { truncated: true },
1578
+ ...thinkingTraces.length > 0 && { thinkingTraces }
1532
1579
  }
1533
1580
  }
1534
1581
  };
@@ -1747,11 +1794,18 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1747
1794
  const toolName = typeof toolBlock.name === "string" && toolBlock.name.length > 0 ? toolBlock.name : _ClaudeCodeLanguageModel.UNKNOWN_TOOL_NAME;
1748
1795
  hasReceivedStreamEvents = true;
1749
1796
  if (textPartId) {
1797
+ const closedTextId = textPartId;
1750
1798
  controller.enqueue({
1751
1799
  type: "text-end",
1752
- id: textPartId
1800
+ id: closedTextId
1753
1801
  });
1754
1802
  textPartId = void 0;
1803
+ for (const [idx, blockTextId] of textBlocksByIndex) {
1804
+ if (blockTextId === closedTextId) {
1805
+ textBlocksByIndex.delete(idx);
1806
+ break;
1807
+ }
1808
+ }
1755
1809
  }
1756
1810
  toolBlocksByIndex.set(blockIndex, toolId);
1757
1811
  toolInputAccumulators.set(toolId, "");
@@ -1810,11 +1864,18 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1810
1864
  const blockIndex = "index" in event ? event.index : -1;
1811
1865
  hasReceivedStreamEvents = true;
1812
1866
  if (textPartId) {
1867
+ const closedTextId = textPartId;
1813
1868
  controller.enqueue({
1814
1869
  type: "text-end",
1815
- id: textPartId
1870
+ id: closedTextId
1816
1871
  });
1817
1872
  textPartId = void 0;
1873
+ for (const [idx, blockTextId] of textBlocksByIndex) {
1874
+ if (blockTextId === closedTextId) {
1875
+ textBlocksByIndex.delete(idx);
1876
+ break;
1877
+ }
1878
+ }
1818
1879
  }
1819
1880
  const reasoningPartId = generateId();
1820
1881
  reasoningBlocksByIndex.set(blockIndex, reasoningPartId);
@@ -1925,11 +1986,18 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1925
1986
  const content = message.message.content;
1926
1987
  const tools = this.extractToolUses(content);
1927
1988
  if (textPartId && tools.length > 0) {
1989
+ const closedTextId = textPartId;
1928
1990
  controller.enqueue({
1929
1991
  type: "text-end",
1930
- id: textPartId
1992
+ id: closedTextId
1931
1993
  });
1932
1994
  textPartId = void 0;
1995
+ for (const [idx, blockTextId] of textBlocksByIndex) {
1996
+ if (blockTextId === closedTextId) {
1997
+ textBlocksByIndex.delete(idx);
1998
+ break;
1999
+ }
2000
+ }
1933
2001
  }
1934
2002
  for (const tool3 of tools) {
1935
2003
  const toolId = tool3.id;