@anthropic-ai/claude-agent-sdk 0.2.1 → 0.2.2

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/sdk.d.ts CHANGED
@@ -1 +1,1586 @@
1
- export * from './entrypoints/agentSdkTypes.d.ts';
1
+ import type { BetaMessage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
2
+ import type { BetaRawMessageStreamEvent } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
3
+ import type { BetaUsage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
4
+ import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
5
+ import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
6
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
+ import type { MessageParam } from '@anthropic-ai/sdk/resources';
8
+ import type { Readable } from 'stream';
9
+ import type { UUID } from 'crypto';
10
+ import type { Writable } from 'stream';
11
+ import { z } from 'zod/v4';
12
+ import type { ZodRawShape } from 'zod';
13
+ import type { ZodRawShape as ZodRawShape_2 } from 'zod/v4';
14
+
15
+ export declare class AbortError extends Error {
16
+ }
17
+
18
+ /**
19
+ * Information about the logged in user's account.
20
+ */
21
+ export declare type AccountInfo = {
22
+ email?: string;
23
+ organization?: string;
24
+ subscriptionType?: string;
25
+ tokenSource?: string;
26
+ apiKeySource?: string;
27
+ };
28
+
29
+ /**
30
+ * Definition for a custom subagent that can be invoked via the Task tool.
31
+ */
32
+ export declare type AgentDefinition = {
33
+ /**
34
+ * Natural language description of when to use this agent
35
+ */
36
+ description: string;
37
+ /**
38
+ * Array of allowed tool names. If omitted, inherits all tools from parent
39
+ */
40
+ tools?: string[];
41
+ /**
42
+ * Array of tool names to explicitly disallow for this agent
43
+ */
44
+ disallowedTools?: string[];
45
+ /**
46
+ * The agent's system prompt
47
+ */
48
+ prompt: string;
49
+ /**
50
+ * Model to use for this agent. If omitted or 'inherit', uses the main model
51
+ */
52
+ model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
53
+ mcpServers?: AgentMcpServerSpec[];
54
+ /**
55
+ * Experimental: Critical reminder added to system prompt
56
+ */
57
+ criticalSystemReminder_EXPERIMENTAL?: string;
58
+ };
59
+
60
+ export declare type AgentMcpServerSpec = string | Record<string, McpServerConfigForProcessTransport>;
61
+
62
+ export declare type AnyZodRawShape = ZodRawShape | ZodRawShape_2;
63
+
64
+ export declare type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';
65
+
66
+ export declare type AsyncHookJSONOutput = {
67
+ async: true;
68
+ asyncTimeout?: number;
69
+ };
70
+
71
+ export declare type BaseHookInput = {
72
+ session_id: string;
73
+ transcript_path: string;
74
+ cwd: string;
75
+ permission_mode?: string;
76
+ };
77
+
78
+ export declare type BaseOutputFormat = {
79
+ type: OutputFormatType;
80
+ };
81
+
82
+ /**
83
+ * Permission callback function for controlling tool usage.
84
+ * Called before each tool execution to determine if it should be allowed.
85
+ */
86
+ export declare type CanUseTool = (toolName: string, input: Record<string, unknown>, options: {
87
+ /** Signaled if the operation should be aborted. */
88
+ signal: AbortSignal;
89
+ /**
90
+ * Suggestions for updating permissions so that the user will not be
91
+ * prompted again for this tool during this session.
92
+ *
93
+ * Typically if presenting the user an option 'always allow' or similar,
94
+ * then this full set of suggestions should be returned as the
95
+ * `updatedPermissions` in the PermissionResult.
96
+ */
97
+ suggestions?: PermissionUpdate[];
98
+ /**
99
+ * The file path that triggered the permission request, if applicable.
100
+ * For example, when a Bash command tries to access a path outside allowed directories.
101
+ */
102
+ blockedPath?: string;
103
+ /** Explains why this permission request was triggered. */
104
+ decisionReason?: string;
105
+ /**
106
+ * Unique identifier for this specific tool call within the assistant message.
107
+ * Multiple tool calls in the same assistant message will have different toolUseIDs.
108
+ */
109
+ toolUseID: string;
110
+ /** If running within the context of a sub-agent, the sub-agent's ID. */
111
+ agentID?: string;
112
+ }) => Promise<PermissionResult>;
113
+
114
+ /**
115
+ * Config scope for settings.
116
+ */
117
+ export declare type ConfigScope = 'local' | 'user' | 'project';
118
+
119
+ declare type ControlErrorResponse = {
120
+ subtype: 'error';
121
+ request_id: string;
122
+ error: string;
123
+ pending_permission_requests?: SDKControlRequest[];
124
+ };
125
+
126
+ declare type ControlResponse = {
127
+ subtype: 'success';
128
+ request_id: string;
129
+ response?: Record<string, unknown>;
130
+ };
131
+
132
+ declare namespace coreTypes {
133
+ export {
134
+ SandboxSettings,
135
+ SandboxNetworkConfig,
136
+ SandboxIgnoreViolations,
137
+ NonNullableUsage,
138
+ HOOK_EVENTS,
139
+ EXIT_REASONS,
140
+ AccountInfo,
141
+ AgentDefinition,
142
+ AgentMcpServerSpec,
143
+ ApiKeySource,
144
+ AsyncHookJSONOutput,
145
+ BaseHookInput,
146
+ BaseOutputFormat,
147
+ ConfigScope,
148
+ ExitReason,
149
+ HookEvent,
150
+ HookInput,
151
+ HookJSONOutput,
152
+ JsonSchemaOutputFormat,
153
+ McpHttpServerConfig,
154
+ McpSSEServerConfig,
155
+ McpSdkServerConfig,
156
+ McpServerConfigForProcessTransport,
157
+ McpServerStatus,
158
+ McpSetServersResult,
159
+ McpStdioServerConfig,
160
+ ModelInfo,
161
+ ModelUsage,
162
+ NotificationHookInput,
163
+ OutputFormat,
164
+ OutputFormatType,
165
+ PermissionBehavior,
166
+ PermissionMode,
167
+ PermissionRequestHookInput,
168
+ PermissionRequestHookSpecificOutput,
169
+ PermissionResult,
170
+ PermissionRuleValue,
171
+ PermissionUpdateDestination,
172
+ PermissionUpdate,
173
+ PostToolUseFailureHookInput,
174
+ PostToolUseFailureHookSpecificOutput,
175
+ PostToolUseHookInput,
176
+ PostToolUseHookSpecificOutput,
177
+ PreCompactHookInput,
178
+ PreToolUseHookInput,
179
+ PreToolUseHookSpecificOutput,
180
+ RewindFilesResult,
181
+ SDKAssistantMessageError,
182
+ SDKAssistantMessage,
183
+ SDKAuthStatusMessage,
184
+ SDKCompactBoundaryMessage,
185
+ SDKHookResponseMessage,
186
+ SDKMessage,
187
+ SDKPartialAssistantMessage,
188
+ SDKPermissionDenial,
189
+ SDKResultError,
190
+ SDKResultMessage,
191
+ SDKResultSuccess,
192
+ SDKStatusMessage,
193
+ SDKStatus,
194
+ SDKSystemMessage,
195
+ SDKToolProgressMessage,
196
+ SDKUserMessageReplay,
197
+ SDKUserMessage,
198
+ SdkBeta,
199
+ SdkPluginConfig,
200
+ SessionEndHookInput,
201
+ SessionStartHookInput,
202
+ SessionStartHookSpecificOutput,
203
+ SettingSource,
204
+ SlashCommand,
205
+ StopHookInput,
206
+ SubagentStartHookInput,
207
+ SubagentStartHookSpecificOutput,
208
+ SubagentStopHookInput,
209
+ SyncHookJSONOutput,
210
+ UserPromptSubmitHookInput,
211
+ UserPromptSubmitHookSpecificOutput
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Creates an MCP server instance that can be used with the SDK transport.
217
+ * This allows SDK users to define custom tools that run in the same process.
218
+ *
219
+ * If your SDK MCP calls will run longer than 60s, override CLAUDE_CODE_STREAM_CLOSE_TIMEOUT
220
+ */
221
+ export declare function createSdkMcpServer(_options: CreateSdkMcpServerOptions): McpSdkServerConfigWithInstance;
222
+
223
+ declare type CreateSdkMcpServerOptions = {
224
+ name: string;
225
+ version?: string;
226
+ tools?: Array<SdkMcpToolDefinition<any>>;
227
+ };
228
+
229
+ export declare const EXIT_REASONS: readonly ["clear", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"];
230
+
231
+ export declare type ExitReason = 'clear' | 'logout' | 'prompt_input_exit' | 'other' | 'bypass_permissions_disabled';
232
+
233
+ export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
234
+
235
+ /**
236
+ * Hook callback function for responding to events during execution.
237
+ */
238
+ export declare type HookCallback = (input: HookInput, toolUseID: string | undefined, options: {
239
+ signal: AbortSignal;
240
+ }) => Promise<HookJSONOutput>;
241
+
242
+ /**
243
+ * Hook callback matcher containing hook callbacks and optional pattern matching.
244
+ */
245
+ export declare interface HookCallbackMatcher {
246
+ matcher?: string;
247
+ hooks: HookCallback[];
248
+ /** Timeout in seconds for all hooks in this matcher */
249
+ timeout?: number;
250
+ }
251
+
252
+ export declare type HookEvent = 'PreToolUse' | 'PostToolUse' | 'PostToolUseFailure' | 'Notification' | 'UserPromptSubmit' | 'SessionStart' | 'SessionEnd' | 'Stop' | 'SubagentStart' | 'SubagentStop' | 'PreCompact' | 'PermissionRequest';
253
+
254
+ export declare type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PermissionRequestHookInput;
255
+
256
+ export declare type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput;
257
+
258
+ export declare type InferShape<T extends AnyZodRawShape> = {
259
+ [K in keyof T]: T[K] extends {
260
+ _output: infer O;
261
+ } ? O : never;
262
+ } & {};
263
+
264
+ export declare type JsonSchemaOutputFormat = {
265
+ type: 'json_schema';
266
+ schema: Record<string, unknown>;
267
+ };
268
+
269
+ export declare type McpHttpServerConfig = {
270
+ type: 'http';
271
+ url: string;
272
+ headers?: Record<string, string>;
273
+ };
274
+
275
+ export declare type McpSdkServerConfig = {
276
+ type: 'sdk';
277
+ name: string;
278
+ };
279
+
280
+ /**
281
+ * MCP SDK server config with an actual McpServer instance.
282
+ * Not serializable - contains a live McpServer object.
283
+ */
284
+ export declare type McpSdkServerConfigWithInstance = McpSdkServerConfig & {
285
+ instance: McpServer;
286
+ };
287
+
288
+ /**
289
+ * Union of all MCP server config types, including those with non-serializable instances.
290
+ */
291
+ export declare type McpServerConfig = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig | McpSdkServerConfigWithInstance;
292
+
293
+ export declare type McpServerConfigForProcessTransport = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig | McpSdkServerConfig;
294
+
295
+ /**
296
+ * Status information for an MCP server connection.
297
+ */
298
+ export declare type McpServerStatus = {
299
+ /**
300
+ * Server name as configured
301
+ */
302
+ name: string;
303
+ /**
304
+ * Current connection status
305
+ */
306
+ status: 'connected' | 'failed' | 'needs-auth' | 'pending';
307
+ /**
308
+ * Server information (available when connected)
309
+ */
310
+ serverInfo?: {
311
+ name: string;
312
+ version: string;
313
+ };
314
+ /**
315
+ * Error message (available when status is 'failed')
316
+ */
317
+ error?: string;
318
+ };
319
+
320
+ /**
321
+ * Result of a setMcpServers operation.
322
+ */
323
+ export declare type McpSetServersResult = {
324
+ /**
325
+ * Names of servers that were added
326
+ */
327
+ added: string[];
328
+ /**
329
+ * Names of servers that were removed
330
+ */
331
+ removed: string[];
332
+ /**
333
+ * Map of server names to error messages for servers that failed to connect
334
+ */
335
+ errors: Record<string, string>;
336
+ };
337
+
338
+ export declare type McpSSEServerConfig = {
339
+ type: 'sse';
340
+ url: string;
341
+ headers?: Record<string, string>;
342
+ };
343
+
344
+ export declare type McpStdioServerConfig = {
345
+ type?: 'stdio';
346
+ command: string;
347
+ args?: string[];
348
+ env?: Record<string, string>;
349
+ };
350
+
351
+ /**
352
+ * Information about an available model.
353
+ */
354
+ export declare type ModelInfo = {
355
+ /**
356
+ * Model identifier to use in API calls
357
+ */
358
+ value: string;
359
+ /**
360
+ * Human-readable display name
361
+ */
362
+ displayName: string;
363
+ /**
364
+ * Description of the model's capabilities
365
+ */
366
+ description: string;
367
+ };
368
+
369
+ export declare type ModelUsage = {
370
+ inputTokens: number;
371
+ outputTokens: number;
372
+ cacheReadInputTokens: number;
373
+ cacheCreationInputTokens: number;
374
+ webSearchRequests: number;
375
+ costUSD: number;
376
+ contextWindow: number;
377
+ };
378
+
379
+ export declare type NonNullableUsage = {
380
+ [K in keyof BetaUsage]: NonNullable<BetaUsage[K]>;
381
+ };
382
+
383
+ export declare type NotificationHookInput = BaseHookInput & {
384
+ hook_event_name: 'Notification';
385
+ message: string;
386
+ title?: string;
387
+ notification_type: string;
388
+ };
389
+
390
+ /**
391
+ * Options for the query function.
392
+ * Contains callbacks and other non-serializable fields.
393
+ */
394
+ export declare type Options = {
395
+ /**
396
+ * Controller for cancelling the query. When aborted, the query will stop
397
+ * and clean up resources.
398
+ */
399
+ abortController?: AbortController;
400
+ /**
401
+ * Additional directories Claude can access beyond the current working directory.
402
+ * Paths should be absolute.
403
+ */
404
+ additionalDirectories?: string[];
405
+ /**
406
+ * Programmatically define custom subagents that can be invoked via the Task tool.
407
+ * Keys are agent names, values are agent definitions.
408
+ *
409
+ * @example
410
+ * ```typescript
411
+ * agents: {
412
+ * 'test-runner': {
413
+ * description: 'Runs tests and reports results',
414
+ * prompt: 'You are a test runner...',
415
+ * tools: ['Read', 'Grep', 'Glob', 'Bash']
416
+ * }
417
+ * }
418
+ * ```
419
+ */
420
+ agents?: Record<string, AgentDefinition>;
421
+ /**
422
+ * List of tool names that are auto-allowed without prompting for permission.
423
+ * These tools will execute automatically without asking the user for approval.
424
+ * To restrict which tools are available, use the `tools` option instead.
425
+ */
426
+ allowedTools?: string[];
427
+ /**
428
+ * Custom permission handler for controlling tool usage. Called before each
429
+ * tool execution to determine if it should be allowed, denied, or prompt the user.
430
+ */
431
+ canUseTool?: CanUseTool;
432
+ /**
433
+ * Continue the most recent conversation in the current directory instead of starting a new one.
434
+ * Mutually exclusive with `resume`.
435
+ */
436
+ continue?: boolean;
437
+ /**
438
+ * Current working directory for the session. Defaults to `process.cwd()`.
439
+ */
440
+ cwd?: string;
441
+ /**
442
+ * List of tool names that are disallowed. These tools will be removed
443
+ * from the model's context and cannot be used, even if they would
444
+ * otherwise be allowed.
445
+ */
446
+ disallowedTools?: string[];
447
+ /**
448
+ * Specify the base set of available built-in tools.
449
+ * - `string[]` - Array of specific tool names (e.g., `['Bash', 'Read', 'Edit']`)
450
+ * - `[]` (empty array) - Disable all built-in tools
451
+ * - `{ type: 'preset'; preset: 'claude_code' }` - Use all default Claude Code tools
452
+ */
453
+ tools?: string[] | {
454
+ type: 'preset';
455
+ preset: 'claude_code';
456
+ };
457
+ /**
458
+ * Environment variables to pass to the Claude Code process.
459
+ * Defaults to `process.env`.
460
+ */
461
+ env?: {
462
+ [envVar: string]: string | undefined;
463
+ };
464
+ /**
465
+ * JavaScript runtime to use for executing Claude Code.
466
+ * Auto-detected if not specified.
467
+ */
468
+ executable?: 'bun' | 'deno' | 'node';
469
+ /**
470
+ * Additional arguments to pass to the JavaScript runtime executable.
471
+ */
472
+ executableArgs?: string[];
473
+ /**
474
+ * Additional CLI arguments to pass to Claude Code.
475
+ * Keys are argument names (without --), values are argument values.
476
+ * Use `null` for boolean flags.
477
+ */
478
+ extraArgs?: Record<string, string | null>;
479
+ /**
480
+ * Fallback model to use if the primary model fails or is unavailable.
481
+ */
482
+ fallbackModel?: string;
483
+ /**
484
+ * Enable file checkpointing to track file changes during the session.
485
+ * When enabled, files can be rewound to their state at any user message
486
+ * using `Query.rewindFiles()`.
487
+ *
488
+ * File checkpointing creates backups of files before they are modified,
489
+ * allowing you to restore them to previous states.
490
+ */
491
+ enableFileCheckpointing?: boolean;
492
+ /**
493
+ * When true, resumed sessions will fork to a new session ID rather than
494
+ * continuing the previous session. Use with `resume`.
495
+ */
496
+ forkSession?: boolean;
497
+ /**
498
+ * Enable beta features. Currently supported:
499
+ * - `'context-1m-2025-08-07'` - Enable 1M token context window (Sonnet 4/4.5 only)
500
+ *
501
+ * @see https://docs.anthropic.com/en/api/beta-headers
502
+ */
503
+ betas?: SdkBeta[];
504
+ /**
505
+ * Hook callbacks for responding to various events during execution.
506
+ * Hooks can modify behavior, add context, or implement custom logic.
507
+ *
508
+ * @example
509
+ * ```typescript
510
+ * hooks: {
511
+ * PreToolUse: [{
512
+ * hooks: [async (input) => ({ continue: true })]
513
+ * }]
514
+ * }
515
+ * ```
516
+ */
517
+ hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
518
+ /**
519
+ * When false, disables session persistence to disk. Sessions will not be
520
+ * saved to ~/.claude/projects/ and cannot be resumed later. Useful for
521
+ * ephemeral or automated workflows where session history is not needed.
522
+ *
523
+ * @default true
524
+ */
525
+ persistSession?: boolean;
526
+ /**
527
+ * Include partial/streaming message events in the output.
528
+ * When true, `SDKPartialAssistantMessage` events will be emitted during streaming.
529
+ */
530
+ includePartialMessages?: boolean;
531
+ /**
532
+ * Maximum number of tokens the model can use for its thinking/reasoning process.
533
+ * Helps control cost and latency for complex tasks.
534
+ */
535
+ maxThinkingTokens?: number;
536
+ /**
537
+ * Maximum number of conversation turns before the query stops.
538
+ * A turn consists of a user message and assistant response.
539
+ */
540
+ maxTurns?: number;
541
+ /**
542
+ * Maximum budget in USD for the query. The query will stop if this
543
+ * budget is exceeded, returning an `error_max_budget_usd` result.
544
+ */
545
+ maxBudgetUsd?: number;
546
+ /**
547
+ * MCP (Model Context Protocol) server configurations.
548
+ * Keys are server names, values are server configurations.
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * mcpServers: {
553
+ * 'my-server': {
554
+ * command: 'node',
555
+ * args: ['./my-mcp-server.js']
556
+ * }
557
+ * }
558
+ * ```
559
+ */
560
+ mcpServers?: Record<string, McpServerConfig>;
561
+ /**
562
+ * Claude model to use. Defaults to the CLI default model.
563
+ * Examples: 'claude-sonnet-4-5-20250929', 'claude-opus-4-20250514'
564
+ */
565
+ model?: string;
566
+ /**
567
+ * Output format configuration for structured responses.
568
+ * When specified, the agent will return structured data matching the schema.
569
+ *
570
+ * @example
571
+ * ```typescript
572
+ * outputFormat: {
573
+ * type: 'json_schema',
574
+ * schema: { type: 'object', properties: { result: { type: 'string' } } }
575
+ * }
576
+ * ```
577
+ */
578
+ outputFormat?: OutputFormat;
579
+ /**
580
+ * Path to the Claude Code executable. Uses the built-in executable if not specified.
581
+ */
582
+ pathToClaudeCodeExecutable?: string;
583
+ /**
584
+ * Permission mode for the session.
585
+ * - `'default'` - Standard permission behavior, prompts for dangerous operations
586
+ * - `'acceptEdits'` - Auto-accept file edit operations
587
+ * - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
588
+ * - `'plan'` - Planning mode, no execution of tools
589
+ * - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
590
+ */
591
+ permissionMode?: PermissionMode;
592
+ /**
593
+ * Must be set to `true` when using `permissionMode: 'bypassPermissions'`.
594
+ * This is a safety measure to ensure intentional bypassing of permissions.
595
+ */
596
+ allowDangerouslySkipPermissions?: boolean;
597
+ /**
598
+ * MCP tool name to use for permission prompts. When set, permission requests
599
+ * will be routed through this MCP tool instead of the default handler.
600
+ */
601
+ permissionPromptToolName?: string;
602
+ /**
603
+ * Load plugins for this session. Plugins provide custom commands, agents,
604
+ * skills, and hooks that extend Claude Code's capabilities.
605
+ *
606
+ * Currently only local plugins are supported via the 'local' type.
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * plugins: [
611
+ * { type: 'local', path: './my-plugin' },
612
+ * { type: 'local', path: '/absolute/path/to/plugin' }
613
+ * ]
614
+ * ```
615
+ */
616
+ plugins?: SdkPluginConfig[];
617
+ /**
618
+ * Session ID to resume. Loads the conversation history from the specified session.
619
+ */
620
+ resume?: string;
621
+ /**
622
+ * When resuming, only resume messages up to and including the message with this UUID.
623
+ * Use with `resume`. This allows you to resume from a specific point in the conversation.
624
+ * The message ID should be from `SDKAssistantMessage.uuid`.
625
+ */
626
+ resumeSessionAt?: string;
627
+ /**
628
+ * Sandbox settings for command execution isolation.
629
+ *
630
+ * When enabled, commands are executed in a sandboxed environment that restricts
631
+ * filesystem and network access. This provides an additional security layer.
632
+ *
633
+ * **Important:** Filesystem and network restrictions are configured via permission
634
+ * rules, not via these sandbox settings:
635
+ * - Filesystem access: Use `Read` and `Edit` permission rules
636
+ * - Network access: Use `WebFetch` permission rules
637
+ *
638
+ * These sandbox settings control sandbox behavior (enabled, auto-allow, etc.),
639
+ * while the actual access restrictions come from your permission configuration.
640
+ *
641
+ * @example Enable sandboxing with auto-allow
642
+ * ```typescript
643
+ * sandbox: {
644
+ * enabled: true,
645
+ * autoAllowBashIfSandboxed: true
646
+ * }
647
+ * ```
648
+ *
649
+ * @example Configure network options (not restrictions)
650
+ * ```typescript
651
+ * sandbox: {
652
+ * enabled: true,
653
+ * network: {
654
+ * allowLocalBinding: true,
655
+ * allowUnixSockets: ['/var/run/docker.sock']
656
+ * }
657
+ * }
658
+ * ```
659
+ *
660
+ * @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
661
+ */
662
+ sandbox?: SandboxSettings;
663
+ /**
664
+ * Control which filesystem settings to load.
665
+ * - `'user'` - Global user settings (`~/.claude/settings.json`)
666
+ * - `'project'` - Project settings (`.claude/settings.json`)
667
+ * - `'local'` - Local settings (`.claude/settings.local.json`)
668
+ *
669
+ * When omitted or empty, no filesystem settings are loaded (SDK isolation mode).
670
+ * Must include `'project'` to load CLAUDE.md files.
671
+ */
672
+ settingSources?: SettingSource[];
673
+ /**
674
+ * Callback for stderr output from the Claude Code process.
675
+ * Useful for debugging and logging.
676
+ */
677
+ stderr?: (data: string) => void;
678
+ /**
679
+ * Enforce strict validation of MCP server configurations.
680
+ * When true, invalid configurations will cause errors instead of warnings.
681
+ */
682
+ strictMcpConfig?: boolean;
683
+ /**
684
+ * System prompt configuration.
685
+ * - `string` - Use a custom system prompt
686
+ * - `{ type: 'preset', preset: 'claude_code' }` - Use Claude Code's default system prompt
687
+ * - `{ type: 'preset', preset: 'claude_code', append: '...' }` - Use default prompt with appended instructions
688
+ *
689
+ * @example Custom prompt
690
+ * ```typescript
691
+ * systemPrompt: 'You are a helpful coding assistant.'
692
+ * ```
693
+ *
694
+ * @example Default with additions
695
+ * ```typescript
696
+ * systemPrompt: {
697
+ * type: 'preset',
698
+ * preset: 'claude_code',
699
+ * append: 'Always explain your reasoning.'
700
+ * }
701
+ * ```
702
+ */
703
+ systemPrompt?: string | {
704
+ type: 'preset';
705
+ preset: 'claude_code';
706
+ append?: string;
707
+ };
708
+ /**
709
+ * Custom function to spawn the Claude Code process.
710
+ * Use this to run Claude Code in VMs, containers, or remote environments.
711
+ *
712
+ * When provided, this function is called instead of the default local spawn.
713
+ * The default behavior checks if the executable exists before spawning.
714
+ *
715
+ * @example
716
+ * ```typescript
717
+ * spawnClaudeCodeProcess: (options) => {
718
+ * // Custom spawn logic for VM execution
719
+ * // options contains: command, args, cwd, env, signal
720
+ * return myVMProcess; // Must satisfy SpawnedProcess interface
721
+ * }
722
+ * ```
723
+ */
724
+ spawnClaudeCodeProcess?: (options: SpawnOptions) => SpawnedProcess;
725
+ };
726
+
727
+ export declare type OutputFormat = JsonSchemaOutputFormat;
728
+
729
+ export declare type OutputFormatType = 'json_schema';
730
+
731
+ export declare type PermissionBehavior = 'allow' | 'deny' | 'ask';
732
+
733
+ /**
734
+ * Permission mode for controlling how tool executions are handled. 'default' - Standard behavior, prompts for dangerous operations. 'acceptEdits' - Auto-accept file edit operations. 'bypassPermissions' - Bypass all permission checks (requires allowDangerouslySkipPermissions). 'plan' - Planning mode, no actual tool execution. 'delegate' - Delegate mode, restricts team leader to only Teammate and Task tools. 'dontAsk' - Don't prompt for permissions, deny if not pre-approved.
735
+ */
736
+ export declare type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'delegate' | 'dontAsk';
737
+
738
+ export declare type PermissionRequestHookInput = BaseHookInput & {
739
+ hook_event_name: 'PermissionRequest';
740
+ tool_name: string;
741
+ tool_input: unknown;
742
+ permission_suggestions?: PermissionUpdate[];
743
+ };
744
+
745
+ export declare type PermissionRequestHookSpecificOutput = {
746
+ hookEventName: 'PermissionRequest';
747
+ decision: {
748
+ behavior: 'allow';
749
+ updatedInput?: Record<string, unknown>;
750
+ updatedPermissions?: PermissionUpdate[];
751
+ } | {
752
+ behavior: 'deny';
753
+ message?: string;
754
+ interrupt?: boolean;
755
+ };
756
+ };
757
+
758
+ export declare type PermissionResult = {
759
+ behavior: 'allow';
760
+ updatedInput?: Record<string, unknown>;
761
+ updatedPermissions?: PermissionUpdate[];
762
+ toolUseID?: string;
763
+ } | {
764
+ behavior: 'deny';
765
+ message: string;
766
+ interrupt?: boolean;
767
+ toolUseID?: string;
768
+ };
769
+
770
+ export declare type PermissionRuleValue = {
771
+ toolName: string;
772
+ ruleContent?: string;
773
+ };
774
+
775
+ export declare type PermissionUpdate = {
776
+ type: 'addRules';
777
+ rules: PermissionRuleValue[];
778
+ behavior: PermissionBehavior;
779
+ destination: PermissionUpdateDestination;
780
+ } | {
781
+ type: 'replaceRules';
782
+ rules: PermissionRuleValue[];
783
+ behavior: PermissionBehavior;
784
+ destination: PermissionUpdateDestination;
785
+ } | {
786
+ type: 'removeRules';
787
+ rules: PermissionRuleValue[];
788
+ behavior: PermissionBehavior;
789
+ destination: PermissionUpdateDestination;
790
+ } | {
791
+ type: 'setMode';
792
+ mode: PermissionMode;
793
+ destination: PermissionUpdateDestination;
794
+ } | {
795
+ type: 'addDirectories';
796
+ directories: string[];
797
+ destination: PermissionUpdateDestination;
798
+ } | {
799
+ type: 'removeDirectories';
800
+ directories: string[];
801
+ destination: PermissionUpdateDestination;
802
+ };
803
+
804
+ export declare type PermissionUpdateDestination = 'userSettings' | 'projectSettings' | 'localSettings' | 'session' | 'cliArg';
805
+
806
+ export declare type PostToolUseFailureHookInput = BaseHookInput & {
807
+ hook_event_name: 'PostToolUseFailure';
808
+ tool_name: string;
809
+ tool_input: unknown;
810
+ tool_use_id: string;
811
+ error: string;
812
+ is_interrupt?: boolean;
813
+ };
814
+
815
+ export declare type PostToolUseFailureHookSpecificOutput = {
816
+ hookEventName: 'PostToolUseFailure';
817
+ additionalContext?: string;
818
+ };
819
+
820
+ export declare type PostToolUseHookInput = BaseHookInput & {
821
+ hook_event_name: 'PostToolUse';
822
+ tool_name: string;
823
+ tool_input: unknown;
824
+ tool_response: unknown;
825
+ tool_use_id: string;
826
+ };
827
+
828
+ export declare type PostToolUseHookSpecificOutput = {
829
+ hookEventName: 'PostToolUse';
830
+ additionalContext?: string;
831
+ updatedMCPToolOutput?: unknown;
832
+ };
833
+
834
+ export declare type PreCompactHookInput = BaseHookInput & {
835
+ hook_event_name: 'PreCompact';
836
+ trigger: 'manual' | 'auto';
837
+ custom_instructions: string | null;
838
+ };
839
+
840
+ export declare type PreToolUseHookInput = BaseHookInput & {
841
+ hook_event_name: 'PreToolUse';
842
+ tool_name: string;
843
+ tool_input: unknown;
844
+ tool_use_id: string;
845
+ };
846
+
847
+ export declare type PreToolUseHookSpecificOutput = {
848
+ hookEventName: 'PreToolUse';
849
+ permissionDecision?: 'allow' | 'deny' | 'ask';
850
+ permissionDecisionReason?: string;
851
+ updatedInput?: Record<string, unknown>;
852
+ };
853
+
854
+ /**
855
+ * Query interface with methods for controlling query execution.
856
+ * Extends AsyncGenerator and has methods, so not serializable.
857
+ */
858
+ export declare interface Query extends AsyncGenerator<SDKMessage, void> {
859
+ /**
860
+ * Control Requests
861
+ * The following methods are control requests, and are only supported when
862
+ * streaming input/output is used.
863
+ */
864
+ /**
865
+ * Interrupt the current query execution. The query will stop processing
866
+ * and return control to the caller.
867
+ */
868
+ interrupt(): Promise<void>;
869
+ /**
870
+ * Change the permission mode for the current session.
871
+ * Only available in streaming input mode.
872
+ *
873
+ * @param mode - The new permission mode to set
874
+ */
875
+ setPermissionMode(mode: PermissionMode): Promise<void>;
876
+ /**
877
+ * Change the model used for subsequent responses.
878
+ * Only available in streaming input mode.
879
+ *
880
+ * @param model - The model identifier to use, or undefined to use the default
881
+ */
882
+ setModel(model?: string): Promise<void>;
883
+ /**
884
+ * Set the maximum number of thinking tokens the model is allowed to use
885
+ * when generating its response. This can be used to limit the amount of
886
+ * tokens the model uses for its response, which can help control cost and
887
+ * latency.
888
+ *
889
+ * Use `null` to clear any previously set limit and allow the model to
890
+ * use the default maximum thinking tokens.
891
+ *
892
+ * @param maxThinkingTokens - Maximum tokens for thinking, or null to clear the limit
893
+ */
894
+ setMaxThinkingTokens(maxThinkingTokens: number | null): Promise<void>;
895
+ /**
896
+ * Get the list of available skills for the current session.
897
+ *
898
+ * @returns Array of available skills with their names and descriptions
899
+ */
900
+ supportedCommands(): Promise<SlashCommand[]>;
901
+ /**
902
+ * Get the list of available models.
903
+ *
904
+ * @returns Array of model information including display names and descriptions
905
+ */
906
+ supportedModels(): Promise<ModelInfo[]>;
907
+ /**
908
+ * Get the current status of all configured MCP servers.
909
+ *
910
+ * @returns Array of MCP server statuses (connected, failed, needs-auth, pending)
911
+ */
912
+ mcpServerStatus(): Promise<McpServerStatus[]>;
913
+ /**
914
+ * Get information about the authenticated account.
915
+ *
916
+ * @returns Account information including email, organization, and subscription type
917
+ */
918
+ accountInfo(): Promise<AccountInfo>;
919
+ /**
920
+ * Rewind tracked files to their state at a specific user message.
921
+ * Requires file checkpointing to be enabled via the `enableFileCheckpointing` option.
922
+ *
923
+ * @param userMessageId - UUID of the user message to rewind to
924
+ * @param options - Options object with optional `dryRun` boolean to preview changes without modifying files
925
+ * @returns Object with canRewind boolean, optional error message, and file change statistics
926
+ */
927
+ rewindFiles(userMessageId: string, options?: {
928
+ dryRun?: boolean;
929
+ }): Promise<RewindFilesResult>;
930
+ /**
931
+ * Dynamically set the MCP servers for this session.
932
+ * This replaces the current set of dynamically-added MCP servers with the provided set.
933
+ * Servers that are removed will be disconnected, and new servers will be connected.
934
+ *
935
+ * Supports both process-based servers (stdio, sse, http) and SDK servers (in-process).
936
+ * SDK servers are handled locally in the SDK process, while process-based servers
937
+ * are managed by the CLI subprocess.
938
+ *
939
+ * Note: This only affects servers added dynamically via this method or the SDK.
940
+ * Servers configured via settings files are not affected.
941
+ *
942
+ * @param servers - Record of server name to configuration. Pass an empty object to remove all dynamic servers.
943
+ * @returns Information about which servers were added, removed, and any connection errors
944
+ */
945
+ setMcpServers(servers: Record<string, McpServerConfig>): Promise<McpSetServersResult>;
946
+ /**
947
+ * Stream input messages to the query.
948
+ * Used internally for multi-turn conversations.
949
+ *
950
+ * @param stream - Async iterable of user messages to send
951
+ */
952
+ streamInput(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
953
+ }
954
+
955
+ export declare function query(_params: {
956
+ prompt: string | AsyncIterable<SDKUserMessage>;
957
+ options?: Options;
958
+ }): Query;
959
+
960
+ /**
961
+ * Result of a rewindFiles operation.
962
+ */
963
+ export declare type RewindFilesResult = {
964
+ canRewind: boolean;
965
+ error?: string;
966
+ filesChanged?: string[];
967
+ insertions?: number;
968
+ deletions?: number;
969
+ };
970
+
971
+ export declare type SandboxIgnoreViolations = NonNullable<SandboxSettings['ignoreViolations']>;
972
+
973
+ export declare type SandboxNetworkConfig = NonNullable<z.infer<typeof SandboxNetworkConfigSchema>>;
974
+
975
+ /**
976
+ * Network configuration schema for sandbox.
977
+ */
978
+ declare const SandboxNetworkConfigSchema: z.ZodOptional<z.ZodObject<{
979
+ allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
980
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString>>;
981
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
982
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
983
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
984
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
985
+ }, z.core.$strip>>;
986
+
987
+ export declare type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
988
+
989
+ /**
990
+ * Sandbox settings schema.
991
+ */
992
+ declare const SandboxSettingsSchema: z.ZodObject<{
993
+ enabled: z.ZodOptional<z.ZodBoolean>;
994
+ autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
995
+ allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
996
+ network: z.ZodOptional<z.ZodObject<{
997
+ allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
998
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString>>;
999
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
1000
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
1001
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
1002
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
1003
+ }, z.core.$strip>>;
1004
+ ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
1005
+ enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
1006
+ excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString>>;
1007
+ ripgrep: z.ZodOptional<z.ZodObject<{
1008
+ command: z.ZodString;
1009
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
1010
+ }, z.core.$strip>>;
1011
+ }, z.core.$loose>;
1012
+
1013
+ export declare type SDKAssistantMessage = {
1014
+ type: 'assistant';
1015
+ message: BetaMessage;
1016
+ parent_tool_use_id: string | null;
1017
+ error?: SDKAssistantMessageError;
1018
+ uuid: UUID;
1019
+ session_id: string;
1020
+ };
1021
+
1022
+ export declare type SDKAssistantMessageError = 'authentication_failed' | 'billing_error' | 'rate_limit' | 'invalid_request' | 'server_error' | 'unknown';
1023
+
1024
+ export declare type SDKAuthStatusMessage = {
1025
+ type: 'auth_status';
1026
+ isAuthenticating: boolean;
1027
+ output: string[];
1028
+ error?: string;
1029
+ uuid: UUID;
1030
+ session_id: string;
1031
+ };
1032
+
1033
+ export declare type SdkBeta = 'context-1m-2025-08-07';
1034
+
1035
+ export declare type SDKCompactBoundaryMessage = {
1036
+ type: 'system';
1037
+ subtype: 'compact_boundary';
1038
+ compact_metadata: {
1039
+ trigger: 'manual' | 'auto';
1040
+ pre_tokens: number;
1041
+ };
1042
+ uuid: UUID;
1043
+ session_id: string;
1044
+ };
1045
+
1046
+ /**
1047
+ * Cancels a currently open control request.
1048
+ */
1049
+ declare type SDKControlCancelRequest = {
1050
+ type: 'control_cancel_request';
1051
+ request_id: string;
1052
+ };
1053
+
1054
+ declare type SDKControlInitializeRequest = {
1055
+ subtype: 'initialize';
1056
+ hooks?: Partial<Record<coreTypes.HookEvent, SDKHookCallbackMatcher[]>>;
1057
+ sdkMcpServers?: string[];
1058
+ jsonSchema?: Record<string, unknown>;
1059
+ systemPrompt?: string;
1060
+ appendSystemPrompt?: string;
1061
+ agents?: Record<string, coreTypes.AgentDefinition>;
1062
+ };
1063
+
1064
+ declare type SDKControlInterruptRequest = {
1065
+ subtype: 'interrupt';
1066
+ };
1067
+
1068
+ declare type SDKControlMcpMessageRequest = {
1069
+ subtype: 'mcp_message';
1070
+ server_name: string;
1071
+ message: JSONRPCMessage;
1072
+ };
1073
+
1074
+ declare type SDKControlMcpSetServersRequest = {
1075
+ subtype: 'mcp_set_servers';
1076
+ servers: Record<string, coreTypes.McpServerConfigForProcessTransport>;
1077
+ };
1078
+
1079
+ declare type SDKControlMcpStatusRequest = {
1080
+ subtype: 'mcp_status';
1081
+ };
1082
+
1083
+ declare type SDKControlPermissionRequest = {
1084
+ subtype: 'can_use_tool';
1085
+ tool_name: string;
1086
+ input: Record<string, unknown>;
1087
+ permission_suggestions?: coreTypes.PermissionUpdate[];
1088
+ blocked_path?: string;
1089
+ decision_reason?: string;
1090
+ tool_use_id: string;
1091
+ agent_id?: string;
1092
+ };
1093
+
1094
+ declare type SDKControlRequest = {
1095
+ type: 'control_request';
1096
+ request_id: string;
1097
+ request: SDKControlRequestInner;
1098
+ };
1099
+
1100
+ declare type SDKControlRequestInner = SDKControlInterruptRequest | SDKControlPermissionRequest | SDKControlInitializeRequest | SDKControlSetPermissionModeRequest | SDKControlSetModelRequest | SDKControlSetMaxThinkingTokensRequest | SDKControlMcpStatusRequest | SDKHookCallbackRequest | SDKControlMcpMessageRequest | SDKControlRewindFilesRequest | SDKControlMcpSetServersRequest;
1101
+
1102
+ declare type SDKControlResponse = {
1103
+ type: 'control_response';
1104
+ response: ControlResponse | ControlErrorResponse;
1105
+ };
1106
+
1107
+ declare type SDKControlRewindFilesRequest = {
1108
+ subtype: 'rewind_files';
1109
+ user_message_id: string;
1110
+ dry_run?: boolean;
1111
+ };
1112
+
1113
+ declare type SDKControlSetMaxThinkingTokensRequest = {
1114
+ subtype: 'set_max_thinking_tokens';
1115
+ max_thinking_tokens: number | null;
1116
+ };
1117
+
1118
+ declare type SDKControlSetModelRequest = {
1119
+ subtype: 'set_model';
1120
+ model?: string;
1121
+ };
1122
+
1123
+ declare type SDKControlSetPermissionModeRequest = {
1124
+ subtype: 'set_permission_mode';
1125
+ /**
1126
+ * Permission mode for controlling how tool executions are handled. 'default' - Standard behavior, prompts for dangerous operations. 'acceptEdits' - Auto-accept file edit operations. 'bypassPermissions' - Bypass all permission checks (requires allowDangerouslySkipPermissions). 'plan' - Planning mode, no actual tool execution. 'delegate' - Delegate mode, restricts team leader to only Teammate and Task tools. 'dontAsk' - Don't prompt for permissions, deny if not pre-approved.
1127
+ */
1128
+ mode: coreTypes.PermissionMode;
1129
+ };
1130
+
1131
+ /**
1132
+ * Configuration for matching and routing hook callbacks.
1133
+ */
1134
+ declare type SDKHookCallbackMatcher = {
1135
+ matcher?: string;
1136
+ hookCallbackIds: string[];
1137
+ timeout?: number;
1138
+ };
1139
+
1140
+ declare type SDKHookCallbackRequest = {
1141
+ subtype: 'hook_callback';
1142
+ callback_id: string;
1143
+ input: coreTypes.HookInput;
1144
+ tool_use_id?: string;
1145
+ };
1146
+
1147
+ export declare type SDKHookResponseMessage = {
1148
+ type: 'system';
1149
+ subtype: 'hook_response';
1150
+ hook_name: string;
1151
+ hook_event: string;
1152
+ stdout: string;
1153
+ stderr: string;
1154
+ exit_code?: number;
1155
+ uuid: UUID;
1156
+ session_id: string;
1157
+ };
1158
+
1159
+ /**
1160
+ * Keep-alive message to maintain WebSocket connection.
1161
+ */
1162
+ declare type SDKKeepAliveMessage = {
1163
+ type: 'keep_alive';
1164
+ };
1165
+
1166
+ /**
1167
+ * MCP tool definition for SDK servers.
1168
+ * Contains a handler function, so not serializable.
1169
+ * Supports both Zod 3 and Zod 4 schemas.
1170
+ */
1171
+ export declare type SdkMcpToolDefinition<Schema extends AnyZodRawShape = AnyZodRawShape> = {
1172
+ name: string;
1173
+ description: string;
1174
+ inputSchema: Schema;
1175
+ handler: (args: InferShape<Schema>, extra: unknown) => Promise<CallToolResult>;
1176
+ };
1177
+
1178
+ export declare type SDKMessage = SDKAssistantMessage | SDKUserMessage | SDKUserMessageReplay | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage | SDKCompactBoundaryMessage | SDKStatusMessage | SDKHookResponseMessage | SDKToolProgressMessage | SDKAuthStatusMessage;
1179
+
1180
+ export declare type SDKPartialAssistantMessage = {
1181
+ type: 'stream_event';
1182
+ event: BetaRawMessageStreamEvent;
1183
+ parent_tool_use_id: string | null;
1184
+ uuid: UUID;
1185
+ session_id: string;
1186
+ };
1187
+
1188
+ export declare type SDKPermissionDenial = {
1189
+ tool_name: string;
1190
+ tool_use_id: string;
1191
+ tool_input: Record<string, unknown>;
1192
+ };
1193
+
1194
+ /**
1195
+ * Configuration for loading a plugin.
1196
+ */
1197
+ export declare type SdkPluginConfig = {
1198
+ /**
1199
+ * Plugin type. Currently only 'local' is supported
1200
+ */
1201
+ type: 'local';
1202
+ /**
1203
+ * Absolute or relative path to the plugin directory
1204
+ */
1205
+ path: string;
1206
+ };
1207
+
1208
+ export declare type SDKResultError = {
1209
+ type: 'result';
1210
+ subtype: 'error_during_execution' | 'error_max_turns' | 'error_max_budget_usd' | 'error_max_structured_output_retries';
1211
+ duration_ms: number;
1212
+ duration_api_ms: number;
1213
+ is_error: boolean;
1214
+ num_turns: number;
1215
+ total_cost_usd: number;
1216
+ usage: NonNullableUsage;
1217
+ modelUsage: Record<string, ModelUsage>;
1218
+ permission_denials: SDKPermissionDenial[];
1219
+ errors: string[];
1220
+ uuid: UUID;
1221
+ session_id: string;
1222
+ };
1223
+
1224
+ export declare type SDKResultMessage = SDKResultSuccess | SDKResultError;
1225
+
1226
+ export declare type SDKResultSuccess = {
1227
+ type: 'result';
1228
+ subtype: 'success';
1229
+ duration_ms: number;
1230
+ duration_api_ms: number;
1231
+ is_error: boolean;
1232
+ num_turns: number;
1233
+ result: string;
1234
+ total_cost_usd: number;
1235
+ usage: NonNullableUsage;
1236
+ modelUsage: Record<string, ModelUsage>;
1237
+ permission_denials: SDKPermissionDenial[];
1238
+ structured_output?: unknown;
1239
+ uuid: UUID;
1240
+ session_id: string;
1241
+ };
1242
+
1243
+ /**
1244
+ * V2 API - UNSTABLE
1245
+ * Session interface for multi-turn conversations.
1246
+ * Has methods, so not serializable.
1247
+ */
1248
+ export declare interface SDKSession {
1249
+ /**
1250
+ * The session ID. Available after receiving the first message.
1251
+ * For resumed sessions, available immediately.
1252
+ * Throws if accessed before the session is initialized.
1253
+ */
1254
+ readonly sessionId: string;
1255
+ /** Send a message to the agent */
1256
+ send(message: string | SDKUserMessage): Promise<void>;
1257
+ /** Stream messages from the agent */
1258
+ stream(): AsyncGenerator<SDKMessage, void>;
1259
+ /** Close the session */
1260
+ close(): void;
1261
+ /** Async disposal support (calls close if not already closed) */
1262
+ [Symbol.asyncDispose](): Promise<void>;
1263
+ }
1264
+
1265
+ /**
1266
+ * V2 API - UNSTABLE
1267
+ * Options for creating a session.
1268
+ */
1269
+ export declare type SDKSessionOptions = {
1270
+ /** Model to use */
1271
+ model: string;
1272
+ /** Path to Claude Code executable */
1273
+ pathToClaudeCodeExecutable?: string;
1274
+ /** Executable to use (node, bun) */
1275
+ executable?: 'node' | 'bun';
1276
+ /** Arguments to pass to executable */
1277
+ executableArgs?: string[];
1278
+ /**
1279
+ * Environment variables to pass to the Claude Code process.
1280
+ * Defaults to `process.env`.
1281
+ */
1282
+ env?: {
1283
+ [envVar: string]: string | undefined;
1284
+ };
1285
+ /**
1286
+ * List of tool names that are auto-allowed without prompting for permission.
1287
+ * These tools will execute automatically without asking the user for approval.
1288
+ */
1289
+ allowedTools?: string[];
1290
+ /**
1291
+ * List of tool names that are disallowed. These tools will be removed
1292
+ * from the model's context and cannot be used.
1293
+ */
1294
+ disallowedTools?: string[];
1295
+ /**
1296
+ * Custom permission handler for controlling tool usage. Called before each
1297
+ * tool execution to determine if it should be allowed, denied, or prompt the user.
1298
+ */
1299
+ canUseTool?: CanUseTool;
1300
+ /**
1301
+ * Hook callbacks for responding to various events during execution.
1302
+ */
1303
+ hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
1304
+ /**
1305
+ * Permission mode for the session.
1306
+ * - `'default'` - Standard permission behavior, prompts for dangerous operations
1307
+ * - `'acceptEdits'` - Auto-accept file edit operations
1308
+ * - `'plan'` - Planning mode, no execution of tools
1309
+ * - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
1310
+ */
1311
+ permissionMode?: PermissionMode;
1312
+ };
1313
+
1314
+ export declare type SDKStatus = 'compacting' | null;
1315
+
1316
+ export declare type SDKStatusMessage = {
1317
+ type: 'system';
1318
+ subtype: 'status';
1319
+ status: SDKStatus;
1320
+ uuid: UUID;
1321
+ session_id: string;
1322
+ };
1323
+
1324
+ export declare type SDKSystemMessage = {
1325
+ type: 'system';
1326
+ subtype: 'init';
1327
+ agents?: string[];
1328
+ apiKeySource: ApiKeySource;
1329
+ betas?: string[];
1330
+ claude_code_version: string;
1331
+ cwd: string;
1332
+ tools: string[];
1333
+ mcp_servers: {
1334
+ name: string;
1335
+ status: string;
1336
+ }[];
1337
+ model: string;
1338
+ /**
1339
+ * Permission mode for controlling how tool executions are handled. 'default' - Standard behavior, prompts for dangerous operations. 'acceptEdits' - Auto-accept file edit operations. 'bypassPermissions' - Bypass all permission checks (requires allowDangerouslySkipPermissions). 'plan' - Planning mode, no actual tool execution. 'delegate' - Delegate mode, restricts team leader to only Teammate and Task tools. 'dontAsk' - Don't prompt for permissions, deny if not pre-approved.
1340
+ */
1341
+ permissionMode: PermissionMode;
1342
+ slash_commands: string[];
1343
+ output_style: string;
1344
+ skills: string[];
1345
+ plugins: {
1346
+ name: string;
1347
+ path: string;
1348
+ }[];
1349
+ uuid: UUID;
1350
+ session_id: string;
1351
+ };
1352
+
1353
+ export declare type SDKToolProgressMessage = {
1354
+ type: 'tool_progress';
1355
+ tool_use_id: string;
1356
+ tool_name: string;
1357
+ parent_tool_use_id: string | null;
1358
+ elapsed_time_seconds: number;
1359
+ uuid: UUID;
1360
+ session_id: string;
1361
+ };
1362
+
1363
+ export declare type SDKUserMessage = {
1364
+ type: 'user';
1365
+ message: MessageParam;
1366
+ parent_tool_use_id: string | null;
1367
+ isSynthetic?: boolean;
1368
+ tool_use_result?: unknown;
1369
+ uuid?: UUID;
1370
+ session_id: string;
1371
+ };
1372
+
1373
+ export declare type SDKUserMessageReplay = {
1374
+ type: 'user';
1375
+ message: MessageParam;
1376
+ parent_tool_use_id: string | null;
1377
+ isSynthetic?: boolean;
1378
+ tool_use_result?: unknown;
1379
+ uuid: UUID;
1380
+ session_id: string;
1381
+ isReplay: true;
1382
+ };
1383
+
1384
+ export declare type SessionEndHookInput = BaseHookInput & {
1385
+ hook_event_name: 'SessionEnd';
1386
+ reason: ExitReason;
1387
+ };
1388
+
1389
+ export declare type SessionStartHookInput = BaseHookInput & {
1390
+ hook_event_name: 'SessionStart';
1391
+ source: 'startup' | 'resume' | 'clear' | 'compact';
1392
+ agent_type?: string;
1393
+ };
1394
+
1395
+ export declare type SessionStartHookSpecificOutput = {
1396
+ hookEventName: 'SessionStart';
1397
+ additionalContext?: string;
1398
+ };
1399
+
1400
+ /**
1401
+ * Source for loading filesystem-based settings. 'user' - Global user settings (~/.claude/settings.json). 'project' - Project settings (.claude/settings.json). 'local' - Local settings (.claude/settings.local.json).
1402
+ */
1403
+ export declare type SettingSource = 'user' | 'project' | 'local';
1404
+
1405
+ /**
1406
+ * Information about an available skill (invoked via /command syntax).
1407
+ */
1408
+ export declare type SlashCommand = {
1409
+ /**
1410
+ * Skill name (without the leading slash)
1411
+ */
1412
+ name: string;
1413
+ /**
1414
+ * Description of what the skill does
1415
+ */
1416
+ description: string;
1417
+ /**
1418
+ * Hint for skill arguments (e.g., "<file>")
1419
+ */
1420
+ argumentHint: string;
1421
+ };
1422
+
1423
+ /**
1424
+ * Represents a spawned process with stdin/stdout streams and lifecycle management.
1425
+ * Implementers provide this interface to abstract the process spawning mechanism.
1426
+ * ChildProcess already satisfies this interface.
1427
+ */
1428
+ export declare interface SpawnedProcess {
1429
+ /** Writable stream for sending data to the process stdin */
1430
+ stdin: Writable;
1431
+ /** Readable stream for receiving data from the process stdout */
1432
+ stdout: Readable;
1433
+ /** Whether the process has been killed */
1434
+ readonly killed: boolean;
1435
+ /** Exit code if the process has exited, null otherwise */
1436
+ readonly exitCode: number | null;
1437
+ /**
1438
+ * Kill the process with the given signal
1439
+ * @param signal - The signal to send (e.g., 'SIGTERM', 'SIGKILL')
1440
+ */
1441
+ kill(signal: NodeJS.Signals): boolean;
1442
+ /**
1443
+ * Register a callback for when the process exits
1444
+ * @param event - Must be 'exit'
1445
+ * @param listener - Callback receiving exit code and signal
1446
+ */
1447
+ on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
1448
+ /**
1449
+ * Register a callback for process errors
1450
+ * @param event - Must be 'error'
1451
+ * @param listener - Callback receiving the error
1452
+ */
1453
+ on(event: 'error', listener: (error: Error) => void): void;
1454
+ /**
1455
+ * Register a one-time callback for when the process exits
1456
+ */
1457
+ once(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
1458
+ once(event: 'error', listener: (error: Error) => void): void;
1459
+ /**
1460
+ * Remove an event listener
1461
+ */
1462
+ off(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
1463
+ off(event: 'error', listener: (error: Error) => void): void;
1464
+ }
1465
+
1466
+ /**
1467
+ * Options passed to the spawn function.
1468
+ */
1469
+ export declare interface SpawnOptions {
1470
+ /** Command to execute */
1471
+ command: string;
1472
+ /** Arguments to pass to the command */
1473
+ args: string[];
1474
+ /** Working directory */
1475
+ cwd?: string;
1476
+ /** Environment variables */
1477
+ env: {
1478
+ [envVar: string]: string | undefined;
1479
+ };
1480
+ /** Abort signal for cancellation */
1481
+ signal: AbortSignal;
1482
+ }
1483
+
1484
+ declare type StdoutMessage = coreTypes.SDKMessage | SDKControlResponse | SDKControlRequest | SDKControlCancelRequest | SDKKeepAliveMessage;
1485
+
1486
+ export declare type StopHookInput = BaseHookInput & {
1487
+ hook_event_name: 'Stop';
1488
+ stop_hook_active: boolean;
1489
+ };
1490
+
1491
+ export declare type SubagentStartHookInput = BaseHookInput & {
1492
+ hook_event_name: 'SubagentStart';
1493
+ agent_id: string;
1494
+ agent_type: string;
1495
+ };
1496
+
1497
+ export declare type SubagentStartHookSpecificOutput = {
1498
+ hookEventName: 'SubagentStart';
1499
+ additionalContext?: string;
1500
+ };
1501
+
1502
+ export declare type SubagentStopHookInput = BaseHookInput & {
1503
+ hook_event_name: 'SubagentStop';
1504
+ stop_hook_active: boolean;
1505
+ agent_id: string;
1506
+ agent_transcript_path: string;
1507
+ };
1508
+
1509
+ export declare type SyncHookJSONOutput = {
1510
+ continue?: boolean;
1511
+ suppressOutput?: boolean;
1512
+ stopReason?: string;
1513
+ decision?: 'approve' | 'block';
1514
+ systemMessage?: string;
1515
+ reason?: string;
1516
+ hookSpecificOutput?: PreToolUseHookSpecificOutput | UserPromptSubmitHookSpecificOutput | SessionStartHookSpecificOutput | SubagentStartHookSpecificOutput | PostToolUseHookSpecificOutput | PostToolUseFailureHookSpecificOutput | PermissionRequestHookSpecificOutput;
1517
+ };
1518
+
1519
+ export declare function tool<Schema extends AnyZodRawShape>(_name: string, _description: string, _inputSchema: Schema, _handler: (args: InferShape<Schema>, extra: unknown) => Promise<CallToolResult>): SdkMcpToolDefinition<Schema>;
1520
+
1521
+ /**
1522
+ * Transport interface for Claude Code SDK communication
1523
+ * Abstracts the communication layer to support both process and WebSocket transports
1524
+ */
1525
+ export declare interface Transport {
1526
+ /**
1527
+ * Write data to the transport
1528
+ * May be async for network-based transports
1529
+ */
1530
+ write(data: string): void | Promise<void>;
1531
+ /**
1532
+ * Close the transport connection and clean up resources
1533
+ * This also closes stdin if still open (eliminating need for endInput)
1534
+ */
1535
+ close(): void;
1536
+ /**
1537
+ * Check if transport is ready for communication
1538
+ */
1539
+ isReady(): boolean;
1540
+ /**
1541
+ * Read and parse messages from the transport
1542
+ * Each transport handles its own protocol and error checking
1543
+ */
1544
+ readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
1545
+ /**
1546
+ * End the input stream
1547
+ */
1548
+ endInput(): void;
1549
+ }
1550
+
1551
+ /**
1552
+ * V2 API - UNSTABLE
1553
+ * Create a persistent session for multi-turn conversations.
1554
+ */
1555
+ export declare function unstable_v2_createSession(_options: SDKSessionOptions): SDKSession;
1556
+
1557
+ /**
1558
+ * V2 API - UNSTABLE
1559
+ * One-shot convenience function for single prompts.
1560
+ *
1561
+ * @example
1562
+ * ```typescript
1563
+ * const result = await unstable_v2_prompt("What files are here?", {
1564
+ * model: 'claude-sonnet-4-5-20250929'
1565
+ * })
1566
+ * ```
1567
+ */
1568
+ export declare function unstable_v2_prompt(_message: string, _options: SDKSessionOptions): Promise<SDKResultMessage>;
1569
+
1570
+ /**
1571
+ * V2 API - UNSTABLE
1572
+ * Resume an existing session by ID.
1573
+ */
1574
+ export declare function unstable_v2_resumeSession(_sessionId: string, _options: SDKSessionOptions): SDKSession;
1575
+
1576
+ export declare type UserPromptSubmitHookInput = BaseHookInput & {
1577
+ hook_event_name: 'UserPromptSubmit';
1578
+ prompt: string;
1579
+ };
1580
+
1581
+ export declare type UserPromptSubmitHookSpecificOutput = {
1582
+ hookEventName: 'UserPromptSubmit';
1583
+ additionalContext?: string;
1584
+ };
1585
+
1586
+ export { }