@anthropic-ai/claude-agent-sdk 0.1.26 → 0.1.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
package/sdk-tools.d.ts CHANGED
@@ -40,6 +40,14 @@ export interface AgentInput {
40
40
  * The type of specialized agent to use for this task
41
41
  */
42
42
  subagent_type: string;
43
+ /**
44
+ * Optional model to use for this agent. If not specified, inherits from parent. Prefer haiku for quick, straightforward tasks to minimize cost and latency.
45
+ */
46
+ model?: "sonnet" | "opus" | "haiku";
47
+ /**
48
+ * Optional agent ID to resume from. If provided, the agent will continue from the previous execution transcript.
49
+ */
50
+ resume?: string;
43
51
  }
44
52
  export interface BashInput {
45
53
  /**
package/sdk.d.ts CHANGED
@@ -129,6 +129,11 @@ export type CanUseTool = (toolName: string, input: Record<string, unknown>, opti
129
129
  * `updatedPermissions` in the PermissionResult.
130
130
  */
131
131
  suggestions?: PermissionUpdate[];
132
+ /**
133
+ * Unique identifier for this specific tool call within the assistant message.
134
+ * Multiple tool calls in the same assistant message will have different toolUseIDs.
135
+ */
136
+ toolUseID: string;
132
137
  }) => Promise<PermissionResult>;
133
138
  export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStop", "PreCompact"];
134
139
  export type HookEvent = (typeof HOOK_EVENTS)[number];
@@ -324,6 +329,10 @@ export type SDKSystemMessage = SDKMessageBase & {
324
329
  slash_commands: string[];
325
330
  output_style: string;
326
331
  skills: string[];
332
+ plugins: {
333
+ name: string;
334
+ path: string;
335
+ }[];
327
336
  };
328
337
  export type SDKPartialAssistantMessage = SDKMessageBase & {
329
338
  type: 'stream_event';
@@ -387,6 +396,8 @@ type CreateSdkMcpServerOptions = {
387
396
  /**
388
397
  * Creates an MCP server instance that can be used with the SDK transport.
389
398
  * This allows SDK users to define custom tools that run in the same process.
399
+ *
400
+ * If your SDK MCP calls will run longer than 60s, override CLAUDE_CODE_STREAM_CLOSE_TIMEOUT
390
401
  */
391
402
  export declare function createSdkMcpServer(_options: CreateSdkMcpServerOptions): McpSdkServerConfigWithInstance;
392
403
  export declare class AbortError extends Error {
@@ -398,6 +409,10 @@ export type AgentDefinition = {
398
409
  model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
399
410
  };
400
411
  export type SettingSource = 'user' | 'project' | 'local';
412
+ export type SdkPluginConfig = {
413
+ type: 'local';
414
+ path: string;
415
+ };
401
416
  export type Options = {
402
417
  abortController?: AbortController;
403
418
  additionalDirectories?: string[];
@@ -429,6 +444,21 @@ export type Options = {
429
444
  permissionMode?: PermissionMode;
430
445
  allowDangerouslySkipPermissions?: boolean;
431
446
  permissionPromptToolName?: string;
447
+ /**
448
+ * Load plugins for this session. Plugins provide custom commands, agents,
449
+ * skills, and hooks that extend Claude Code's capabilities.
450
+ *
451
+ * Currently only local plugins are supported via the 'local' type.
452
+ *
453
+ * @example
454
+ * ```typescript
455
+ * plugins: [
456
+ * { type: 'local', path: './my-plugin' },
457
+ * { type: 'local', path: '/absolute/path/to/plugin' }
458
+ * ]
459
+ * ```
460
+ */
461
+ plugins?: SdkPluginConfig[];
432
462
  resume?: string;
433
463
  /**
434
464
  * When resuming, only resume messages up to and including the assistant
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.26
4
+ // Version: 0.1.28
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -6400,7 +6400,8 @@ class ProcessTransport {
6400
6400
  mcpServers,
6401
6401
  strictMcpConfig,
6402
6402
  canUseTool,
6403
- includePartialMessages
6403
+ includePartialMessages,
6404
+ plugins
6404
6405
  } = this.options;
6405
6406
  const args = [
6406
6407
  "--output-format",
@@ -6470,6 +6471,15 @@ class ProcessTransport {
6470
6471
  for (const dir of additionalDirectories) {
6471
6472
  args.push("--add-dir", dir);
6472
6473
  }
6474
+ if (plugins && plugins.length > 0) {
6475
+ for (const plugin of plugins) {
6476
+ if (plugin.type === "local") {
6477
+ args.push("--plugin-dir", plugin.path);
6478
+ } else {
6479
+ throw new Error(`Unsupported plugin type: ${plugin.type}`);
6480
+ }
6481
+ }
6482
+ }
6473
6483
  if (this.options.forkSession) {
6474
6484
  args.push("--fork-session");
6475
6485
  }
@@ -7291,6 +7301,7 @@ import { dirname, join as join2 } from "path";
7291
7301
 
7292
7302
  // ../src/bootstrap/state.ts
7293
7303
  import { cwd } from "process";
7304
+ import { realpathSync as realpathSync2 } from "fs";
7294
7305
  import { randomUUID } from "crypto";
7295
7306
 
7296
7307
  // ../src/bootstrap/envValidators.ts
@@ -7352,8 +7363,9 @@ var maxOutputTokensValidator = {
7352
7363
 
7353
7364
  // ../src/bootstrap/state.ts
7354
7365
  function getInitialState() {
7366
+ const resolvedCwd = realpathSync2(cwd());
7355
7367
  return {
7356
- originalCwd: cwd(),
7368
+ originalCwd: resolvedCwd,
7357
7369
  totalCostUSD: 0,
7358
7370
  totalAPIDuration: 0,
7359
7371
  totalAPIDurationWithoutRetries: 0,
@@ -7363,7 +7375,7 @@ function getInitialState() {
7363
7375
  totalLinesAdded: 0,
7364
7376
  totalLinesRemoved: 0,
7365
7377
  hasUnknownModelCost: false,
7366
- cwd: cwd(),
7378
+ cwd: resolvedCwd,
7367
7379
  modelUsage: {},
7368
7380
  mainLoopModelOverride: undefined,
7369
7381
  maxRateLimitFallbackActive: false,
@@ -7495,12 +7507,14 @@ class Query {
7495
7507
  pendingMcpResponses = new Map;
7496
7508
  firstResultReceivedPromise;
7497
7509
  firstResultReceivedResolve;
7510
+ streamCloseTimeout;
7498
7511
  constructor(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers = new Map) {
7499
7512
  this.transport = transport;
7500
7513
  this.isSingleUserTurn = isSingleUserTurn;
7501
7514
  this.canUseTool = canUseTool;
7502
7515
  this.hooks = hooks;
7503
7516
  this.abortController = abortController;
7517
+ this.streamCloseTimeout = parseInt(process.env.CLAUDE_CODE_STREAM_CLOSE_TIMEOUT || "") || 60000;
7504
7518
  for (const [name, server] of sdkMcpServers) {
7505
7519
  const sdkTransport = new SdkControlServerTransport((message) => this.sendMcpServerMessageToCli(name, message));
7506
7520
  this.sdkMcpTransports.set(name, sdkTransport);
@@ -7626,7 +7640,8 @@ class Query {
7626
7640
  }
7627
7641
  return this.canUseTool(request.request.tool_name, request.request.input, {
7628
7642
  signal,
7629
- suggestions: request.request.permission_suggestions
7643
+ suggestions: request.request.permission_suggestions,
7644
+ toolUseID: request.request.tool_use_id
7630
7645
  });
7631
7646
  } else if (request.request.subtype === "hook_callback") {
7632
7647
  const result = await this.handleHookCallbacks(request.request.callback_id, request.request.input, request.request.tool_use_id, signal);
@@ -7707,6 +7722,13 @@ class Query {
7707
7722
  max_thinking_tokens: maxThinkingTokens
7708
7723
  });
7709
7724
  }
7725
+ async processPendingPermissionRequests(pendingPermissionRequests) {
7726
+ for (const request of pendingPermissionRequests) {
7727
+ if (request.request.subtype === "can_use_tool") {
7728
+ this.handleControlRequest(request).catch(() => {});
7729
+ }
7730
+ }
7731
+ }
7710
7732
  request(request) {
7711
7733
  const requestId = Math.random().toString(36).substring(2, 15);
7712
7734
  const sdkRequest = {
@@ -7720,6 +7742,9 @@ class Query {
7720
7742
  resolve(response);
7721
7743
  } else {
7722
7744
  reject(new Error(response.error));
7745
+ if (response.pending_permission_requests) {
7746
+ this.processPendingPermissionRequests(response.pending_permission_requests);
7747
+ }
7723
7748
  }
7724
7749
  });
7725
7750
  Promise.resolve(this.transport.write(JSON.stringify(sdkRequest) + `
@@ -7759,7 +7784,6 @@ class Query {
7759
7784
  logForDebugging(`[Query.streamInput] About to check MCP servers. this.sdkMcpTransports.size = ${this.sdkMcpTransports.size}`);
7760
7785
  if (this.sdkMcpTransports.size > 0 && this.firstResultReceivedPromise) {
7761
7786
  logForDebugging(`[Query.streamInput] Entering Promise.race to wait for result`);
7762
- const STREAM_CLOSE_TIMEOUT = 1e4;
7763
7787
  let timeoutId;
7764
7788
  await Promise.race([
7765
7789
  this.firstResultReceivedPromise.then(() => {
@@ -7772,7 +7796,7 @@ class Query {
7772
7796
  timeoutId = setTimeout(() => {
7773
7797
  logForDebugging(`[Query.streamInput] Timed out waiting for first result, closing input stream`);
7774
7798
  resolve();
7775
- }, STREAM_CLOSE_TIMEOUT);
7799
+ }, this.streamCloseTimeout);
7776
7800
  })
7777
7801
  ]);
7778
7802
  if (timeoutId) {
@@ -7812,11 +7836,7 @@ class Query {
7812
7836
  const messageId = "id" in mcpRequest.message ? mcpRequest.message.id : null;
7813
7837
  const key = `${serverName}:${messageId}`;
7814
7838
  return new Promise((resolve, reject) => {
7815
- let timeoutId = null;
7816
7839
  const cleanup = () => {
7817
- if (timeoutId) {
7818
- clearTimeout(timeoutId);
7819
- }
7820
7840
  this.pendingMcpResponses.delete(key);
7821
7841
  };
7822
7842
  const resolveAndCleanup = (response) => {
@@ -7838,12 +7858,6 @@ class Query {
7838
7858
  reject(new Error("No message handler registered"));
7839
7859
  return;
7840
7860
  }
7841
- timeoutId = setTimeout(() => {
7842
- if (this.pendingMcpResponses.has(key)) {
7843
- cleanup();
7844
- reject(new Error("Request timeout"));
7845
- }
7846
- }, 30000);
7847
7861
  });
7848
7862
  }
7849
7863
  }
@@ -14749,7 +14763,7 @@ function query({
14749
14763
  const dirname2 = join3(filename, "..");
14750
14764
  pathToClaudeCodeExecutable = join3(dirname2, "cli.js");
14751
14765
  }
14752
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.26";
14766
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.28";
14753
14767
  const {
14754
14768
  abortController = createAbortController(),
14755
14769
  additionalDirectories = [],
@@ -14774,6 +14788,7 @@ function query({
14774
14788
  permissionMode = "default",
14775
14789
  allowDangerouslySkipPermissions = false,
14776
14790
  permissionPromptToolName,
14791
+ plugins,
14777
14792
  resume,
14778
14793
  resumeSessionAt,
14779
14794
  stderr,
@@ -14836,7 +14851,8 @@ function query({
14836
14851
  strictMcpConfig,
14837
14852
  canUseTool: !!canUseTool,
14838
14853
  hooks: !!hooks,
14839
- includePartialMessages
14854
+ includePartialMessages,
14855
+ plugins
14840
14856
  });
14841
14857
  const queryInstance = new Query(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers);
14842
14858
  if (typeof prompt === "string") {