@anthropic-ai/claude-agent-sdk 0.1.39 → 0.1.43

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.
Files changed (4) hide show
  1. package/cli.js +1616 -1546
  2. package/package.json +1 -1
  3. package/sdk.d.ts +35 -7
  4. package/sdk.mjs +24 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.39",
3
+ "version": "0.1.43",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
package/sdk.d.ts CHANGED
@@ -97,6 +97,10 @@ export type PermissionResult = {
97
97
  * commands.
98
98
  */
99
99
  updatedPermissions?: PermissionUpdate[];
100
+ /**
101
+ * The tool use ID. Supplied and used internally.
102
+ */
103
+ toolUseID?: string;
100
104
  } | {
101
105
  behavior: 'deny';
102
106
  /**
@@ -112,6 +116,10 @@ export type PermissionResult = {
112
116
  * which the model should incorporate and continue.
113
117
  */
114
118
  interrupt?: boolean;
119
+ /**
120
+ * The tool use ID. Supplied and used internally.
121
+ */
122
+ toolUseID?: string;
115
123
  };
116
124
  export type PermissionRuleValue = {
117
125
  toolName: string;
@@ -129,13 +137,20 @@ export type CanUseTool = (toolName: string, input: Record<string, unknown>, opti
129
137
  * `updatedPermissions` in the PermissionResult.
130
138
  */
131
139
  suggestions?: PermissionUpdate[];
140
+ /**
141
+ * The file path that triggered the permission request, if applicable.
142
+ * For example, when a Bash command tries to access a path outside allowed directories.
143
+ */
144
+ blockedPath?: string;
145
+ /** Explains why this permission request was triggered. */
146
+ decisionReason?: string;
132
147
  /**
133
148
  * Unique identifier for this specific tool call within the assistant message.
134
149
  * Multiple tool calls in the same assistant message will have different toolUseIDs.
135
150
  */
136
151
  toolUseID: string;
137
152
  }) => Promise<PermissionResult>;
138
- export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStop", "PreCompact"];
153
+ export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact"];
139
154
  export type HookEvent = (typeof HOOK_EVENTS)[number];
140
155
  export type HookCallback = (input: HookInput, toolUseID: string | undefined, options: {
141
156
  signal: AbortSignal;
@@ -156,12 +171,14 @@ export type PreToolUseHookInput = BaseHookInput & {
156
171
  hook_event_name: 'PreToolUse';
157
172
  tool_name: string;
158
173
  tool_input: unknown;
174
+ tool_use_id: string;
159
175
  };
160
176
  export type PostToolUseHookInput = BaseHookInput & {
161
177
  hook_event_name: 'PostToolUse';
162
178
  tool_name: string;
163
179
  tool_input: unknown;
164
180
  tool_response: unknown;
181
+ tool_use_id: string;
165
182
  };
166
183
  export type NotificationHookInput = BaseHookInput & {
167
184
  hook_event_name: 'Notification';
@@ -181,9 +198,16 @@ export type StopHookInput = BaseHookInput & {
181
198
  hook_event_name: 'Stop';
182
199
  stop_hook_active: boolean;
183
200
  };
201
+ export type SubagentStartHookInput = BaseHookInput & {
202
+ hook_event_name: 'SubagentStart';
203
+ agent_id: string;
204
+ agent_type: string;
205
+ };
184
206
  export type SubagentStopHookInput = BaseHookInput & {
185
207
  hook_event_name: 'SubagentStop';
186
208
  stop_hook_active: boolean;
209
+ agent_id: string;
210
+ agent_transcript_path: string;
187
211
  };
188
212
  export type PreCompactHookInput = BaseHookInput & {
189
213
  hook_event_name: 'PreCompact';
@@ -196,7 +220,7 @@ export type SessionEndHookInput = BaseHookInput & {
196
220
  hook_event_name: 'SessionEnd';
197
221
  reason: ExitReason;
198
222
  };
199
- export type HookInput = PreToolUseHookInput | PostToolUseHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStopHookInput | PreCompactHookInput;
223
+ export type HookInput = PreToolUseHookInput | PostToolUseHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput;
200
224
  export type AsyncHookJSONOutput = {
201
225
  async: true;
202
226
  asyncTimeout?: number;
@@ -219,6 +243,9 @@ export type SyncHookJSONOutput = {
219
243
  } | {
220
244
  hookEventName: 'SessionStart';
221
245
  additionalContext?: string;
246
+ } | {
247
+ hookEventName: 'SubagentStart';
248
+ additionalContext?: string;
222
249
  } | {
223
250
  hookEventName: 'PostToolUse';
224
251
  additionalContext?: string;
@@ -302,11 +329,12 @@ export type SDKResultMessage = {
302
329
  [modelName: string]: ModelUsage;
303
330
  };
304
331
  permission_denials: SDKPermissionDenial[];
332
+ structured_output?: unknown;
305
333
  uuid: UUID;
306
334
  session_id: string;
307
335
  } | {
308
336
  type: 'result';
309
- subtype: 'error_during_execution' | 'error_max_turns' | 'error_max_budget_usd';
337
+ subtype: 'error_during_execution' | 'error_max_turns' | 'error_max_budget_usd' | 'error_max_structured_output_retries';
310
338
  duration_ms: number;
311
339
  duration_api_ms: number;
312
340
  is_error: boolean;
@@ -484,6 +512,7 @@ export type Options = {
484
512
  maxBudgetUsd?: number;
485
513
  mcpServers?: Record<string, McpServerConfig>;
486
514
  model?: string;
515
+ outputSchema?: Record<string, unknown>;
487
516
  pathToClaudeCodeExecutable?: string;
488
517
  permissionMode?: PermissionMode;
489
518
  allowDangerouslySkipPermissions?: boolean;
@@ -505,10 +534,9 @@ export type Options = {
505
534
  plugins?: SdkPluginConfig[];
506
535
  resume?: string;
507
536
  /**
508
- * When resuming, only resume messages up to and including the assistant
509
- * message with this message.id. Use with --resume.
510
- * This allows you to resume from a specific point in the conversation.
511
- * The message ID is expected to be from SDKAssistantMessage.message.id.
537
+ * When resuming, only resume messages up to and including the message with this message.uuid.
538
+ * Use with --resume. This allows you to resume from a specific point in the conversation.
539
+ * The message ID is expected to be from SDKAssistantMessage.uuid.
512
540
  */
513
541
  resumeSessionAt?: string;
514
542
  settingSources?: SettingSource[];
package/sdk.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://docs.claude.com/en/docs/claude-code/legal-and-compliance.
3
3
 
4
- // Version: 0.1.39
4
+ // Version: 0.1.43
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -6349,6 +6349,7 @@ var HOOK_EVENTS = [
6349
6349
  "SessionStart",
6350
6350
  "SessionEnd",
6351
6351
  "Stop",
6352
+ "SubagentStart",
6352
6353
  "SubagentStop",
6353
6354
  "PreCompact"
6354
6355
  ];
@@ -6403,6 +6404,7 @@ class ProcessTransport {
6403
6404
  maxBudgetUsd,
6404
6405
  model,
6405
6406
  fallbackModel,
6407
+ outputSchema,
6406
6408
  permissionMode,
6407
6409
  allowDangerouslySkipPermissions,
6408
6410
  permissionPromptToolName,
@@ -6438,6 +6440,9 @@ class ProcessTransport {
6438
6440
  }
6439
6441
  if (model)
6440
6442
  args.push("--model", model);
6443
+ if (outputSchema) {
6444
+ args.push("--output-schema", JSON.stringify(outputSchema));
6445
+ }
6441
6446
  if (env.DEBUG)
6442
6447
  args.push("--debug-to-stderr");
6443
6448
  if (canUseTool) {
@@ -7435,7 +7440,8 @@ function getInitialState() {
7435
7440
  envVarValidators: [bashMaxOutputLengthValidator, maxOutputTokensValidator],
7436
7441
  lastAPIRequest: null,
7437
7442
  inMemoryErrorLog: [],
7438
- inlinePlugins: []
7443
+ inlinePlugins: [],
7444
+ sessionBypassPermissionsMode: false
7439
7445
  };
7440
7446
  }
7441
7447
  var STATE = getInitialState();
@@ -7665,11 +7671,17 @@ class Query {
7665
7671
  if (!this.canUseTool) {
7666
7672
  throw new Error("canUseTool callback is not provided.");
7667
7673
  }
7668
- return this.canUseTool(request.request.tool_name, request.request.input, {
7674
+ const result = await this.canUseTool(request.request.tool_name, request.request.input, {
7669
7675
  signal,
7670
7676
  suggestions: request.request.permission_suggestions,
7677
+ blockedPath: request.request.blocked_path,
7678
+ decisionReason: request.request.decision_reason,
7671
7679
  toolUseID: request.request.tool_use_id
7672
7680
  });
7681
+ return {
7682
+ ...result,
7683
+ toolUseID: request.request.tool_use_id
7684
+ };
7673
7685
  } else if (request.request.subtype === "hook_callback") {
7674
7686
  const result = await this.handleHookCallbacks(request.request.callback_id, request.request.input, request.request.tool_use_id, signal);
7675
7687
  return result;
@@ -7750,6 +7762,12 @@ class Query {
7750
7762
  max_thinking_tokens: maxThinkingTokens
7751
7763
  });
7752
7764
  }
7765
+ async rewindCode(userMessageId) {
7766
+ await this.request({
7767
+ subtype: "rewind_code",
7768
+ user_message_id: userMessageId
7769
+ });
7770
+ }
7753
7771
  async processPendingPermissionRequests(pendingPermissionRequests) {
7754
7772
  for (const request of pendingPermissionRequests) {
7755
7773
  if (request.request.subtype === "can_use_tool") {
@@ -14802,7 +14820,7 @@ function query({
14802
14820
  const dirname2 = join3(filename, "..");
14803
14821
  pathToClaudeCodeExecutable = join3(dirname2, "cli.js");
14804
14822
  }
14805
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.39";
14823
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.43";
14806
14824
  const {
14807
14825
  abortController = createAbortController(),
14808
14826
  additionalDirectories = [],
@@ -14825,6 +14843,7 @@ function query({
14825
14843
  maxBudgetUsd,
14826
14844
  mcpServers,
14827
14845
  model,
14846
+ outputSchema,
14828
14847
  permissionMode = "default",
14829
14848
  allowDangerouslySkipPermissions = false,
14830
14849
  permissionPromptToolName,
@@ -14879,6 +14898,7 @@ function query({
14879
14898
  maxBudgetUsd,
14880
14899
  model,
14881
14900
  fallbackModel,
14901
+ outputSchema,
14882
14902
  permissionMode,
14883
14903
  allowDangerouslySkipPermissions,
14884
14904
  permissionPromptToolName,