@anthropic-ai/claude-agent-sdk 0.1.58 → 0.1.60

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 (38) hide show
  1. package/cli.js +1823 -1639
  2. package/package.json +1 -1
  3. package/sdk-tools.d.ts +28 -1
  4. package/sdk.d.ts +278 -7
  5. package/sdk.mjs +2 -2
  6. package/vendor/claude-code-jetbrains-plugin/lib/annotations-23.0.0.jar +0 -0
  7. package/vendor/claude-code-jetbrains-plugin/lib/claude-code-jetbrains-plugin-0.1.12-beta-searchableOptions.jar +0 -0
  8. package/vendor/claude-code-jetbrains-plugin/lib/claude-code-jetbrains-plugin-0.1.12-beta.jar +0 -0
  9. package/vendor/claude-code-jetbrains-plugin/lib/config-1.4.3.jar +0 -0
  10. package/vendor/claude-code-jetbrains-plugin/lib/jansi-2.4.1.jar +0 -0
  11. package/vendor/claude-code-jetbrains-plugin/lib/kotlin-logging-jvm-7.0.0.jar +0 -0
  12. package/vendor/claude-code-jetbrains-plugin/lib/kotlin-reflect-2.0.21.jar +0 -0
  13. package/vendor/claude-code-jetbrains-plugin/lib/kotlin-sdk-jvm-0.4.0.jar +0 -0
  14. package/vendor/claude-code-jetbrains-plugin/lib/kotlin-stdlib-2.1.20.jar +0 -0
  15. package/vendor/claude-code-jetbrains-plugin/lib/kotlinx-coroutines-core-jvm-1.9.0.jar +0 -0
  16. package/vendor/claude-code-jetbrains-plugin/lib/kotlinx-coroutines-slf4j-1.9.0.jar +0 -0
  17. package/vendor/claude-code-jetbrains-plugin/lib/kotlinx-io-bytestring-jvm-0.5.4.jar +0 -0
  18. package/vendor/claude-code-jetbrains-plugin/lib/kotlinx-io-core-jvm-0.5.4.jar +0 -0
  19. package/vendor/claude-code-jetbrains-plugin/lib/kotlinx-serialization-core-jvm-1.8.1.jar +0 -0
  20. package/vendor/claude-code-jetbrains-plugin/lib/kotlinx-serialization-json-jvm-1.8.1.jar +0 -0
  21. package/vendor/claude-code-jetbrains-plugin/lib/ktor-client-cio-jvm-3.0.2.jar +0 -0
  22. package/vendor/claude-code-jetbrains-plugin/lib/ktor-client-core-jvm-3.0.2.jar +0 -0
  23. package/vendor/claude-code-jetbrains-plugin/lib/ktor-events-jvm-3.0.2.jar +0 -0
  24. package/vendor/claude-code-jetbrains-plugin/lib/ktor-http-cio-jvm-3.0.2.jar +0 -0
  25. package/vendor/claude-code-jetbrains-plugin/lib/ktor-http-jvm-3.0.2.jar +0 -0
  26. package/vendor/claude-code-jetbrains-plugin/lib/ktor-io-jvm-3.0.2.jar +0 -0
  27. package/vendor/claude-code-jetbrains-plugin/lib/ktor-network-jvm-3.0.2.jar +0 -0
  28. package/vendor/claude-code-jetbrains-plugin/lib/ktor-network-tls-jvm-3.0.2.jar +0 -0
  29. package/vendor/claude-code-jetbrains-plugin/lib/ktor-serialization-jvm-3.0.2.jar +0 -0
  30. package/vendor/claude-code-jetbrains-plugin/lib/ktor-server-cio-jvm-3.0.2.jar +0 -0
  31. package/vendor/claude-code-jetbrains-plugin/lib/ktor-server-core-jvm-3.0.2.jar +0 -0
  32. package/vendor/claude-code-jetbrains-plugin/lib/ktor-server-sse-jvm-3.0.2.jar +0 -0
  33. package/vendor/claude-code-jetbrains-plugin/lib/ktor-server-websockets-jvm-3.0.2.jar +0 -0
  34. package/vendor/claude-code-jetbrains-plugin/lib/ktor-sse-jvm-3.0.2.jar +0 -0
  35. package/vendor/claude-code-jetbrains-plugin/lib/ktor-utils-jvm-3.0.2.jar +0 -0
  36. package/vendor/claude-code-jetbrains-plugin/lib/ktor-websocket-serialization-jvm-3.0.2.jar +0 -0
  37. package/vendor/claude-code-jetbrains-plugin/lib/ktor-websockets-jvm-3.0.2.jar +0 -0
  38. package/vendor/claude-code-jetbrains-plugin/lib/slf4j-api-2.0.16.jar +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
package/sdk-tools.d.ts CHANGED
@@ -26,7 +26,8 @@ export type ToolInputSchemas =
26
26
  | TodoWriteInput
27
27
  | WebFetchInput
28
28
  | WebSearchInput
29
- | AskUserQuestionInput;
29
+ | AskUserQuestionInput
30
+ | AgentOutputInput;
30
31
 
31
32
  export interface AgentInput {
32
33
  /**
@@ -49,6 +50,10 @@ export interface AgentInput {
49
50
  * Optional agent ID to resume from. If provided, the agent will continue from the previous execution transcript.
50
51
  */
51
52
  resume?: string;
53
+ /**
54
+ * Set to true to run this agent in the background. Use AgentOutputTool to read the output later.
55
+ */
56
+ run_in_background?: boolean;
52
57
  }
53
58
  export interface BashInput {
54
59
  /**
@@ -94,6 +99,14 @@ export interface BashOutputInput {
94
99
  filter?: string;
95
100
  }
96
101
  export interface ExitPlanModeInput {
102
+ /**
103
+ * Whether to launch a swarm to implement the plan
104
+ */
105
+ launchSwarm?: boolean;
106
+ /**
107
+ * Number of teammates to spawn in the swarm
108
+ */
109
+ teammateCount?: number;
97
110
  [k: string]: unknown;
98
111
  }
99
112
  export interface FileEditInput {
@@ -1476,3 +1489,17 @@ export interface AskUserQuestionInput {
1476
1489
  [k: string]: string;
1477
1490
  };
1478
1491
  }
1492
+ export interface AgentOutputInput {
1493
+ /**
1494
+ * The agent ID to retrieve results for
1495
+ */
1496
+ agentId: string;
1497
+ /**
1498
+ * Whether to block until results are ready
1499
+ */
1500
+ block?: boolean;
1501
+ /**
1502
+ * Maximum time to wait in seconds
1503
+ */
1504
+ wait_up_to?: number;
1505
+ }
package/sdk.d.ts CHANGED
@@ -298,15 +298,35 @@ export type SyncHookJSONOutput = {
298
298
  };
299
299
  };
300
300
  export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput;
301
+ /**
302
+ * Permission mode for controlling how tool executions are handled.
303
+ * - `'default'` - Standard behavior, prompts for dangerous operations
304
+ * - `'acceptEdits'` - Auto-accept file edit operations
305
+ * - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
306
+ * - `'plan'` - Planning mode, no actual tool execution
307
+ * - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
308
+ */
301
309
  export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'dontAsk';
310
+ /**
311
+ * Information about an available slash command.
312
+ */
302
313
  export type SlashCommand = {
314
+ /** Command name (without the leading slash) */
303
315
  name: string;
316
+ /** Description of what the command does */
304
317
  description: string;
318
+ /** Hint for command arguments (e.g., "<file>") */
305
319
  argumentHint: string;
306
320
  };
321
+ /**
322
+ * Information about an available model.
323
+ */
307
324
  export type ModelInfo = {
325
+ /** Model identifier to use in API calls */
308
326
  value: string;
327
+ /** Human-readable display name */
309
328
  displayName: string;
329
+ /** Description of the model's capabilities */
310
330
  description: string;
311
331
  };
312
332
  /** Information about the logged in user's account. */
@@ -317,9 +337,15 @@ export type AccountInfo = {
317
337
  tokenSource?: string;
318
338
  apiKeySource?: string;
319
339
  };
340
+ /**
341
+ * Status information for an MCP server connection.
342
+ */
320
343
  export type McpServerStatus = {
344
+ /** Server name as configured */
321
345
  name: string;
346
+ /** Current connection status */
322
347
  status: 'connected' | 'failed' | 'needs-auth' | 'pending';
348
+ /** Server information (available when connected) */
323
349
  serverInfo?: {
324
350
  name: string;
325
351
  version: string;
@@ -489,8 +515,24 @@ export interface Query extends AsyncGenerator<SDKMessage, void> {
489
515
  * The following methods are control requests, and are only supported when
490
516
  * streaming input/output is used.
491
517
  */
518
+ /**
519
+ * Interrupt the current query execution. The query will stop processing
520
+ * and return control to the caller.
521
+ */
492
522
  interrupt(): Promise<void>;
523
+ /**
524
+ * Change the permission mode for the current session.
525
+ * Only available in streaming input mode.
526
+ *
527
+ * @param mode - The new permission mode to set
528
+ */
493
529
  setPermissionMode(mode: PermissionMode): Promise<void>;
530
+ /**
531
+ * Change the model used for subsequent responses.
532
+ * Only available in streaming input mode.
533
+ *
534
+ * @param model - The model identifier to use, or undefined to use the default
535
+ */
494
536
  setModel(model?: string): Promise<void>;
495
537
  /**
496
538
  * Set the maximum number of thinking tokens the model is allowed to use
@@ -500,15 +542,39 @@ export interface Query extends AsyncGenerator<SDKMessage, void> {
500
542
  *
501
543
  * Use `null` to clear any previously set limit and allow the model to
502
544
  * use the default maximum thinking tokens.
545
+ *
546
+ * @param maxThinkingTokens - Maximum tokens for thinking, or null to clear the limit
503
547
  */
504
548
  setMaxThinkingTokens(maxThinkingTokens: number | null): Promise<void>;
549
+ /**
550
+ * Get the list of available slash commands for the current session.
551
+ *
552
+ * @returns Array of available slash commands with their names and descriptions
553
+ */
505
554
  supportedCommands(): Promise<SlashCommand[]>;
555
+ /**
556
+ * Get the list of available models.
557
+ *
558
+ * @returns Array of model information including display names and descriptions
559
+ */
506
560
  supportedModels(): Promise<ModelInfo[]>;
561
+ /**
562
+ * Get the current status of all configured MCP servers.
563
+ *
564
+ * @returns Array of MCP server statuses (connected, failed, needs-auth, pending)
565
+ */
507
566
  mcpServerStatus(): Promise<McpServerStatus[]>;
567
+ /**
568
+ * Get information about the authenticated account.
569
+ *
570
+ * @returns Account information including email, organization, and subscription type
571
+ */
508
572
  accountInfo(): Promise<AccountInfo>;
509
573
  /**
510
- * Stream input messages to the query
511
- * Used internally for multi-turn conversations
574
+ * Stream input messages to the query.
575
+ * Used internally for multi-turn conversations.
576
+ *
577
+ * @param stream - Async iterable of user messages to send
512
578
  */
513
579
  streamInput(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
514
580
  }
@@ -561,27 +627,89 @@ type CreateSdkMcpServerOptions = {
561
627
  export declare function createSdkMcpServer(_options: CreateSdkMcpServerOptions): McpSdkServerConfigWithInstance;
562
628
  export declare class AbortError extends Error {
563
629
  }
630
+ /**
631
+ * Definition for a custom subagent that can be invoked via the Task tool.
632
+ */
564
633
  export type AgentDefinition = {
634
+ /** Natural language description of when to use this agent */
565
635
  description: string;
636
+ /** Array of allowed tool names. If omitted, inherits all tools from parent */
566
637
  tools?: string[];
638
+ /** Array of tool names to explicitly disallow for this agent */
567
639
  disallowedTools?: string[];
640
+ /** The agent's system prompt */
568
641
  prompt: string;
642
+ /** Model to use for this agent. If omitted or 'inherit', uses the main model */
569
643
  model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
644
+ /** Experimental: Critical reminder added to system prompt */
570
645
  criticalSystemReminder_EXPERIMENTAL?: string;
571
646
  };
647
+ /**
648
+ * Source for loading filesystem-based settings.
649
+ * - `'user'` - Global user settings (`~/.claude/settings.json`)
650
+ * - `'project'` - Project settings (`.claude/settings.json`)
651
+ * - `'local'` - Local settings (`.claude/settings.local.json`)
652
+ */
572
653
  export type SettingSource = 'user' | 'project' | 'local';
654
+ /**
655
+ * Configuration for loading a plugin.
656
+ */
573
657
  export type SdkPluginConfig = {
658
+ /** Plugin type. Currently only 'local' is supported */
574
659
  type: 'local';
660
+ /** Absolute or relative path to the plugin directory */
575
661
  path: string;
576
662
  };
577
663
  export type Options = {
664
+ /**
665
+ * Controller for cancelling the query. When aborted, the query will stop
666
+ * and clean up resources.
667
+ */
578
668
  abortController?: AbortController;
669
+ /**
670
+ * Additional directories Claude can access beyond the current working directory.
671
+ * Paths should be absolute.
672
+ */
579
673
  additionalDirectories?: string[];
674
+ /**
675
+ * Programmatically define custom subagents that can be invoked via the Task tool.
676
+ * Keys are agent names, values are agent definitions.
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * agents: {
681
+ * 'code-reviewer': {
682
+ * description: 'Reviews code for bugs and style issues',
683
+ * prompt: 'You are a code reviewer...',
684
+ * tools: ['Read', 'Grep', 'Glob']
685
+ * }
686
+ * }
687
+ * ```
688
+ */
580
689
  agents?: Record<string, AgentDefinition>;
690
+ /**
691
+ * List of tool names that are allowed. When specified, only these tools
692
+ * will be available. Use with `disallowedTools` to fine-tune tool access.
693
+ */
581
694
  allowedTools?: string[];
695
+ /**
696
+ * Custom permission handler for controlling tool usage. Called before each
697
+ * tool execution to determine if it should be allowed, denied, or prompt the user.
698
+ */
582
699
  canUseTool?: CanUseTool;
700
+ /**
701
+ * Continue the most recent conversation instead of starting a new one.
702
+ * Mutually exclusive with `resume`.
703
+ */
583
704
  continue?: boolean;
705
+ /**
706
+ * Current working directory for the session. Defaults to `process.cwd()`.
707
+ */
584
708
  cwd?: string;
709
+ /**
710
+ * List of tool names that are disallowed. These tools will not be available
711
+ * even if they would otherwise be allowed.
712
+ */
585
713
  disallowedTools?: string[];
586
714
  /**
587
715
  * Specify the base set of available built-in tools.
@@ -593,30 +721,133 @@ export type Options = {
593
721
  type: 'preset';
594
722
  preset: 'claude_code';
595
723
  };
724
+ /**
725
+ * Environment variables to pass to the Claude Code process.
726
+ * Defaults to `process.env`.
727
+ */
596
728
  env?: {
597
729
  [envVar: string]: string | undefined;
598
730
  };
731
+ /**
732
+ * JavaScript runtime to use for executing Claude Code.
733
+ * Auto-detected if not specified.
734
+ */
599
735
  executable?: 'bun' | 'deno' | 'node';
736
+ /**
737
+ * Additional arguments to pass to the JavaScript runtime executable.
738
+ */
600
739
  executableArgs?: string[];
740
+ /**
741
+ * Additional CLI arguments to pass to Claude Code.
742
+ * Keys are argument names (without --), values are argument values.
743
+ * Use `null` for boolean flags.
744
+ */
601
745
  extraArgs?: Record<string, string | null>;
746
+ /**
747
+ * Fallback model to use if the primary model fails or is unavailable.
748
+ */
602
749
  fallbackModel?: string;
603
750
  /**
604
- * When true resumed sessions will fork to a new session ID rather than
605
- * continuing the previous session. Use with --resume.
751
+ * When true, resumed sessions will fork to a new session ID rather than
752
+ * continuing the previous session. Use with `resume`.
606
753
  */
607
754
  forkSession?: boolean;
755
+ /**
756
+ * Enable beta features. Currently supported:
757
+ * - `'context-1m-2025-08-07'` - Enable 1M token context window (Sonnet 4/4.5 only)
758
+ *
759
+ * @see https://docs.anthropic.com/en/api/beta-headers
760
+ */
608
761
  betas?: SdkBeta[];
762
+ /**
763
+ * Hook callbacks for responding to various events during execution.
764
+ * Hooks can modify behavior, add context, or implement custom logic.
765
+ *
766
+ * @example
767
+ * ```typescript
768
+ * hooks: {
769
+ * PreToolUse: [{
770
+ * hooks: [async (input) => ({ continue: true })]
771
+ * }]
772
+ * }
773
+ * ```
774
+ */
609
775
  hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
776
+ /**
777
+ * Include partial/streaming message events in the output.
778
+ * When true, `SDKPartialAssistantMessage` events will be emitted during streaming.
779
+ */
610
780
  includePartialMessages?: boolean;
781
+ /**
782
+ * Maximum number of tokens the model can use for its thinking/reasoning process.
783
+ * Helps control cost and latency for complex tasks.
784
+ */
611
785
  maxThinkingTokens?: number;
786
+ /**
787
+ * Maximum number of conversation turns before the query stops.
788
+ * A turn consists of a user message and assistant response.
789
+ */
612
790
  maxTurns?: number;
791
+ /**
792
+ * Maximum budget in USD for the query. The query will stop if this
793
+ * budget is exceeded, returning an `error_max_budget_usd` result.
794
+ */
613
795
  maxBudgetUsd?: number;
796
+ /**
797
+ * MCP (Model Context Protocol) server configurations.
798
+ * Keys are server names, values are server configurations.
799
+ *
800
+ * @example
801
+ * ```typescript
802
+ * mcpServers: {
803
+ * 'my-server': {
804
+ * command: 'node',
805
+ * args: ['./my-mcp-server.js']
806
+ * }
807
+ * }
808
+ * ```
809
+ */
614
810
  mcpServers?: Record<string, McpServerConfig>;
811
+ /**
812
+ * Claude model to use. Defaults to the CLI default model.
813
+ * Examples: 'claude-sonnet-4-5-20250929', 'claude-opus-4-20250514'
814
+ */
615
815
  model?: string;
816
+ /**
817
+ * Output format configuration for structured responses.
818
+ * When specified, the agent will return structured data matching the schema.
819
+ *
820
+ * @example
821
+ * ```typescript
822
+ * outputFormat: {
823
+ * type: 'json_schema',
824
+ * schema: { type: 'object', properties: { result: { type: 'string' } } }
825
+ * }
826
+ * ```
827
+ */
616
828
  outputFormat?: OutputFormat;
829
+ /**
830
+ * Path to the Claude Code executable. Uses the built-in executable if not specified.
831
+ */
617
832
  pathToClaudeCodeExecutable?: string;
833
+ /**
834
+ * Permission mode for the session.
835
+ * - `'default'` - Standard permission behavior, prompts for dangerous operations
836
+ * - `'acceptEdits'` - Auto-accept file edit operations
837
+ * - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
838
+ * - `'plan'` - Planning mode, no execution of tools
839
+ * - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
840
+ */
618
841
  permissionMode?: PermissionMode;
842
+ /**
843
+ * Must be set to `true` when using `permissionMode: 'bypassPermissions'`.
844
+ * This is a safety measure to ensure intentional bypassing of permissions.
845
+ */
619
846
  allowDangerouslySkipPermissions?: boolean;
847
+ /**
848
+ * MCP tool name to use for permission prompts. When set, permission requests
849
+ * will be routed through this MCP tool instead of the default handler.
850
+ */
620
851
  permissionPromptToolName?: string;
621
852
  /**
622
853
  * Load plugins for this session. Plugins provide custom commands, agents,
@@ -633,11 +864,14 @@ export type Options = {
633
864
  * ```
634
865
  */
635
866
  plugins?: SdkPluginConfig[];
867
+ /**
868
+ * Session ID to resume. Loads the conversation history from the specified session.
869
+ */
636
870
  resume?: string;
637
871
  /**
638
- * When resuming, only resume messages up to and including the message with this message.uuid.
639
- * Use with --resume. This allows you to resume from a specific point in the conversation.
640
- * The message ID is expected to be from SDKAssistantMessage.uuid.
872
+ * When resuming, only resume messages up to and including the message with this UUID.
873
+ * Use with `resume`. This allows you to resume from a specific point in the conversation.
874
+ * The message ID should be from `SDKAssistantMessage.uuid`.
641
875
  */
642
876
  resumeSessionAt?: string;
643
877
  /**
@@ -676,9 +910,46 @@ export type Options = {
676
910
  * @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
677
911
  */
678
912
  sandbox?: SandboxSettings;
913
+ /**
914
+ * Control which filesystem settings to load.
915
+ * - `'user'` - Global user settings (`~/.claude/settings.json`)
916
+ * - `'project'` - Project settings (`.claude/settings.json`)
917
+ * - `'local'` - Local settings (`.claude/settings.local.json`)
918
+ *
919
+ * When omitted or empty, no filesystem settings are loaded (SDK isolation mode).
920
+ * Must include `'project'` to load CLAUDE.md files.
921
+ */
679
922
  settingSources?: SettingSource[];
923
+ /**
924
+ * Callback for stderr output from the Claude Code process.
925
+ * Useful for debugging and logging.
926
+ */
680
927
  stderr?: (data: string) => void;
928
+ /**
929
+ * Enforce strict validation of MCP server configurations.
930
+ * When true, invalid configurations will cause errors instead of warnings.
931
+ */
681
932
  strictMcpConfig?: boolean;
933
+ /**
934
+ * System prompt configuration.
935
+ * - `string` - Use a custom system prompt
936
+ * - `{ type: 'preset', preset: 'claude_code' }` - Use Claude Code's default system prompt
937
+ * - `{ type: 'preset', preset: 'claude_code', append: '...' }` - Use default prompt with appended instructions
938
+ *
939
+ * @example Custom prompt
940
+ * ```typescript
941
+ * systemPrompt: 'You are a helpful coding assistant.'
942
+ * ```
943
+ *
944
+ * @example Default with additions
945
+ * ```typescript
946
+ * systemPrompt: {
947
+ * type: 'preset',
948
+ * preset: 'claude_code',
949
+ * append: 'Always explain your reasoning.'
950
+ * }
951
+ * ```
952
+ */
682
953
  systemPrompt?: string | {
683
954
  type: 'preset';
684
955
  preset: 'claude_code';
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://code.claude.com/docs/en/legal-and-compliance.
3
3
 
4
- // Version: 0.1.58
4
+ // Version: 0.1.60
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -15104,7 +15104,7 @@ function query({
15104
15104
  const dirname2 = join5(filename, "..");
15105
15105
  pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
15106
15106
  }
15107
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.58";
15107
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.60";
15108
15108
  const {
15109
15109
  abortController = createAbortController(),
15110
15110
  additionalDirectories = [],