@anthropic-ai/claude-agent-sdk 0.1.63 → 0.1.65
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/cli.js +1474 -1466
- package/entrypoints/agentSdkTypes.d.ts +1041 -0
- package/entrypoints/sdkControlTypes.d.ts +96 -0
- package/package.json +1 -1
- package/sdk-tools.d.ts +14 -25
- package/sdk.d.ts +1 -1008
- package/sdk.mjs +121 -70
- package/transport/processTransportTypes.d.ts +60 -0
- package/transport/transport.d.ts +30 -0
- /package/{sandboxTypes.d.ts → entrypoints/sandboxTypes.d.ts} +0 -0
|
@@ -0,0 +1,1041 @@
|
|
|
1
|
+
import type { MessageParam as APIUserMessage } from '@anthropic-ai/sdk/resources';
|
|
2
|
+
import type { BetaMessage as APIAssistantMessage, BetaUsage as Usage, BetaRawMessageStreamEvent as RawMessageStreamEvent } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
|
|
3
|
+
import type { UUID } from 'crypto';
|
|
4
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
|
+
import { type z, type ZodRawShape, type ZodObject } from 'zod';
|
|
7
|
+
import type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations } from './sandboxTypes.js';
|
|
8
|
+
import type { SpawnedProcess, SpawnOptions } from '../transport/processTransportTypes.js';
|
|
9
|
+
import type { Transport } from '../transport/transport.js';
|
|
10
|
+
export type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations };
|
|
11
|
+
export type NonNullableUsage = {
|
|
12
|
+
[K in keyof Usage]: NonNullable<Usage[K]>;
|
|
13
|
+
};
|
|
14
|
+
export type ModelUsage = {
|
|
15
|
+
inputTokens: number;
|
|
16
|
+
outputTokens: number;
|
|
17
|
+
cacheReadInputTokens: number;
|
|
18
|
+
cacheCreationInputTokens: number;
|
|
19
|
+
webSearchRequests: number;
|
|
20
|
+
costUSD: number;
|
|
21
|
+
contextWindow: number;
|
|
22
|
+
};
|
|
23
|
+
export type OutputFormatType = 'json_schema';
|
|
24
|
+
export type BaseOutputFormat = {
|
|
25
|
+
type: OutputFormatType;
|
|
26
|
+
};
|
|
27
|
+
export type JsonSchemaOutputFormat = BaseOutputFormat & {
|
|
28
|
+
type: 'json_schema';
|
|
29
|
+
schema: Record<string, unknown>;
|
|
30
|
+
};
|
|
31
|
+
export type OutputFormat = JsonSchemaOutputFormat;
|
|
32
|
+
export type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';
|
|
33
|
+
export type ConfigScope = 'local' | 'user' | 'project';
|
|
34
|
+
/**
|
|
35
|
+
* Allowed beta headers that can be passed via SDK options.
|
|
36
|
+
*/
|
|
37
|
+
export type SdkBeta = 'context-1m-2025-08-07';
|
|
38
|
+
export type McpStdioServerConfig = {
|
|
39
|
+
type?: 'stdio';
|
|
40
|
+
command: string;
|
|
41
|
+
args?: string[];
|
|
42
|
+
env?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
export type McpSSEServerConfig = {
|
|
45
|
+
type: 'sse';
|
|
46
|
+
url: string;
|
|
47
|
+
headers?: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
export type McpHttpServerConfig = {
|
|
50
|
+
type: 'http';
|
|
51
|
+
url: string;
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
export type McpSdkServerConfig = {
|
|
55
|
+
type: 'sdk';
|
|
56
|
+
name: string;
|
|
57
|
+
};
|
|
58
|
+
export type McpSdkServerConfigWithInstance = McpSdkServerConfig & {
|
|
59
|
+
instance: McpServer;
|
|
60
|
+
};
|
|
61
|
+
export type McpServerConfig = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig | McpSdkServerConfigWithInstance;
|
|
62
|
+
export type McpServerConfigForProcessTransport = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig | McpSdkServerConfig;
|
|
63
|
+
type PermissionUpdateDestination = 'userSettings' | 'projectSettings' | 'localSettings' | 'session' | 'cliArg';
|
|
64
|
+
export type PermissionBehavior = 'allow' | 'deny' | 'ask';
|
|
65
|
+
export type PermissionUpdate = {
|
|
66
|
+
type: 'addRules';
|
|
67
|
+
rules: PermissionRuleValue[];
|
|
68
|
+
behavior: PermissionBehavior;
|
|
69
|
+
destination: PermissionUpdateDestination;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'replaceRules';
|
|
72
|
+
rules: PermissionRuleValue[];
|
|
73
|
+
behavior: PermissionBehavior;
|
|
74
|
+
destination: PermissionUpdateDestination;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'removeRules';
|
|
77
|
+
rules: PermissionRuleValue[];
|
|
78
|
+
behavior: PermissionBehavior;
|
|
79
|
+
destination: PermissionUpdateDestination;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'setMode';
|
|
82
|
+
mode: PermissionMode;
|
|
83
|
+
destination: PermissionUpdateDestination;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'addDirectories';
|
|
86
|
+
directories: string[];
|
|
87
|
+
destination: PermissionUpdateDestination;
|
|
88
|
+
} | {
|
|
89
|
+
type: 'removeDirectories';
|
|
90
|
+
directories: string[];
|
|
91
|
+
destination: PermissionUpdateDestination;
|
|
92
|
+
};
|
|
93
|
+
export type PermissionResult = {
|
|
94
|
+
behavior: 'allow';
|
|
95
|
+
/**
|
|
96
|
+
* Updated tool input to use, if any changes are needed.
|
|
97
|
+
*
|
|
98
|
+
* For example if the user was given the option to update the tool use
|
|
99
|
+
* input before approving, then this would be the updated input which
|
|
100
|
+
* would be executed by the tool.
|
|
101
|
+
*/
|
|
102
|
+
updatedInput: Record<string, unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* Permissions updates to be applied as part of accepting this tool use.
|
|
105
|
+
*
|
|
106
|
+
* Typically this is used as part of the 'always allow' flow and these
|
|
107
|
+
* permission updates are from the `suggestions` field from the
|
|
108
|
+
* CanUseTool callback.
|
|
109
|
+
*
|
|
110
|
+
* It is recommended that you use these suggestions rather than
|
|
111
|
+
* attempting to re-derive them from the tool use input, as the
|
|
112
|
+
* suggestions may include other permission changes such as adding
|
|
113
|
+
* directories or incorporate complex tool-use logic such as bash
|
|
114
|
+
* commands.
|
|
115
|
+
*/
|
|
116
|
+
updatedPermissions?: PermissionUpdate[];
|
|
117
|
+
/**
|
|
118
|
+
* The tool use ID. Supplied and used internally.
|
|
119
|
+
*/
|
|
120
|
+
toolUseID?: string;
|
|
121
|
+
} | {
|
|
122
|
+
behavior: 'deny';
|
|
123
|
+
/**
|
|
124
|
+
* Message indicating the reason for denial, or guidance of what the
|
|
125
|
+
* model should do instead.
|
|
126
|
+
*/
|
|
127
|
+
message: string;
|
|
128
|
+
/**
|
|
129
|
+
* If true, interrupt execution and do not continue.
|
|
130
|
+
*
|
|
131
|
+
* Typically this should be set to true when the user says 'no' with no
|
|
132
|
+
* further guidance. Leave unset or false if the user provides guidance
|
|
133
|
+
* which the model should incorporate and continue.
|
|
134
|
+
*/
|
|
135
|
+
interrupt?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* The tool use ID. Supplied and used internally.
|
|
138
|
+
*/
|
|
139
|
+
toolUseID?: string;
|
|
140
|
+
};
|
|
141
|
+
export type PermissionRuleValue = {
|
|
142
|
+
toolName: string;
|
|
143
|
+
ruleContent?: string;
|
|
144
|
+
};
|
|
145
|
+
export type CanUseTool = (toolName: string, input: Record<string, unknown>, options: {
|
|
146
|
+
/** Signaled if the operation should be aborted. */
|
|
147
|
+
signal: AbortSignal;
|
|
148
|
+
/**
|
|
149
|
+
* Suggestions for updating permissions so that the user will not be
|
|
150
|
+
* prompted again for this tool during this session.
|
|
151
|
+
*
|
|
152
|
+
* Typically if presenting the user an option 'always allow' or similar,
|
|
153
|
+
* then this full set of suggestions should be returned as the
|
|
154
|
+
* `updatedPermissions` in the PermissionResult.
|
|
155
|
+
*/
|
|
156
|
+
suggestions?: PermissionUpdate[];
|
|
157
|
+
/**
|
|
158
|
+
* The file path that triggered the permission request, if applicable.
|
|
159
|
+
* For example, when a Bash command tries to access a path outside allowed directories.
|
|
160
|
+
*/
|
|
161
|
+
blockedPath?: string;
|
|
162
|
+
/** Explains why this permission request was triggered. */
|
|
163
|
+
decisionReason?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Unique identifier for this specific tool call within the assistant message.
|
|
166
|
+
* Multiple tool calls in the same assistant message will have different toolUseIDs.
|
|
167
|
+
*/
|
|
168
|
+
toolUseID: string;
|
|
169
|
+
/** If running within the context of a sub-agent, the sub-agent's ID. */
|
|
170
|
+
agentID?: string;
|
|
171
|
+
}) => Promise<PermissionResult>;
|
|
172
|
+
export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
|
|
173
|
+
export type HookEvent = (typeof HOOK_EVENTS)[number];
|
|
174
|
+
export type HookCallback = (input: HookInput, toolUseID: string | undefined, options: {
|
|
175
|
+
signal: AbortSignal;
|
|
176
|
+
}) => Promise<HookJSONOutput>;
|
|
177
|
+
export interface HookCallbackMatcher {
|
|
178
|
+
matcher?: string;
|
|
179
|
+
hooks: HookCallback[];
|
|
180
|
+
/** Timeout in seconds for all hooks in this matcher */
|
|
181
|
+
timeout?: number;
|
|
182
|
+
}
|
|
183
|
+
export type BaseHookInput = {
|
|
184
|
+
session_id: string;
|
|
185
|
+
transcript_path: string;
|
|
186
|
+
cwd: string;
|
|
187
|
+
permission_mode?: string;
|
|
188
|
+
};
|
|
189
|
+
export type PreToolUseHookInput = BaseHookInput & {
|
|
190
|
+
hook_event_name: 'PreToolUse';
|
|
191
|
+
tool_name: string;
|
|
192
|
+
tool_input: unknown;
|
|
193
|
+
tool_use_id: string;
|
|
194
|
+
};
|
|
195
|
+
export type PermissionRequestHookInput = BaseHookInput & {
|
|
196
|
+
hook_event_name: 'PermissionRequest';
|
|
197
|
+
tool_name: string;
|
|
198
|
+
tool_input: unknown;
|
|
199
|
+
permission_suggestions?: PermissionUpdate[];
|
|
200
|
+
};
|
|
201
|
+
export type PostToolUseHookInput = BaseHookInput & {
|
|
202
|
+
hook_event_name: 'PostToolUse';
|
|
203
|
+
tool_name: string;
|
|
204
|
+
tool_input: unknown;
|
|
205
|
+
tool_response: unknown;
|
|
206
|
+
tool_use_id: string;
|
|
207
|
+
};
|
|
208
|
+
export type PostToolUseFailureHookInput = BaseHookInput & {
|
|
209
|
+
hook_event_name: 'PostToolUseFailure';
|
|
210
|
+
tool_name: string;
|
|
211
|
+
tool_input: unknown;
|
|
212
|
+
tool_use_id: string;
|
|
213
|
+
error: string;
|
|
214
|
+
is_interrupt?: boolean;
|
|
215
|
+
};
|
|
216
|
+
export type NotificationHookInput = BaseHookInput & {
|
|
217
|
+
hook_event_name: 'Notification';
|
|
218
|
+
message: string;
|
|
219
|
+
title?: string;
|
|
220
|
+
notification_type: string;
|
|
221
|
+
};
|
|
222
|
+
export type UserPromptSubmitHookInput = BaseHookInput & {
|
|
223
|
+
hook_event_name: 'UserPromptSubmit';
|
|
224
|
+
prompt: string;
|
|
225
|
+
};
|
|
226
|
+
export type SessionStartHookInput = BaseHookInput & {
|
|
227
|
+
hook_event_name: 'SessionStart';
|
|
228
|
+
source: 'startup' | 'resume' | 'clear' | 'compact';
|
|
229
|
+
};
|
|
230
|
+
export type StopHookInput = BaseHookInput & {
|
|
231
|
+
hook_event_name: 'Stop';
|
|
232
|
+
stop_hook_active: boolean;
|
|
233
|
+
};
|
|
234
|
+
export type SubagentStartHookInput = BaseHookInput & {
|
|
235
|
+
hook_event_name: 'SubagentStart';
|
|
236
|
+
agent_id: string;
|
|
237
|
+
agent_type: string;
|
|
238
|
+
};
|
|
239
|
+
export type SubagentStopHookInput = BaseHookInput & {
|
|
240
|
+
hook_event_name: 'SubagentStop';
|
|
241
|
+
stop_hook_active: boolean;
|
|
242
|
+
agent_id: string;
|
|
243
|
+
agent_transcript_path: string;
|
|
244
|
+
};
|
|
245
|
+
export type PreCompactHookInput = BaseHookInput & {
|
|
246
|
+
hook_event_name: 'PreCompact';
|
|
247
|
+
trigger: 'manual' | 'auto';
|
|
248
|
+
custom_instructions: string | null;
|
|
249
|
+
};
|
|
250
|
+
export declare const EXIT_REASONS: string[];
|
|
251
|
+
export type ExitReason = (typeof EXIT_REASONS)[number];
|
|
252
|
+
export type SessionEndHookInput = BaseHookInput & {
|
|
253
|
+
hook_event_name: 'SessionEnd';
|
|
254
|
+
reason: ExitReason;
|
|
255
|
+
};
|
|
256
|
+
export type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PermissionRequestHookInput;
|
|
257
|
+
export type AsyncHookJSONOutput = {
|
|
258
|
+
async: true;
|
|
259
|
+
asyncTimeout?: number;
|
|
260
|
+
};
|
|
261
|
+
export type SyncHookJSONOutput = {
|
|
262
|
+
continue?: boolean;
|
|
263
|
+
suppressOutput?: boolean;
|
|
264
|
+
stopReason?: string;
|
|
265
|
+
decision?: 'approve' | 'block';
|
|
266
|
+
systemMessage?: string;
|
|
267
|
+
reason?: string;
|
|
268
|
+
hookSpecificOutput?: {
|
|
269
|
+
hookEventName: 'PreToolUse';
|
|
270
|
+
permissionDecision?: 'allow' | 'deny' | 'ask';
|
|
271
|
+
permissionDecisionReason?: string;
|
|
272
|
+
updatedInput?: Record<string, unknown>;
|
|
273
|
+
} | {
|
|
274
|
+
hookEventName: 'UserPromptSubmit';
|
|
275
|
+
additionalContext?: string;
|
|
276
|
+
} | {
|
|
277
|
+
hookEventName: 'SessionStart';
|
|
278
|
+
additionalContext?: string;
|
|
279
|
+
} | {
|
|
280
|
+
hookEventName: 'SubagentStart';
|
|
281
|
+
additionalContext?: string;
|
|
282
|
+
} | {
|
|
283
|
+
hookEventName: 'PostToolUse';
|
|
284
|
+
additionalContext?: string;
|
|
285
|
+
updatedMCPToolOutput?: unknown;
|
|
286
|
+
} | {
|
|
287
|
+
hookEventName: 'PostToolUseFailure';
|
|
288
|
+
additionalContext?: string;
|
|
289
|
+
} | {
|
|
290
|
+
hookEventName: 'PermissionRequest';
|
|
291
|
+
decision: {
|
|
292
|
+
behavior: 'allow';
|
|
293
|
+
updatedInput?: Record<string, unknown>;
|
|
294
|
+
updatedPermissions?: PermissionUpdate[];
|
|
295
|
+
} | {
|
|
296
|
+
behavior: 'deny';
|
|
297
|
+
message?: string;
|
|
298
|
+
interrupt?: boolean;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput;
|
|
303
|
+
/**
|
|
304
|
+
* Permission mode for controlling how tool executions are handled.
|
|
305
|
+
* - `'default'` - Standard behavior, prompts for dangerous operations
|
|
306
|
+
* - `'acceptEdits'` - Auto-accept file edit operations
|
|
307
|
+
* - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
|
|
308
|
+
* - `'plan'` - Planning mode, no actual tool execution
|
|
309
|
+
* - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
|
|
310
|
+
*/
|
|
311
|
+
export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'dontAsk';
|
|
312
|
+
/**
|
|
313
|
+
* Information about an available slash command.
|
|
314
|
+
*/
|
|
315
|
+
export type SlashCommand = {
|
|
316
|
+
/** Command name (without the leading slash) */
|
|
317
|
+
name: string;
|
|
318
|
+
/** Description of what the command does */
|
|
319
|
+
description: string;
|
|
320
|
+
/** Hint for command arguments (e.g., "<file>") */
|
|
321
|
+
argumentHint: string;
|
|
322
|
+
};
|
|
323
|
+
/**
|
|
324
|
+
* Information about an available model.
|
|
325
|
+
*/
|
|
326
|
+
export type ModelInfo = {
|
|
327
|
+
/** Model identifier to use in API calls */
|
|
328
|
+
value: string;
|
|
329
|
+
/** Human-readable display name */
|
|
330
|
+
displayName: string;
|
|
331
|
+
/** Description of the model's capabilities */
|
|
332
|
+
description: string;
|
|
333
|
+
};
|
|
334
|
+
/** Information about the logged in user's account. */
|
|
335
|
+
export type AccountInfo = {
|
|
336
|
+
email?: string;
|
|
337
|
+
organization?: string;
|
|
338
|
+
subscriptionType?: string;
|
|
339
|
+
tokenSource?: string;
|
|
340
|
+
apiKeySource?: string;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Status information for an MCP server connection.
|
|
344
|
+
*/
|
|
345
|
+
export type McpServerStatus = {
|
|
346
|
+
/** Server name as configured */
|
|
347
|
+
name: string;
|
|
348
|
+
/** Current connection status */
|
|
349
|
+
status: 'connected' | 'failed' | 'needs-auth' | 'pending';
|
|
350
|
+
/** Server information (available when connected) */
|
|
351
|
+
serverInfo?: {
|
|
352
|
+
name: string;
|
|
353
|
+
version: string;
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
type SDKUserMessageContent = {
|
|
357
|
+
type: 'user';
|
|
358
|
+
message: APIUserMessage;
|
|
359
|
+
parent_tool_use_id: string | null;
|
|
360
|
+
/**
|
|
361
|
+
* True if this is a 'synthetic' user message which did not originate from
|
|
362
|
+
* the user directly, but instead was generated by the system.
|
|
363
|
+
*/
|
|
364
|
+
isSynthetic?: boolean;
|
|
365
|
+
/**
|
|
366
|
+
* If present, the JSON result of a tool use that this user message is
|
|
367
|
+
* responding to. This is provided to make it easier for applications to
|
|
368
|
+
* present the tool result in a formatted way. The model only receives
|
|
369
|
+
* the content within the user message.
|
|
370
|
+
* The specific format is tool-dependent.
|
|
371
|
+
*/
|
|
372
|
+
tool_use_result?: unknown;
|
|
373
|
+
};
|
|
374
|
+
export type SDKUserMessage = SDKUserMessageContent & {
|
|
375
|
+
uuid?: UUID;
|
|
376
|
+
session_id: string;
|
|
377
|
+
};
|
|
378
|
+
export type SDKUserMessageReplay = SDKUserMessageContent & {
|
|
379
|
+
uuid: UUID;
|
|
380
|
+
session_id: string;
|
|
381
|
+
/**
|
|
382
|
+
* True if this is a replay/acknowledgment of a user message that was already
|
|
383
|
+
* added to the messages array. Used internally to prevent duplicate messages.
|
|
384
|
+
*/
|
|
385
|
+
isReplay: true;
|
|
386
|
+
};
|
|
387
|
+
export type SDKAssistantMessageError = 'authentication_failed' | 'billing_error' | 'rate_limit' | 'invalid_request' | 'server_error' | 'unknown';
|
|
388
|
+
export type SDKAssistantMessage = {
|
|
389
|
+
type: 'assistant';
|
|
390
|
+
message: APIAssistantMessage;
|
|
391
|
+
parent_tool_use_id: string | null;
|
|
392
|
+
error?: SDKAssistantMessageError;
|
|
393
|
+
uuid: UUID;
|
|
394
|
+
session_id: string;
|
|
395
|
+
};
|
|
396
|
+
export type SDKPermissionDenial = {
|
|
397
|
+
tool_name: string;
|
|
398
|
+
tool_use_id: string;
|
|
399
|
+
tool_input: Record<string, unknown>;
|
|
400
|
+
};
|
|
401
|
+
export type SDKResultMessage = {
|
|
402
|
+
type: 'result';
|
|
403
|
+
subtype: 'success';
|
|
404
|
+
duration_ms: number;
|
|
405
|
+
duration_api_ms: number;
|
|
406
|
+
is_error: boolean;
|
|
407
|
+
num_turns: number;
|
|
408
|
+
result: string;
|
|
409
|
+
total_cost_usd: number;
|
|
410
|
+
usage: NonNullableUsage;
|
|
411
|
+
modelUsage: {
|
|
412
|
+
[modelName: string]: ModelUsage;
|
|
413
|
+
};
|
|
414
|
+
permission_denials: SDKPermissionDenial[];
|
|
415
|
+
structured_output?: unknown;
|
|
416
|
+
uuid: UUID;
|
|
417
|
+
session_id: string;
|
|
418
|
+
} | {
|
|
419
|
+
type: 'result';
|
|
420
|
+
subtype: 'error_during_execution' | 'error_max_turns' | 'error_max_budget_usd' | 'error_max_structured_output_retries';
|
|
421
|
+
duration_ms: number;
|
|
422
|
+
duration_api_ms: number;
|
|
423
|
+
is_error: boolean;
|
|
424
|
+
num_turns: number;
|
|
425
|
+
total_cost_usd: number;
|
|
426
|
+
usage: NonNullableUsage;
|
|
427
|
+
modelUsage: {
|
|
428
|
+
[modelName: string]: ModelUsage;
|
|
429
|
+
};
|
|
430
|
+
permission_denials: SDKPermissionDenial[];
|
|
431
|
+
errors: string[];
|
|
432
|
+
uuid: UUID;
|
|
433
|
+
session_id: string;
|
|
434
|
+
};
|
|
435
|
+
export type SDKSystemMessage = {
|
|
436
|
+
type: 'system';
|
|
437
|
+
subtype: 'init';
|
|
438
|
+
agents?: string[];
|
|
439
|
+
apiKeySource: ApiKeySource;
|
|
440
|
+
betas?: string[];
|
|
441
|
+
claude_code_version: string;
|
|
442
|
+
cwd: string;
|
|
443
|
+
tools: string[];
|
|
444
|
+
mcp_servers: {
|
|
445
|
+
name: string;
|
|
446
|
+
status: string;
|
|
447
|
+
}[];
|
|
448
|
+
model: string;
|
|
449
|
+
permissionMode: PermissionMode;
|
|
450
|
+
slash_commands: string[];
|
|
451
|
+
output_style: string;
|
|
452
|
+
skills: string[];
|
|
453
|
+
plugins: {
|
|
454
|
+
name: string;
|
|
455
|
+
path: string;
|
|
456
|
+
}[];
|
|
457
|
+
uuid: UUID;
|
|
458
|
+
session_id: string;
|
|
459
|
+
};
|
|
460
|
+
export type SDKPartialAssistantMessage = {
|
|
461
|
+
type: 'stream_event';
|
|
462
|
+
event: RawMessageStreamEvent;
|
|
463
|
+
parent_tool_use_id: string | null;
|
|
464
|
+
uuid: UUID;
|
|
465
|
+
session_id: string;
|
|
466
|
+
};
|
|
467
|
+
export type SDKCompactBoundaryMessage = {
|
|
468
|
+
type: 'system';
|
|
469
|
+
subtype: 'compact_boundary';
|
|
470
|
+
compact_metadata: {
|
|
471
|
+
trigger: 'manual' | 'auto';
|
|
472
|
+
pre_tokens: number;
|
|
473
|
+
};
|
|
474
|
+
uuid: UUID;
|
|
475
|
+
session_id: string;
|
|
476
|
+
};
|
|
477
|
+
export type SDKStatus = 'compacting' | null;
|
|
478
|
+
export type SDKStatusMessage = {
|
|
479
|
+
type: 'system';
|
|
480
|
+
subtype: 'status';
|
|
481
|
+
status: SDKStatus;
|
|
482
|
+
uuid: UUID;
|
|
483
|
+
session_id: string;
|
|
484
|
+
};
|
|
485
|
+
export type SDKHookResponseMessage = {
|
|
486
|
+
type: 'system';
|
|
487
|
+
subtype: 'hook_response';
|
|
488
|
+
hook_name: string;
|
|
489
|
+
hook_event: string;
|
|
490
|
+
stdout: string;
|
|
491
|
+
stderr: string;
|
|
492
|
+
exit_code?: number;
|
|
493
|
+
uuid: UUID;
|
|
494
|
+
session_id: string;
|
|
495
|
+
};
|
|
496
|
+
export type SDKToolProgressMessage = {
|
|
497
|
+
type: 'tool_progress';
|
|
498
|
+
tool_use_id: string;
|
|
499
|
+
tool_name: string;
|
|
500
|
+
parent_tool_use_id: string | null;
|
|
501
|
+
elapsed_time_seconds: number;
|
|
502
|
+
uuid: UUID;
|
|
503
|
+
session_id: string;
|
|
504
|
+
};
|
|
505
|
+
export type SDKAuthStatusMessage = {
|
|
506
|
+
type: 'auth_status';
|
|
507
|
+
isAuthenticating: boolean;
|
|
508
|
+
output: string[];
|
|
509
|
+
error?: string;
|
|
510
|
+
uuid: UUID;
|
|
511
|
+
session_id: string;
|
|
512
|
+
};
|
|
513
|
+
export type SDKMessage = SDKAssistantMessage | SDKUserMessage | SDKUserMessageReplay | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage | SDKCompactBoundaryMessage | SDKStatusMessage | SDKHookResponseMessage | SDKToolProgressMessage | SDKAuthStatusMessage;
|
|
514
|
+
export interface Query extends AsyncGenerator<SDKMessage, void> {
|
|
515
|
+
/**
|
|
516
|
+
* Control Requests
|
|
517
|
+
* The following methods are control requests, and are only supported when
|
|
518
|
+
* streaming input/output is used.
|
|
519
|
+
*/
|
|
520
|
+
/**
|
|
521
|
+
* Interrupt the current query execution. The query will stop processing
|
|
522
|
+
* and return control to the caller.
|
|
523
|
+
*/
|
|
524
|
+
interrupt(): Promise<void>;
|
|
525
|
+
/**
|
|
526
|
+
* Change the permission mode for the current session.
|
|
527
|
+
* Only available in streaming input mode.
|
|
528
|
+
*
|
|
529
|
+
* @param mode - The new permission mode to set
|
|
530
|
+
*/
|
|
531
|
+
setPermissionMode(mode: PermissionMode): Promise<void>;
|
|
532
|
+
/**
|
|
533
|
+
* Change the model used for subsequent responses.
|
|
534
|
+
* Only available in streaming input mode.
|
|
535
|
+
*
|
|
536
|
+
* @param model - The model identifier to use, or undefined to use the default
|
|
537
|
+
*/
|
|
538
|
+
setModel(model?: string): Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Set the maximum number of thinking tokens the model is allowed to use
|
|
541
|
+
* when generating its response. This can be used to limit the amount of
|
|
542
|
+
* tokens the model uses for its response, which can help control cost and
|
|
543
|
+
* latency.
|
|
544
|
+
*
|
|
545
|
+
* Use `null` to clear any previously set limit and allow the model to
|
|
546
|
+
* use the default maximum thinking tokens.
|
|
547
|
+
*
|
|
548
|
+
* @param maxThinkingTokens - Maximum tokens for thinking, or null to clear the limit
|
|
549
|
+
*/
|
|
550
|
+
setMaxThinkingTokens(maxThinkingTokens: number | null): Promise<void>;
|
|
551
|
+
/**
|
|
552
|
+
* Get the list of available slash commands for the current session.
|
|
553
|
+
*
|
|
554
|
+
* @returns Array of available slash commands with their names and descriptions
|
|
555
|
+
*/
|
|
556
|
+
supportedCommands(): Promise<SlashCommand[]>;
|
|
557
|
+
/**
|
|
558
|
+
* Get the list of available models.
|
|
559
|
+
*
|
|
560
|
+
* @returns Array of model information including display names and descriptions
|
|
561
|
+
*/
|
|
562
|
+
supportedModels(): Promise<ModelInfo[]>;
|
|
563
|
+
/**
|
|
564
|
+
* Get the current status of all configured MCP servers.
|
|
565
|
+
*
|
|
566
|
+
* @returns Array of MCP server statuses (connected, failed, needs-auth, pending)
|
|
567
|
+
*/
|
|
568
|
+
mcpServerStatus(): Promise<McpServerStatus[]>;
|
|
569
|
+
/**
|
|
570
|
+
* Get information about the authenticated account.
|
|
571
|
+
*
|
|
572
|
+
* @returns Account information including email, organization, and subscription type
|
|
573
|
+
*/
|
|
574
|
+
accountInfo(): Promise<AccountInfo>;
|
|
575
|
+
/**
|
|
576
|
+
* Rewind tracked files to their state at a specific user message.
|
|
577
|
+
* Requires file checkpointing to be enabled via the `enableFileCheckpointing` option.
|
|
578
|
+
*
|
|
579
|
+
* @param userMessageId - UUID of the user message to rewind to
|
|
580
|
+
*/
|
|
581
|
+
rewindFiles(userMessageId: string): Promise<void>;
|
|
582
|
+
/**
|
|
583
|
+
* Stream input messages to the query.
|
|
584
|
+
* Used internally for multi-turn conversations.
|
|
585
|
+
*
|
|
586
|
+
* @param stream - Async iterable of user messages to send
|
|
587
|
+
*/
|
|
588
|
+
streamInput(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* V2 API - UNSTABLE
|
|
592
|
+
* Options for creating a session
|
|
593
|
+
*/
|
|
594
|
+
export type SDKSessionOptions = {
|
|
595
|
+
/** Model to use */
|
|
596
|
+
model: string;
|
|
597
|
+
/** Path to Claude Code executable */
|
|
598
|
+
pathToClaudeCodeExecutable?: string;
|
|
599
|
+
/** Executable to use (node, bun) */
|
|
600
|
+
executable?: 'node' | 'bun';
|
|
601
|
+
/** Arguments to pass to executable */
|
|
602
|
+
executableArgs?: string[];
|
|
603
|
+
/**
|
|
604
|
+
* Environment variables to pass to the Claude Code process.
|
|
605
|
+
* Defaults to `process.env`.
|
|
606
|
+
*/
|
|
607
|
+
env?: {
|
|
608
|
+
[envVar: string]: string | undefined;
|
|
609
|
+
};
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* V2 API - UNSTABLE
|
|
613
|
+
* Session interface for multi-turn conversations
|
|
614
|
+
*/
|
|
615
|
+
export interface SDKSession {
|
|
616
|
+
/**
|
|
617
|
+
* The session ID. Available after receiving the first message.
|
|
618
|
+
* For resumed sessions, available immediately.
|
|
619
|
+
* Throws if accessed before the session is initialized.
|
|
620
|
+
*/
|
|
621
|
+
readonly sessionId: string;
|
|
622
|
+
/** Send a message to the agent */
|
|
623
|
+
send(message: string | SDKUserMessage): Promise<void>;
|
|
624
|
+
/** Receive messages from the agent */
|
|
625
|
+
receive(): AsyncGenerator<SDKMessage, void>;
|
|
626
|
+
/** Close the session */
|
|
627
|
+
close(): void;
|
|
628
|
+
/** Async disposal support (calls close if not already closed) */
|
|
629
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
630
|
+
}
|
|
631
|
+
type SdkMcpToolDefinition<Schema extends ZodRawShape = ZodRawShape> = {
|
|
632
|
+
name: string;
|
|
633
|
+
description: string;
|
|
634
|
+
inputSchema: Schema;
|
|
635
|
+
handler: (args: z.infer<ZodObject<Schema>>, extra: unknown) => Promise<CallToolResult>;
|
|
636
|
+
};
|
|
637
|
+
export declare function tool<Schema extends ZodRawShape>(_name: string, _description: string, _inputSchema: Schema, _handler: (args: z.infer<ZodObject<Schema>>, extra: unknown) => Promise<CallToolResult>): SdkMcpToolDefinition<Schema>;
|
|
638
|
+
type CreateSdkMcpServerOptions = {
|
|
639
|
+
name: string;
|
|
640
|
+
version?: string;
|
|
641
|
+
tools?: Array<SdkMcpToolDefinition<any>>;
|
|
642
|
+
};
|
|
643
|
+
/**
|
|
644
|
+
* Creates an MCP server instance that can be used with the SDK transport.
|
|
645
|
+
* This allows SDK users to define custom tools that run in the same process.
|
|
646
|
+
*
|
|
647
|
+
* If your SDK MCP calls will run longer than 60s, override CLAUDE_CODE_STREAM_CLOSE_TIMEOUT
|
|
648
|
+
*/
|
|
649
|
+
export declare function createSdkMcpServer(_options: CreateSdkMcpServerOptions): McpSdkServerConfigWithInstance;
|
|
650
|
+
export declare class AbortError extends Error {
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Definition for a custom subagent that can be invoked via the Task tool.
|
|
654
|
+
*/
|
|
655
|
+
export type AgentDefinition = {
|
|
656
|
+
/** Natural language description of when to use this agent */
|
|
657
|
+
description: string;
|
|
658
|
+
/** Array of allowed tool names. If omitted, inherits all tools from parent */
|
|
659
|
+
tools?: string[];
|
|
660
|
+
/** Array of tool names to explicitly disallow for this agent */
|
|
661
|
+
disallowedTools?: string[];
|
|
662
|
+
/** The agent's system prompt */
|
|
663
|
+
prompt: string;
|
|
664
|
+
/** Model to use for this agent. If omitted or 'inherit', uses the main model */
|
|
665
|
+
model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
|
|
666
|
+
/** Experimental: Critical reminder added to system prompt */
|
|
667
|
+
criticalSystemReminder_EXPERIMENTAL?: string;
|
|
668
|
+
};
|
|
669
|
+
/**
|
|
670
|
+
* Source for loading filesystem-based settings.
|
|
671
|
+
* - `'user'` - Global user settings (`~/.claude/settings.json`)
|
|
672
|
+
* - `'project'` - Project settings (`.claude/settings.json`)
|
|
673
|
+
* - `'local'` - Local settings (`.claude/settings.local.json`)
|
|
674
|
+
*/
|
|
675
|
+
export type SettingSource = 'user' | 'project' | 'local';
|
|
676
|
+
/**
|
|
677
|
+
* Configuration for loading a plugin.
|
|
678
|
+
*/
|
|
679
|
+
export type SdkPluginConfig = {
|
|
680
|
+
/** Plugin type. Currently only 'local' is supported */
|
|
681
|
+
type: 'local';
|
|
682
|
+
/** Absolute or relative path to the plugin directory */
|
|
683
|
+
path: string;
|
|
684
|
+
};
|
|
685
|
+
export type Options = {
|
|
686
|
+
/**
|
|
687
|
+
* Controller for cancelling the query. When aborted, the query will stop
|
|
688
|
+
* and clean up resources.
|
|
689
|
+
*/
|
|
690
|
+
abortController?: AbortController;
|
|
691
|
+
/**
|
|
692
|
+
* Additional directories Claude can access beyond the current working directory.
|
|
693
|
+
* Paths should be absolute.
|
|
694
|
+
*/
|
|
695
|
+
additionalDirectories?: string[];
|
|
696
|
+
/**
|
|
697
|
+
* Programmatically define custom subagents that can be invoked via the Task tool.
|
|
698
|
+
* Keys are agent names, values are agent definitions.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* agents: {
|
|
703
|
+
* 'code-reviewer': {
|
|
704
|
+
* description: 'Reviews code for bugs and style issues',
|
|
705
|
+
* prompt: 'You are a code reviewer...',
|
|
706
|
+
* tools: ['Read', 'Grep', 'Glob']
|
|
707
|
+
* }
|
|
708
|
+
* }
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
agents?: Record<string, AgentDefinition>;
|
|
712
|
+
/**
|
|
713
|
+
* List of tool names that are allowed. When specified, only these tools
|
|
714
|
+
* will be available. Use with `disallowedTools` to fine-tune tool access.
|
|
715
|
+
*/
|
|
716
|
+
allowedTools?: string[];
|
|
717
|
+
/**
|
|
718
|
+
* Custom permission handler for controlling tool usage. Called before each
|
|
719
|
+
* tool execution to determine if it should be allowed, denied, or prompt the user.
|
|
720
|
+
*/
|
|
721
|
+
canUseTool?: CanUseTool;
|
|
722
|
+
/**
|
|
723
|
+
* Continue the most recent conversation instead of starting a new one.
|
|
724
|
+
* Mutually exclusive with `resume`.
|
|
725
|
+
*/
|
|
726
|
+
continue?: boolean;
|
|
727
|
+
/**
|
|
728
|
+
* Current working directory for the session. Defaults to `process.cwd()`.
|
|
729
|
+
*/
|
|
730
|
+
cwd?: string;
|
|
731
|
+
/**
|
|
732
|
+
* List of tool names that are disallowed. These tools will not be available
|
|
733
|
+
* even if they would otherwise be allowed.
|
|
734
|
+
*/
|
|
735
|
+
disallowedTools?: string[];
|
|
736
|
+
/**
|
|
737
|
+
* Specify the base set of available built-in tools.
|
|
738
|
+
* - `string[]` - Array of specific tool names (e.g., `['Bash', 'Read', 'Edit']`)
|
|
739
|
+
* - `[]` (empty array) - Disable all built-in tools
|
|
740
|
+
* - `{ type: 'preset'; preset: 'claude_code' }` - Use all default Claude Code tools
|
|
741
|
+
*/
|
|
742
|
+
tools?: string[] | {
|
|
743
|
+
type: 'preset';
|
|
744
|
+
preset: 'claude_code';
|
|
745
|
+
};
|
|
746
|
+
/**
|
|
747
|
+
* Environment variables to pass to the Claude Code process.
|
|
748
|
+
* Defaults to `process.env`.
|
|
749
|
+
*/
|
|
750
|
+
env?: {
|
|
751
|
+
[envVar: string]: string | undefined;
|
|
752
|
+
};
|
|
753
|
+
/**
|
|
754
|
+
* JavaScript runtime to use for executing Claude Code.
|
|
755
|
+
* Auto-detected if not specified.
|
|
756
|
+
*/
|
|
757
|
+
executable?: 'bun' | 'deno' | 'node';
|
|
758
|
+
/**
|
|
759
|
+
* Additional arguments to pass to the JavaScript runtime executable.
|
|
760
|
+
*/
|
|
761
|
+
executableArgs?: string[];
|
|
762
|
+
/**
|
|
763
|
+
* Additional CLI arguments to pass to Claude Code.
|
|
764
|
+
* Keys are argument names (without --), values are argument values.
|
|
765
|
+
* Use `null` for boolean flags.
|
|
766
|
+
*/
|
|
767
|
+
extraArgs?: Record<string, string | null>;
|
|
768
|
+
/**
|
|
769
|
+
* Fallback model to use if the primary model fails or is unavailable.
|
|
770
|
+
*/
|
|
771
|
+
fallbackModel?: string;
|
|
772
|
+
/**
|
|
773
|
+
* Enable file checkpointing to track file changes during the session.
|
|
774
|
+
* When enabled, files can be rewound to their state at any user message
|
|
775
|
+
* using `Query.rewindFiles()`.
|
|
776
|
+
*
|
|
777
|
+
* File checkpointing creates backups of files before they are modified,
|
|
778
|
+
* allowing you to restore them to previous states.
|
|
779
|
+
*/
|
|
780
|
+
enableFileCheckpointing?: boolean;
|
|
781
|
+
/**
|
|
782
|
+
* When true, resumed sessions will fork to a new session ID rather than
|
|
783
|
+
* continuing the previous session. Use with `resume`.
|
|
784
|
+
*/
|
|
785
|
+
forkSession?: boolean;
|
|
786
|
+
/**
|
|
787
|
+
* Enable beta features. Currently supported:
|
|
788
|
+
* - `'context-1m-2025-08-07'` - Enable 1M token context window (Sonnet 4/4.5 only)
|
|
789
|
+
*
|
|
790
|
+
* @see https://docs.anthropic.com/en/api/beta-headers
|
|
791
|
+
*/
|
|
792
|
+
betas?: SdkBeta[];
|
|
793
|
+
/**
|
|
794
|
+
* Hook callbacks for responding to various events during execution.
|
|
795
|
+
* Hooks can modify behavior, add context, or implement custom logic.
|
|
796
|
+
*
|
|
797
|
+
* @example
|
|
798
|
+
* ```typescript
|
|
799
|
+
* hooks: {
|
|
800
|
+
* PreToolUse: [{
|
|
801
|
+
* hooks: [async (input) => ({ continue: true })]
|
|
802
|
+
* }]
|
|
803
|
+
* }
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
806
|
+
hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
807
|
+
/**
|
|
808
|
+
* When false, disables session persistence to disk. Sessions will not be
|
|
809
|
+
* saved to ~/.claude/projects/ and cannot be resumed later. Useful for
|
|
810
|
+
* ephemeral or automated workflows where session history is not needed.
|
|
811
|
+
*
|
|
812
|
+
* @default true
|
|
813
|
+
*/
|
|
814
|
+
persistSession?: boolean;
|
|
815
|
+
/**
|
|
816
|
+
* Include partial/streaming message events in the output.
|
|
817
|
+
* When true, `SDKPartialAssistantMessage` events will be emitted during streaming.
|
|
818
|
+
*/
|
|
819
|
+
includePartialMessages?: boolean;
|
|
820
|
+
/**
|
|
821
|
+
* Maximum number of tokens the model can use for its thinking/reasoning process.
|
|
822
|
+
* Helps control cost and latency for complex tasks.
|
|
823
|
+
*/
|
|
824
|
+
maxThinkingTokens?: number;
|
|
825
|
+
/**
|
|
826
|
+
* Maximum number of conversation turns before the query stops.
|
|
827
|
+
* A turn consists of a user message and assistant response.
|
|
828
|
+
*/
|
|
829
|
+
maxTurns?: number;
|
|
830
|
+
/**
|
|
831
|
+
* Maximum budget in USD for the query. The query will stop if this
|
|
832
|
+
* budget is exceeded, returning an `error_max_budget_usd` result.
|
|
833
|
+
*/
|
|
834
|
+
maxBudgetUsd?: number;
|
|
835
|
+
/**
|
|
836
|
+
* MCP (Model Context Protocol) server configurations.
|
|
837
|
+
* Keys are server names, values are server configurations.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```typescript
|
|
841
|
+
* mcpServers: {
|
|
842
|
+
* 'my-server': {
|
|
843
|
+
* command: 'node',
|
|
844
|
+
* args: ['./my-mcp-server.js']
|
|
845
|
+
* }
|
|
846
|
+
* }
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
850
|
+
/**
|
|
851
|
+
* Claude model to use. Defaults to the CLI default model.
|
|
852
|
+
* Examples: 'claude-sonnet-4-5-20250929', 'claude-opus-4-20250514'
|
|
853
|
+
*/
|
|
854
|
+
model?: string;
|
|
855
|
+
/**
|
|
856
|
+
* Output format configuration for structured responses.
|
|
857
|
+
* When specified, the agent will return structured data matching the schema.
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```typescript
|
|
861
|
+
* outputFormat: {
|
|
862
|
+
* type: 'json_schema',
|
|
863
|
+
* schema: { type: 'object', properties: { result: { type: 'string' } } }
|
|
864
|
+
* }
|
|
865
|
+
* ```
|
|
866
|
+
*/
|
|
867
|
+
outputFormat?: OutputFormat;
|
|
868
|
+
/**
|
|
869
|
+
* Path to the Claude Code executable. Uses the built-in executable if not specified.
|
|
870
|
+
*/
|
|
871
|
+
pathToClaudeCodeExecutable?: string;
|
|
872
|
+
/**
|
|
873
|
+
* Permission mode for the session.
|
|
874
|
+
* - `'default'` - Standard permission behavior, prompts for dangerous operations
|
|
875
|
+
* - `'acceptEdits'` - Auto-accept file edit operations
|
|
876
|
+
* - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
|
|
877
|
+
* - `'plan'` - Planning mode, no execution of tools
|
|
878
|
+
* - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
|
|
879
|
+
*/
|
|
880
|
+
permissionMode?: PermissionMode;
|
|
881
|
+
/**
|
|
882
|
+
* Must be set to `true` when using `permissionMode: 'bypassPermissions'`.
|
|
883
|
+
* This is a safety measure to ensure intentional bypassing of permissions.
|
|
884
|
+
*/
|
|
885
|
+
allowDangerouslySkipPermissions?: boolean;
|
|
886
|
+
/**
|
|
887
|
+
* MCP tool name to use for permission prompts. When set, permission requests
|
|
888
|
+
* will be routed through this MCP tool instead of the default handler.
|
|
889
|
+
*/
|
|
890
|
+
permissionPromptToolName?: string;
|
|
891
|
+
/**
|
|
892
|
+
* Load plugins for this session. Plugins provide custom commands, agents,
|
|
893
|
+
* skills, and hooks that extend Claude Code's capabilities.
|
|
894
|
+
*
|
|
895
|
+
* Currently only local plugins are supported via the 'local' type.
|
|
896
|
+
*
|
|
897
|
+
* @example
|
|
898
|
+
* ```typescript
|
|
899
|
+
* plugins: [
|
|
900
|
+
* { type: 'local', path: './my-plugin' },
|
|
901
|
+
* { type: 'local', path: '/absolute/path/to/plugin' }
|
|
902
|
+
* ]
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
plugins?: SdkPluginConfig[];
|
|
906
|
+
/**
|
|
907
|
+
* Session ID to resume. Loads the conversation history from the specified session.
|
|
908
|
+
*/
|
|
909
|
+
resume?: string;
|
|
910
|
+
/**
|
|
911
|
+
* When resuming, only resume messages up to and including the message with this UUID.
|
|
912
|
+
* Use with `resume`. This allows you to resume from a specific point in the conversation.
|
|
913
|
+
* The message ID should be from `SDKAssistantMessage.uuid`.
|
|
914
|
+
*/
|
|
915
|
+
resumeSessionAt?: string;
|
|
916
|
+
/**
|
|
917
|
+
* Sandbox settings for command execution isolation.
|
|
918
|
+
*
|
|
919
|
+
* When enabled, commands are executed in a sandboxed environment that restricts
|
|
920
|
+
* filesystem and network access. This provides an additional security layer.
|
|
921
|
+
*
|
|
922
|
+
* **Important:** Filesystem and network restrictions are configured via permission
|
|
923
|
+
* rules, not via these sandbox settings:
|
|
924
|
+
* - Filesystem access: Use `Read` and `Edit` permission rules
|
|
925
|
+
* - Network access: Use `WebFetch` permission rules
|
|
926
|
+
*
|
|
927
|
+
* These sandbox settings control sandbox behavior (enabled, auto-allow, etc.),
|
|
928
|
+
* while the actual access restrictions come from your permission configuration.
|
|
929
|
+
*
|
|
930
|
+
* @example Enable sandboxing with auto-allow
|
|
931
|
+
* ```typescript
|
|
932
|
+
* sandbox: {
|
|
933
|
+
* enabled: true,
|
|
934
|
+
* autoAllowBashIfSandboxed: true
|
|
935
|
+
* }
|
|
936
|
+
* ```
|
|
937
|
+
*
|
|
938
|
+
* @example Configure network options (not restrictions)
|
|
939
|
+
* ```typescript
|
|
940
|
+
* sandbox: {
|
|
941
|
+
* enabled: true,
|
|
942
|
+
* network: {
|
|
943
|
+
* allowLocalBinding: true,
|
|
944
|
+
* allowUnixSockets: ['/var/run/docker.sock']
|
|
945
|
+
* }
|
|
946
|
+
* }
|
|
947
|
+
* ```
|
|
948
|
+
*
|
|
949
|
+
* @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
|
|
950
|
+
*/
|
|
951
|
+
sandbox?: SandboxSettings;
|
|
952
|
+
/**
|
|
953
|
+
* Control which filesystem settings to load.
|
|
954
|
+
* - `'user'` - Global user settings (`~/.claude/settings.json`)
|
|
955
|
+
* - `'project'` - Project settings (`.claude/settings.json`)
|
|
956
|
+
* - `'local'` - Local settings (`.claude/settings.local.json`)
|
|
957
|
+
*
|
|
958
|
+
* When omitted or empty, no filesystem settings are loaded (SDK isolation mode).
|
|
959
|
+
* Must include `'project'` to load CLAUDE.md files.
|
|
960
|
+
*/
|
|
961
|
+
settingSources?: SettingSource[];
|
|
962
|
+
/**
|
|
963
|
+
* Callback for stderr output from the Claude Code process.
|
|
964
|
+
* Useful for debugging and logging.
|
|
965
|
+
*/
|
|
966
|
+
stderr?: (data: string) => void;
|
|
967
|
+
/**
|
|
968
|
+
* Enforce strict validation of MCP server configurations.
|
|
969
|
+
* When true, invalid configurations will cause errors instead of warnings.
|
|
970
|
+
*/
|
|
971
|
+
strictMcpConfig?: boolean;
|
|
972
|
+
/**
|
|
973
|
+
* System prompt configuration.
|
|
974
|
+
* - `string` - Use a custom system prompt
|
|
975
|
+
* - `{ type: 'preset', preset: 'claude_code' }` - Use Claude Code's default system prompt
|
|
976
|
+
* - `{ type: 'preset', preset: 'claude_code', append: '...' }` - Use default prompt with appended instructions
|
|
977
|
+
*
|
|
978
|
+
* @example Custom prompt
|
|
979
|
+
* ```typescript
|
|
980
|
+
* systemPrompt: 'You are a helpful coding assistant.'
|
|
981
|
+
* ```
|
|
982
|
+
*
|
|
983
|
+
* @example Default with additions
|
|
984
|
+
* ```typescript
|
|
985
|
+
* systemPrompt: {
|
|
986
|
+
* type: 'preset',
|
|
987
|
+
* preset: 'claude_code',
|
|
988
|
+
* append: 'Always explain your reasoning.'
|
|
989
|
+
* }
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
systemPrompt?: string | {
|
|
993
|
+
type: 'preset';
|
|
994
|
+
preset: 'claude_code';
|
|
995
|
+
append?: string;
|
|
996
|
+
};
|
|
997
|
+
/**
|
|
998
|
+
* Custom function to spawn the Claude Code process.
|
|
999
|
+
* Use this to run Claude Code in VMs, containers, or remote environments.
|
|
1000
|
+
*
|
|
1001
|
+
* When provided, this function is called instead of the default local spawn.
|
|
1002
|
+
* The default behavior checks if the executable exists before spawning.
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```typescript
|
|
1006
|
+
* spawnClaudeCodeProcess: (options) => {
|
|
1007
|
+
* // Custom spawn logic for VM execution
|
|
1008
|
+
* // options contains: command, args, cwd, env, signal
|
|
1009
|
+
* return myVMProcess; // Must satisfy SpawnedProcess interface
|
|
1010
|
+
* }
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
spawnClaudeCodeProcess?: (options: SpawnOptions) => SpawnedProcess;
|
|
1014
|
+
};
|
|
1015
|
+
export declare function query(_params: {
|
|
1016
|
+
prompt: string | AsyncIterable<SDKUserMessage>;
|
|
1017
|
+
options?: Options;
|
|
1018
|
+
}): Query;
|
|
1019
|
+
/**
|
|
1020
|
+
* V2 API - UNSTABLE
|
|
1021
|
+
* Create a persistent session for multi-turn conversations
|
|
1022
|
+
*/
|
|
1023
|
+
export declare function unstable_v2_createSession(_options: SDKSessionOptions): SDKSession;
|
|
1024
|
+
/**
|
|
1025
|
+
* V2 API - UNSTABLE
|
|
1026
|
+
* Resume an existing session by ID
|
|
1027
|
+
*/
|
|
1028
|
+
export declare function unstable_v2_resumeSession(_sessionId: string, _options: SDKSessionOptions): SDKSession;
|
|
1029
|
+
/**
|
|
1030
|
+
* V2 API - UNSTABLE
|
|
1031
|
+
* One-shot convenience function for single prompts
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* const result = await unstable_v2_prompt("What files are here?", {
|
|
1036
|
+
* model: 'claude-sonnet-4-5-20250929'
|
|
1037
|
+
* })
|
|
1038
|
+
* ```
|
|
1039
|
+
*/
|
|
1040
|
+
export declare function unstable_v2_prompt(_message: string, _options: SDKSessionOptions): Promise<SDKResultMessage>;
|
|
1041
|
+
export { SpawnOptions, SpawnedProcess, Transport };
|