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

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.
@@ -1,553 +1,5 @@
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';
1
+ export * from './coreTypes.generated.js';
4
2
  export type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations, } from '../sandboxTypes.js';
5
- export type NonNullableUsage = {
6
- [K in keyof Usage]: NonNullable<Usage[K]>;
7
- };
8
- export type ModelUsage = {
9
- inputTokens: number;
10
- outputTokens: number;
11
- cacheReadInputTokens: number;
12
- cacheCreationInputTokens: number;
13
- webSearchRequests: number;
14
- costUSD: number;
15
- contextWindow: number;
16
- };
17
- export type OutputFormatType = 'json_schema';
18
- export type BaseOutputFormat = {
19
- type: OutputFormatType;
20
- };
21
- export type JsonSchemaOutputFormat = BaseOutputFormat & {
22
- type: 'json_schema';
23
- schema: Record<string, unknown>;
24
- };
25
- export type OutputFormat = JsonSchemaOutputFormat;
26
- export type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';
27
- export type ConfigScope = 'local' | 'user' | 'project';
28
- /**
29
- * Allowed beta headers that can be passed via SDK options.
30
- */
31
- export type SdkBeta = 'context-1m-2025-08-07';
32
- export type McpStdioServerConfig = {
33
- type?: 'stdio';
34
- command: string;
35
- args?: string[];
36
- env?: Record<string, string>;
37
- };
38
- export type McpSSEServerConfig = {
39
- type: 'sse';
40
- url: string;
41
- headers?: Record<string, string>;
42
- };
43
- export type McpHttpServerConfig = {
44
- type: 'http';
45
- url: string;
46
- headers?: Record<string, string>;
47
- };
48
- export type McpSdkServerConfig = {
49
- type: 'sdk';
50
- name: string;
51
- };
52
- /**
53
- * MCP server config types that can be serialized for process transport.
54
- * Does not include McpSdkServerConfigWithInstance which contains a non-serializable McpServer instance.
55
- */
56
- export type McpServerConfigForProcessTransport = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig | McpSdkServerConfig;
57
- /**
58
- * Status information for an MCP server connection.
59
- */
60
- export type McpServerStatus = {
61
- /** Server name as configured */
62
- name: string;
63
- /** Current connection status */
64
- status: 'connected' | 'failed' | 'needs-auth' | 'pending';
65
- /** Server information (available when connected) */
66
- serverInfo?: {
67
- name: string;
68
- version: string;
69
- };
70
- };
71
- /**
72
- * Result of a setMcpServers operation.
73
- */
74
- export type McpSetServersResult = {
75
- /** Names of servers that were added */
76
- added: string[];
77
- /** Names of servers that were removed */
78
- removed: string[];
79
- /** Map of server names to error messages for servers that failed to connect */
80
- errors: Record<string, string>;
81
- };
82
- type PermissionUpdateDestination = 'userSettings' | 'projectSettings' | 'localSettings' | 'session' | 'cliArg';
83
- export type PermissionBehavior = 'allow' | 'deny' | 'ask';
84
- export type PermissionUpdate = {
85
- type: 'addRules';
86
- rules: PermissionRuleValue[];
87
- behavior: PermissionBehavior;
88
- destination: PermissionUpdateDestination;
89
- } | {
90
- type: 'replaceRules';
91
- rules: PermissionRuleValue[];
92
- behavior: PermissionBehavior;
93
- destination: PermissionUpdateDestination;
94
- } | {
95
- type: 'removeRules';
96
- rules: PermissionRuleValue[];
97
- behavior: PermissionBehavior;
98
- destination: PermissionUpdateDestination;
99
- } | {
100
- type: 'setMode';
101
- mode: PermissionMode;
102
- destination: PermissionUpdateDestination;
103
- } | {
104
- type: 'addDirectories';
105
- directories: string[];
106
- destination: PermissionUpdateDestination;
107
- } | {
108
- type: 'removeDirectories';
109
- directories: string[];
110
- destination: PermissionUpdateDestination;
111
- };
112
- export type PermissionResult = {
113
- behavior: 'allow';
114
- /**
115
- * Updated tool input to use, if any changes are needed.
116
- *
117
- * For example if the user was given the option to update the tool use
118
- * input before approving, then this would be the updated input which
119
- * would be executed by the tool.
120
- */
121
- updatedInput: Record<string, unknown>;
122
- /**
123
- * Permissions updates to be applied as part of accepting this tool use.
124
- *
125
- * Typically this is used as part of the 'always allow' flow and these
126
- * permission updates are from the `suggestions` field from the
127
- * CanUseTool callback.
128
- *
129
- * It is recommended that you use these suggestions rather than
130
- * attempting to re-derive them from the tool use input, as the
131
- * suggestions may include other permission changes such as adding
132
- * directories or incorporate complex tool-use logic such as bash
133
- * commands.
134
- */
135
- updatedPermissions?: PermissionUpdate[];
136
- /**
137
- * The tool use ID. Supplied and used internally.
138
- */
139
- toolUseID?: string;
140
- } | {
141
- behavior: 'deny';
142
- /**
143
- * Message indicating the reason for denial, or guidance of what the
144
- * model should do instead.
145
- */
146
- message: string;
147
- /**
148
- * If true, interrupt execution and do not continue.
149
- *
150
- * Typically this should be set to true when the user says 'no' with no
151
- * further guidance. Leave unset or false if the user provides guidance
152
- * which the model should incorporate and continue.
153
- */
154
- interrupt?: boolean;
155
- /**
156
- * The tool use ID. Supplied and used internally.
157
- */
158
- toolUseID?: string;
159
- };
160
- export type PermissionRuleValue = {
161
- toolName: string;
162
- ruleContent?: string;
163
- };
164
- /**
165
- * Permission mode for controlling how tool executions are handled.
166
- * - `'default'` - Standard behavior, prompts for dangerous operations
167
- * - `'acceptEdits'` - Auto-accept file edit operations
168
- * - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
169
- * - `'plan'` - Planning mode, no actual tool execution
170
- * - `'delegate'` - Delegate mode, restricts team leader to only Teammate and Task tools
171
- * - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
172
- */
173
- export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'delegate' | 'dontAsk';
3
+ export type { NonNullableUsage } from './sdkUtilityTypes.js';
174
4
  export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
175
- export type HookEvent = (typeof HOOK_EVENTS)[number];
176
- export type BaseHookInput = {
177
- session_id: string;
178
- transcript_path: string;
179
- cwd: string;
180
- permission_mode?: string;
181
- };
182
- export type PreToolUseHookInput = BaseHookInput & {
183
- hook_event_name: 'PreToolUse';
184
- tool_name: string;
185
- tool_input: unknown;
186
- tool_use_id: string;
187
- };
188
- export type PermissionRequestHookInput = BaseHookInput & {
189
- hook_event_name: 'PermissionRequest';
190
- tool_name: string;
191
- tool_input: unknown;
192
- permission_suggestions?: PermissionUpdate[];
193
- };
194
- export type PostToolUseHookInput = BaseHookInput & {
195
- hook_event_name: 'PostToolUse';
196
- tool_name: string;
197
- tool_input: unknown;
198
- tool_response: unknown;
199
- tool_use_id: string;
200
- };
201
- export type PostToolUseFailureHookInput = BaseHookInput & {
202
- hook_event_name: 'PostToolUseFailure';
203
- tool_name: string;
204
- tool_input: unknown;
205
- tool_use_id: string;
206
- error: string;
207
- is_interrupt?: boolean;
208
- };
209
- export type NotificationHookInput = BaseHookInput & {
210
- hook_event_name: 'Notification';
211
- message: string;
212
- title?: string;
213
- notification_type: string;
214
- };
215
- export type UserPromptSubmitHookInput = BaseHookInput & {
216
- hook_event_name: 'UserPromptSubmit';
217
- prompt: string;
218
- };
219
- export type SessionStartHookInput = BaseHookInput & {
220
- hook_event_name: 'SessionStart';
221
- source: 'startup' | 'resume' | 'clear' | 'compact';
222
- };
223
- export type StopHookInput = BaseHookInput & {
224
- hook_event_name: 'Stop';
225
- stop_hook_active: boolean;
226
- };
227
- export type SubagentStartHookInput = BaseHookInput & {
228
- hook_event_name: 'SubagentStart';
229
- agent_id: string;
230
- agent_type: string;
231
- };
232
- export type SubagentStopHookInput = BaseHookInput & {
233
- hook_event_name: 'SubagentStop';
234
- stop_hook_active: boolean;
235
- agent_id: string;
236
- agent_transcript_path: string;
237
- };
238
- export type PreCompactHookInput = BaseHookInput & {
239
- hook_event_name: 'PreCompact';
240
- trigger: 'manual' | 'auto';
241
- custom_instructions: string | null;
242
- };
243
- export declare const EXIT_REASONS: string[];
244
- export type ExitReason = (typeof EXIT_REASONS)[number];
245
- export type SessionEndHookInput = BaseHookInput & {
246
- hook_event_name: 'SessionEnd';
247
- reason: ExitReason;
248
- };
249
- export type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PermissionRequestHookInput;
250
- export type AsyncHookJSONOutput = {
251
- async: true;
252
- asyncTimeout?: number;
253
- };
254
- export type SyncHookJSONOutput = {
255
- continue?: boolean;
256
- suppressOutput?: boolean;
257
- stopReason?: string;
258
- decision?: 'approve' | 'block';
259
- systemMessage?: string;
260
- reason?: string;
261
- hookSpecificOutput?: {
262
- hookEventName: 'PreToolUse';
263
- permissionDecision?: 'allow' | 'deny' | 'ask';
264
- permissionDecisionReason?: string;
265
- updatedInput?: Record<string, unknown>;
266
- } | {
267
- hookEventName: 'UserPromptSubmit';
268
- additionalContext?: string;
269
- } | {
270
- hookEventName: 'SessionStart';
271
- additionalContext?: string;
272
- } | {
273
- hookEventName: 'SubagentStart';
274
- additionalContext?: string;
275
- } | {
276
- hookEventName: 'PostToolUse';
277
- additionalContext?: string;
278
- updatedMCPToolOutput?: unknown;
279
- } | {
280
- hookEventName: 'PostToolUseFailure';
281
- additionalContext?: string;
282
- } | {
283
- hookEventName: 'PermissionRequest';
284
- decision: {
285
- behavior: 'allow';
286
- updatedInput?: Record<string, unknown>;
287
- updatedPermissions?: PermissionUpdate[];
288
- } | {
289
- behavior: 'deny';
290
- message?: string;
291
- interrupt?: boolean;
292
- };
293
- };
294
- };
295
- export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput;
296
- /**
297
- * Information about an available skill (invoked via /command syntax).
298
- */
299
- export type SlashCommand = {
300
- /** Skill name (without the leading slash) */
301
- name: string;
302
- /** Description of what the skill does */
303
- description: string;
304
- /** Hint for skill arguments (e.g., "<file>") */
305
- argumentHint: string;
306
- };
307
- /**
308
- * Information about an available model.
309
- */
310
- export type ModelInfo = {
311
- /** Model identifier to use in API calls */
312
- value: string;
313
- /** Human-readable display name */
314
- displayName: string;
315
- /** Description of the model's capabilities */
316
- description: string;
317
- };
318
- /** Information about the logged in user's account. */
319
- export type AccountInfo = {
320
- email?: string;
321
- organization?: string;
322
- subscriptionType?: string;
323
- tokenSource?: string;
324
- apiKeySource?: string;
325
- };
326
- /**
327
- * MCP server specification for agents. Can be either:
328
- * - A string reference to an existing MCP server by name
329
- * - An inline MCP server definition as \{ [name]: config \}
330
- */
331
- export type AgentMcpServerSpec = string | {
332
- [name: string]: McpServerConfigForProcessTransport;
333
- };
334
- /**
335
- * Definition for a custom subagent that can be invoked via the Task tool.
336
- */
337
- export type AgentDefinition = {
338
- /** Natural language description of when to use this agent */
339
- description: string;
340
- /** Array of allowed tool names. If omitted, inherits all tools from parent */
341
- tools?: string[];
342
- /** Array of tool names to explicitly disallow for this agent */
343
- disallowedTools?: string[];
344
- /** The agent's system prompt */
345
- prompt: string;
346
- /** Model to use for this agent. If omitted or 'inherit', uses the main model */
347
- model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
348
- /**
349
- * MCP servers specific to this agent. These are additive to any parent MCP servers.
350
- * Servers are connected when the agent starts and cleaned up when it finishes.
351
- *
352
- * @example
353
- * ```typescript
354
- * mcpServers: [
355
- * 'slack', // Reference existing server by name
356
- * { // Inline server definition
357
- * 'custom-server': {
358
- * type: 'stdio',
359
- * command: 'node',
360
- * args: ['./my-server.js']
361
- * }
362
- * }
363
- * ]
364
- * ```
365
- */
366
- mcpServers?: AgentMcpServerSpec[];
367
- /** Experimental: Critical reminder added to system prompt */
368
- criticalSystemReminder_EXPERIMENTAL?: string;
369
- };
370
- /**
371
- * Source for loading filesystem-based settings.
372
- * - `'user'` - Global user settings (`~/.claude/settings.json`)
373
- * - `'project'` - Project settings (`.claude/settings.json`)
374
- * - `'local'` - Local settings (`.claude/settings.local.json`)
375
- */
376
- export type SettingSource = 'user' | 'project' | 'local';
377
- /**
378
- * Configuration for loading a plugin.
379
- */
380
- export type SdkPluginConfig = {
381
- /** Plugin type. Currently only 'local' is supported */
382
- type: 'local';
383
- /** Absolute or relative path to the plugin directory */
384
- path: string;
385
- };
386
- /**
387
- * Result of a rewindFiles operation.
388
- */
389
- export type RewindFilesResult = {
390
- canRewind: boolean;
391
- error?: string;
392
- filesChanged?: string[];
393
- insertions?: number;
394
- deletions?: number;
395
- };
396
- type SDKUserMessageContent = {
397
- type: 'user';
398
- message: APIUserMessage;
399
- parent_tool_use_id: string | null;
400
- /**
401
- * True if this is a 'synthetic' user message which did not originate from
402
- * the user directly, but instead was generated by the system.
403
- */
404
- isSynthetic?: boolean;
405
- /**
406
- * If present, the JSON result of a tool use that this user message is
407
- * responding to. This is provided to make it easier for applications to
408
- * present the tool result in a formatted way. The model only receives
409
- * the content within the user message.
410
- * The specific format is tool-dependent.
411
- */
412
- tool_use_result?: unknown;
413
- };
414
- export type SDKUserMessage = SDKUserMessageContent & {
415
- uuid?: UUID;
416
- session_id: string;
417
- };
418
- export type SDKUserMessageReplay = SDKUserMessageContent & {
419
- uuid: UUID;
420
- session_id: string;
421
- /**
422
- * True if this is a replay/acknowledgment of a user message that was already
423
- * added to the messages array. Used internally to prevent duplicate messages.
424
- */
425
- isReplay: true;
426
- };
427
- export type SDKAssistantMessageError = 'authentication_failed' | 'billing_error' | 'rate_limit' | 'invalid_request' | 'server_error' | 'unknown';
428
- export type SDKAssistantMessage = {
429
- type: 'assistant';
430
- message: APIAssistantMessage;
431
- parent_tool_use_id: string | null;
432
- error?: SDKAssistantMessageError;
433
- uuid: UUID;
434
- session_id: string;
435
- };
436
- export type SDKPermissionDenial = {
437
- tool_name: string;
438
- tool_use_id: string;
439
- tool_input: Record<string, unknown>;
440
- };
441
- export type SDKResultMessage = {
442
- type: 'result';
443
- subtype: 'success';
444
- duration_ms: number;
445
- duration_api_ms: number;
446
- is_error: boolean;
447
- num_turns: number;
448
- result: string;
449
- total_cost_usd: number;
450
- usage: NonNullableUsage;
451
- modelUsage: {
452
- [modelName: string]: ModelUsage;
453
- };
454
- permission_denials: SDKPermissionDenial[];
455
- structured_output?: unknown;
456
- uuid: UUID;
457
- session_id: string;
458
- } | {
459
- type: 'result';
460
- subtype: 'error_during_execution' | 'error_max_turns' | 'error_max_budget_usd' | 'error_max_structured_output_retries';
461
- duration_ms: number;
462
- duration_api_ms: number;
463
- is_error: boolean;
464
- num_turns: number;
465
- total_cost_usd: number;
466
- usage: NonNullableUsage;
467
- modelUsage: {
468
- [modelName: string]: ModelUsage;
469
- };
470
- permission_denials: SDKPermissionDenial[];
471
- errors: string[];
472
- uuid: UUID;
473
- session_id: string;
474
- };
475
- export type SDKSystemMessage = {
476
- type: 'system';
477
- subtype: 'init';
478
- agents?: string[];
479
- apiKeySource: ApiKeySource;
480
- betas?: string[];
481
- claude_code_version: string;
482
- cwd: string;
483
- tools: string[];
484
- mcp_servers: {
485
- name: string;
486
- status: string;
487
- }[];
488
- model: string;
489
- permissionMode: PermissionMode;
490
- slash_commands: string[];
491
- output_style: string;
492
- skills: string[];
493
- plugins: {
494
- name: string;
495
- path: string;
496
- }[];
497
- uuid: UUID;
498
- session_id: string;
499
- };
500
- export type SDKPartialAssistantMessage = {
501
- type: 'stream_event';
502
- event: RawMessageStreamEvent;
503
- parent_tool_use_id: string | null;
504
- uuid: UUID;
505
- session_id: string;
506
- };
507
- export type SDKCompactBoundaryMessage = {
508
- type: 'system';
509
- subtype: 'compact_boundary';
510
- compact_metadata: {
511
- trigger: 'manual' | 'auto';
512
- pre_tokens: number;
513
- };
514
- uuid: UUID;
515
- session_id: string;
516
- };
517
- export type SDKStatus = 'compacting' | null;
518
- export type SDKStatusMessage = {
519
- type: 'system';
520
- subtype: 'status';
521
- status: SDKStatus;
522
- uuid: UUID;
523
- session_id: string;
524
- };
525
- export type SDKHookResponseMessage = {
526
- type: 'system';
527
- subtype: 'hook_response';
528
- hook_name: string;
529
- hook_event: string;
530
- stdout: string;
531
- stderr: string;
532
- exit_code?: number;
533
- uuid: UUID;
534
- session_id: string;
535
- };
536
- export type SDKToolProgressMessage = {
537
- type: 'tool_progress';
538
- tool_use_id: string;
539
- tool_name: string;
540
- parent_tool_use_id: string | null;
541
- elapsed_time_seconds: number;
542
- uuid: UUID;
543
- session_id: string;
544
- };
545
- export type SDKAuthStatusMessage = {
546
- type: 'auth_status';
547
- isAuthenticating: boolean;
548
- output: string[];
549
- error?: string;
550
- uuid: UUID;
551
- session_id: string;
552
- };
553
- export type SDKMessage = SDKAssistantMessage | SDKUserMessage | SDKUserMessageReplay | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage | SDKCompactBoundaryMessage | SDKStatusMessage | SDKHookResponseMessage | SDKToolProgressMessage | SDKAuthStatusMessage;
5
+ export declare const EXIT_REASONS: readonly ["clear", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"];