@anthropic-ai/claude-agent-sdk 0.2.0 → 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/cli.js +1682 -1745
- package/package.json +1 -1
- package/sdk-tools.d.ts +4 -0
- package/sdk.d.ts +1586 -1
- package/sdk.mjs +10 -9
- package/entrypoints/agentSdkTypes.d.ts +0 -56
- package/entrypoints/sandboxTypes.d.ts +0 -44
- package/entrypoints/sdk/controlTypes.d.ts +0 -2
- package/entrypoints/sdk/controlTypes.generated.d.ts +0 -135
- package/entrypoints/sdk/coreTypes.d.ts +0 -5
- package/entrypoints/sdk/coreTypes.generated.d.ts +0 -476
- package/entrypoints/sdk/runtimeTypes.d.ts +0 -560
- package/entrypoints/sdk/sdkUtilityTypes.d.ts +0 -4
- package/transport/processTransportTypes.d.ts +0 -60
- package/transport/transport.d.ts +0 -30
|
@@ -1,560 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import type { ZodRawShape } from 'zod';
|
|
4
|
-
import type { ZodRawShape as Zod4RawShape } from 'zod/v4';
|
|
5
|
-
export type AnyZodRawShape = ZodRawShape | Zod4RawShape;
|
|
6
|
-
export type InferShape<T extends AnyZodRawShape> = {
|
|
7
|
-
[K in keyof T]: T[K] extends {
|
|
8
|
-
_output: infer O;
|
|
9
|
-
} ? O : never;
|
|
10
|
-
} & {};
|
|
11
|
-
import type { SpawnedProcess, SpawnOptions } from '../../transport/processTransportTypes.js';
|
|
12
|
-
import type { Transport } from '../../transport/transport.js';
|
|
13
|
-
import type { PermissionResult, PermissionUpdate, PermissionMode, HookInput, HookJSONOutput, HookEvent, McpStdioServerConfig, McpSSEServerConfig, McpHttpServerConfig, McpSdkServerConfig, SlashCommand, ModelInfo, McpServerStatus, AccountInfo, McpSetServersResult, RewindFilesResult, SDKMessage, SDKUserMessage, OutputFormat, SdkBeta, AgentDefinition, SettingSource, SdkPluginConfig, SandboxSettings } from './coreTypes.js';
|
|
14
|
-
export type { SpawnOptions, SpawnedProcess, Transport };
|
|
15
|
-
/**
|
|
16
|
-
* Permission callback function for controlling tool usage.
|
|
17
|
-
* Called before each tool execution to determine if it should be allowed.
|
|
18
|
-
*/
|
|
19
|
-
export type CanUseTool = (toolName: string, input: Record<string, unknown>, options: {
|
|
20
|
-
/** Signaled if the operation should be aborted. */
|
|
21
|
-
signal: AbortSignal;
|
|
22
|
-
/**
|
|
23
|
-
* Suggestions for updating permissions so that the user will not be
|
|
24
|
-
* prompted again for this tool during this session.
|
|
25
|
-
*
|
|
26
|
-
* Typically if presenting the user an option 'always allow' or similar,
|
|
27
|
-
* then this full set of suggestions should be returned as the
|
|
28
|
-
* `updatedPermissions` in the PermissionResult.
|
|
29
|
-
*/
|
|
30
|
-
suggestions?: PermissionUpdate[];
|
|
31
|
-
/**
|
|
32
|
-
* The file path that triggered the permission request, if applicable.
|
|
33
|
-
* For example, when a Bash command tries to access a path outside allowed directories.
|
|
34
|
-
*/
|
|
35
|
-
blockedPath?: string;
|
|
36
|
-
/** Explains why this permission request was triggered. */
|
|
37
|
-
decisionReason?: string;
|
|
38
|
-
/**
|
|
39
|
-
* Unique identifier for this specific tool call within the assistant message.
|
|
40
|
-
* Multiple tool calls in the same assistant message will have different toolUseIDs.
|
|
41
|
-
*/
|
|
42
|
-
toolUseID: string;
|
|
43
|
-
/** If running within the context of a sub-agent, the sub-agent's ID. */
|
|
44
|
-
agentID?: string;
|
|
45
|
-
}) => Promise<PermissionResult>;
|
|
46
|
-
/**
|
|
47
|
-
* Hook callback function for responding to events during execution.
|
|
48
|
-
*/
|
|
49
|
-
export type HookCallback = (input: HookInput, toolUseID: string | undefined, options: {
|
|
50
|
-
signal: AbortSignal;
|
|
51
|
-
}) => Promise<HookJSONOutput>;
|
|
52
|
-
/**
|
|
53
|
-
* Hook callback matcher containing hook callbacks and optional pattern matching.
|
|
54
|
-
*/
|
|
55
|
-
export interface HookCallbackMatcher {
|
|
56
|
-
matcher?: string;
|
|
57
|
-
hooks: HookCallback[];
|
|
58
|
-
/** Timeout in seconds for all hooks in this matcher */
|
|
59
|
-
timeout?: number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* MCP SDK server config with an actual McpServer instance.
|
|
63
|
-
* Not serializable - contains a live McpServer object.
|
|
64
|
-
*/
|
|
65
|
-
export type McpSdkServerConfigWithInstance = McpSdkServerConfig & {
|
|
66
|
-
instance: McpServer;
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Union of all MCP server config types, including those with non-serializable instances.
|
|
70
|
-
*/
|
|
71
|
-
export type McpServerConfig = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig | McpSdkServerConfigWithInstance;
|
|
72
|
-
/**
|
|
73
|
-
* MCP tool definition for SDK servers.
|
|
74
|
-
* Contains a handler function, so not serializable.
|
|
75
|
-
* Supports both Zod 3 and Zod 4 schemas.
|
|
76
|
-
*/
|
|
77
|
-
export type SdkMcpToolDefinition<Schema extends AnyZodRawShape = AnyZodRawShape> = {
|
|
78
|
-
name: string;
|
|
79
|
-
description: string;
|
|
80
|
-
inputSchema: Schema;
|
|
81
|
-
handler: (args: InferShape<Schema>, extra: unknown) => Promise<CallToolResult>;
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* Query interface with methods for controlling query execution.
|
|
85
|
-
* Extends AsyncGenerator and has methods, so not serializable.
|
|
86
|
-
*/
|
|
87
|
-
export interface Query extends AsyncGenerator<SDKMessage, void> {
|
|
88
|
-
/**
|
|
89
|
-
* Control Requests
|
|
90
|
-
* The following methods are control requests, and are only supported when
|
|
91
|
-
* streaming input/output is used.
|
|
92
|
-
*/
|
|
93
|
-
/**
|
|
94
|
-
* Interrupt the current query execution. The query will stop processing
|
|
95
|
-
* and return control to the caller.
|
|
96
|
-
*/
|
|
97
|
-
interrupt(): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Change the permission mode for the current session.
|
|
100
|
-
* Only available in streaming input mode.
|
|
101
|
-
*
|
|
102
|
-
* @param mode - The new permission mode to set
|
|
103
|
-
*/
|
|
104
|
-
setPermissionMode(mode: PermissionMode): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Change the model used for subsequent responses.
|
|
107
|
-
* Only available in streaming input mode.
|
|
108
|
-
*
|
|
109
|
-
* @param model - The model identifier to use, or undefined to use the default
|
|
110
|
-
*/
|
|
111
|
-
setModel(model?: string): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
* Set the maximum number of thinking tokens the model is allowed to use
|
|
114
|
-
* when generating its response. This can be used to limit the amount of
|
|
115
|
-
* tokens the model uses for its response, which can help control cost and
|
|
116
|
-
* latency.
|
|
117
|
-
*
|
|
118
|
-
* Use `null` to clear any previously set limit and allow the model to
|
|
119
|
-
* use the default maximum thinking tokens.
|
|
120
|
-
*
|
|
121
|
-
* @param maxThinkingTokens - Maximum tokens for thinking, or null to clear the limit
|
|
122
|
-
*/
|
|
123
|
-
setMaxThinkingTokens(maxThinkingTokens: number | null): Promise<void>;
|
|
124
|
-
/**
|
|
125
|
-
* Get the list of available skills for the current session.
|
|
126
|
-
*
|
|
127
|
-
* @returns Array of available skills with their names and descriptions
|
|
128
|
-
*/
|
|
129
|
-
supportedCommands(): Promise<SlashCommand[]>;
|
|
130
|
-
/**
|
|
131
|
-
* Get the list of available models.
|
|
132
|
-
*
|
|
133
|
-
* @returns Array of model information including display names and descriptions
|
|
134
|
-
*/
|
|
135
|
-
supportedModels(): Promise<ModelInfo[]>;
|
|
136
|
-
/**
|
|
137
|
-
* Get the current status of all configured MCP servers.
|
|
138
|
-
*
|
|
139
|
-
* @returns Array of MCP server statuses (connected, failed, needs-auth, pending)
|
|
140
|
-
*/
|
|
141
|
-
mcpServerStatus(): Promise<McpServerStatus[]>;
|
|
142
|
-
/**
|
|
143
|
-
* Get information about the authenticated account.
|
|
144
|
-
*
|
|
145
|
-
* @returns Account information including email, organization, and subscription type
|
|
146
|
-
*/
|
|
147
|
-
accountInfo(): Promise<AccountInfo>;
|
|
148
|
-
/**
|
|
149
|
-
* Rewind tracked files to their state at a specific user message.
|
|
150
|
-
* Requires file checkpointing to be enabled via the `enableFileCheckpointing` option.
|
|
151
|
-
*
|
|
152
|
-
* @param userMessageId - UUID of the user message to rewind to
|
|
153
|
-
* @param options - Options object with optional `dryRun` boolean to preview changes without modifying files
|
|
154
|
-
* @returns Object with canRewind boolean, optional error message, and file change statistics
|
|
155
|
-
*/
|
|
156
|
-
rewindFiles(userMessageId: string, options?: {
|
|
157
|
-
dryRun?: boolean;
|
|
158
|
-
}): Promise<RewindFilesResult>;
|
|
159
|
-
/**
|
|
160
|
-
* Dynamically set the MCP servers for this session.
|
|
161
|
-
* This replaces the current set of dynamically-added MCP servers with the provided set.
|
|
162
|
-
* Servers that are removed will be disconnected, and new servers will be connected.
|
|
163
|
-
*
|
|
164
|
-
* Supports both process-based servers (stdio, sse, http) and SDK servers (in-process).
|
|
165
|
-
* SDK servers are handled locally in the SDK process, while process-based servers
|
|
166
|
-
* are managed by the CLI subprocess.
|
|
167
|
-
*
|
|
168
|
-
* Note: This only affects servers added dynamically via this method or the SDK.
|
|
169
|
-
* Servers configured via settings files are not affected.
|
|
170
|
-
*
|
|
171
|
-
* @param servers - Record of server name to configuration. Pass an empty object to remove all dynamic servers.
|
|
172
|
-
* @returns Information about which servers were added, removed, and any connection errors
|
|
173
|
-
*/
|
|
174
|
-
setMcpServers(servers: Record<string, McpServerConfig>): Promise<McpSetServersResult>;
|
|
175
|
-
/**
|
|
176
|
-
* Stream input messages to the query.
|
|
177
|
-
* Used internally for multi-turn conversations.
|
|
178
|
-
*
|
|
179
|
-
* @param stream - Async iterable of user messages to send
|
|
180
|
-
*/
|
|
181
|
-
streamInput(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* V2 API - UNSTABLE
|
|
185
|
-
* Options for creating a session.
|
|
186
|
-
*/
|
|
187
|
-
export type SDKSessionOptions = {
|
|
188
|
-
/** Model to use */
|
|
189
|
-
model: string;
|
|
190
|
-
/** Path to Claude Code executable */
|
|
191
|
-
pathToClaudeCodeExecutable?: string;
|
|
192
|
-
/** Executable to use (node, bun) */
|
|
193
|
-
executable?: 'node' | 'bun';
|
|
194
|
-
/** Arguments to pass to executable */
|
|
195
|
-
executableArgs?: string[];
|
|
196
|
-
/**
|
|
197
|
-
* Environment variables to pass to the Claude Code process.
|
|
198
|
-
* Defaults to `process.env`.
|
|
199
|
-
*/
|
|
200
|
-
env?: {
|
|
201
|
-
[envVar: string]: string | undefined;
|
|
202
|
-
};
|
|
203
|
-
};
|
|
204
|
-
/**
|
|
205
|
-
* V2 API - UNSTABLE
|
|
206
|
-
* Session interface for multi-turn conversations.
|
|
207
|
-
* Has methods, so not serializable.
|
|
208
|
-
*/
|
|
209
|
-
export interface SDKSession {
|
|
210
|
-
/**
|
|
211
|
-
* The session ID. Available after receiving the first message.
|
|
212
|
-
* For resumed sessions, available immediately.
|
|
213
|
-
* Throws if accessed before the session is initialized.
|
|
214
|
-
*/
|
|
215
|
-
readonly sessionId: string;
|
|
216
|
-
/** Send a message to the agent */
|
|
217
|
-
send(message: string | SDKUserMessage): Promise<void>;
|
|
218
|
-
/** Stream messages from the agent */
|
|
219
|
-
stream(): AsyncGenerator<SDKMessage, void>;
|
|
220
|
-
/** Close the session */
|
|
221
|
-
close(): void;
|
|
222
|
-
/** Async disposal support (calls close if not already closed) */
|
|
223
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Options for the query function.
|
|
227
|
-
* Contains callbacks and other non-serializable fields.
|
|
228
|
-
*/
|
|
229
|
-
export type Options = {
|
|
230
|
-
/**
|
|
231
|
-
* Controller for cancelling the query. When aborted, the query will stop
|
|
232
|
-
* and clean up resources.
|
|
233
|
-
*/
|
|
234
|
-
abortController?: AbortController;
|
|
235
|
-
/**
|
|
236
|
-
* Additional directories Claude can access beyond the current working directory.
|
|
237
|
-
* Paths should be absolute.
|
|
238
|
-
*/
|
|
239
|
-
additionalDirectories?: string[];
|
|
240
|
-
/**
|
|
241
|
-
* Programmatically define custom subagents that can be invoked via the Task tool.
|
|
242
|
-
* Keys are agent names, values are agent definitions.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* agents: {
|
|
247
|
-
* 'test-runner': {
|
|
248
|
-
* description: 'Runs tests and reports results',
|
|
249
|
-
* prompt: 'You are a test runner...',
|
|
250
|
-
* tools: ['Read', 'Grep', 'Glob', 'Bash']
|
|
251
|
-
* }
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
agents?: Record<string, AgentDefinition>;
|
|
256
|
-
/**
|
|
257
|
-
* List of tool names that are auto-allowed without prompting for permission.
|
|
258
|
-
* These tools will execute automatically without asking the user for approval.
|
|
259
|
-
* To restrict which tools are available, use the `tools` option instead.
|
|
260
|
-
*/
|
|
261
|
-
allowedTools?: string[];
|
|
262
|
-
/**
|
|
263
|
-
* Custom permission handler for controlling tool usage. Called before each
|
|
264
|
-
* tool execution to determine if it should be allowed, denied, or prompt the user.
|
|
265
|
-
*/
|
|
266
|
-
canUseTool?: CanUseTool;
|
|
267
|
-
/**
|
|
268
|
-
* Continue the most recent conversation instead of starting a new one.
|
|
269
|
-
* Mutually exclusive with `resume`.
|
|
270
|
-
*/
|
|
271
|
-
continue?: boolean;
|
|
272
|
-
/**
|
|
273
|
-
* Current working directory for the session. Defaults to `process.cwd()`.
|
|
274
|
-
*/
|
|
275
|
-
cwd?: string;
|
|
276
|
-
/**
|
|
277
|
-
* List of tool names that are disallowed. These tools will be removed
|
|
278
|
-
* from the model's context and cannot be used, even if they would
|
|
279
|
-
* otherwise be allowed.
|
|
280
|
-
*/
|
|
281
|
-
disallowedTools?: string[];
|
|
282
|
-
/**
|
|
283
|
-
* Specify the base set of available built-in tools.
|
|
284
|
-
* - `string[]` - Array of specific tool names (e.g., `['Bash', 'Read', 'Edit']`)
|
|
285
|
-
* - `[]` (empty array) - Disable all built-in tools
|
|
286
|
-
* - `{ type: 'preset'; preset: 'claude_code' }` - Use all default Claude Code tools
|
|
287
|
-
*/
|
|
288
|
-
tools?: string[] | {
|
|
289
|
-
type: 'preset';
|
|
290
|
-
preset: 'claude_code';
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* Environment variables to pass to the Claude Code process.
|
|
294
|
-
* Defaults to `process.env`.
|
|
295
|
-
*/
|
|
296
|
-
env?: {
|
|
297
|
-
[envVar: string]: string | undefined;
|
|
298
|
-
};
|
|
299
|
-
/**
|
|
300
|
-
* JavaScript runtime to use for executing Claude Code.
|
|
301
|
-
* Auto-detected if not specified.
|
|
302
|
-
*/
|
|
303
|
-
executable?: 'bun' | 'deno' | 'node';
|
|
304
|
-
/**
|
|
305
|
-
* Additional arguments to pass to the JavaScript runtime executable.
|
|
306
|
-
*/
|
|
307
|
-
executableArgs?: string[];
|
|
308
|
-
/**
|
|
309
|
-
* Additional CLI arguments to pass to Claude Code.
|
|
310
|
-
* Keys are argument names (without --), values are argument values.
|
|
311
|
-
* Use `null` for boolean flags.
|
|
312
|
-
*/
|
|
313
|
-
extraArgs?: Record<string, string | null>;
|
|
314
|
-
/**
|
|
315
|
-
* Fallback model to use if the primary model fails or is unavailable.
|
|
316
|
-
*/
|
|
317
|
-
fallbackModel?: string;
|
|
318
|
-
/**
|
|
319
|
-
* Enable file checkpointing to track file changes during the session.
|
|
320
|
-
* When enabled, files can be rewound to their state at any user message
|
|
321
|
-
* using `Query.rewindFiles()`.
|
|
322
|
-
*
|
|
323
|
-
* File checkpointing creates backups of files before they are modified,
|
|
324
|
-
* allowing you to restore them to previous states.
|
|
325
|
-
*/
|
|
326
|
-
enableFileCheckpointing?: boolean;
|
|
327
|
-
/**
|
|
328
|
-
* When true, resumed sessions will fork to a new session ID rather than
|
|
329
|
-
* continuing the previous session. Use with `resume`.
|
|
330
|
-
*/
|
|
331
|
-
forkSession?: boolean;
|
|
332
|
-
/**
|
|
333
|
-
* Enable beta features. Currently supported:
|
|
334
|
-
* - `'context-1m-2025-08-07'` - Enable 1M token context window (Sonnet 4/4.5 only)
|
|
335
|
-
*
|
|
336
|
-
* @see https://docs.anthropic.com/en/api/beta-headers
|
|
337
|
-
*/
|
|
338
|
-
betas?: SdkBeta[];
|
|
339
|
-
/**
|
|
340
|
-
* Hook callbacks for responding to various events during execution.
|
|
341
|
-
* Hooks can modify behavior, add context, or implement custom logic.
|
|
342
|
-
*
|
|
343
|
-
* @example
|
|
344
|
-
* ```typescript
|
|
345
|
-
* hooks: {
|
|
346
|
-
* PreToolUse: [{
|
|
347
|
-
* hooks: [async (input) => ({ continue: true })]
|
|
348
|
-
* }]
|
|
349
|
-
* }
|
|
350
|
-
* ```
|
|
351
|
-
*/
|
|
352
|
-
hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
353
|
-
/**
|
|
354
|
-
* When false, disables session persistence to disk. Sessions will not be
|
|
355
|
-
* saved to ~/.claude/projects/ and cannot be resumed later. Useful for
|
|
356
|
-
* ephemeral or automated workflows where session history is not needed.
|
|
357
|
-
*
|
|
358
|
-
* @default true
|
|
359
|
-
*/
|
|
360
|
-
persistSession?: boolean;
|
|
361
|
-
/**
|
|
362
|
-
* Include partial/streaming message events in the output.
|
|
363
|
-
* When true, `SDKPartialAssistantMessage` events will be emitted during streaming.
|
|
364
|
-
*/
|
|
365
|
-
includePartialMessages?: boolean;
|
|
366
|
-
/**
|
|
367
|
-
* Maximum number of tokens the model can use for its thinking/reasoning process.
|
|
368
|
-
* Helps control cost and latency for complex tasks.
|
|
369
|
-
*/
|
|
370
|
-
maxThinkingTokens?: number;
|
|
371
|
-
/**
|
|
372
|
-
* Maximum number of conversation turns before the query stops.
|
|
373
|
-
* A turn consists of a user message and assistant response.
|
|
374
|
-
*/
|
|
375
|
-
maxTurns?: number;
|
|
376
|
-
/**
|
|
377
|
-
* Maximum budget in USD for the query. The query will stop if this
|
|
378
|
-
* budget is exceeded, returning an `error_max_budget_usd` result.
|
|
379
|
-
*/
|
|
380
|
-
maxBudgetUsd?: number;
|
|
381
|
-
/**
|
|
382
|
-
* MCP (Model Context Protocol) server configurations.
|
|
383
|
-
* Keys are server names, values are server configurations.
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```typescript
|
|
387
|
-
* mcpServers: {
|
|
388
|
-
* 'my-server': {
|
|
389
|
-
* command: 'node',
|
|
390
|
-
* args: ['./my-mcp-server.js']
|
|
391
|
-
* }
|
|
392
|
-
* }
|
|
393
|
-
* ```
|
|
394
|
-
*/
|
|
395
|
-
mcpServers?: Record<string, McpServerConfig>;
|
|
396
|
-
/**
|
|
397
|
-
* Claude model to use. Defaults to the CLI default model.
|
|
398
|
-
* Examples: 'claude-sonnet-4-5-20250929', 'claude-opus-4-20250514'
|
|
399
|
-
*/
|
|
400
|
-
model?: string;
|
|
401
|
-
/**
|
|
402
|
-
* Output format configuration for structured responses.
|
|
403
|
-
* When specified, the agent will return structured data matching the schema.
|
|
404
|
-
*
|
|
405
|
-
* @example
|
|
406
|
-
* ```typescript
|
|
407
|
-
* outputFormat: {
|
|
408
|
-
* type: 'json_schema',
|
|
409
|
-
* schema: { type: 'object', properties: { result: { type: 'string' } } }
|
|
410
|
-
* }
|
|
411
|
-
* ```
|
|
412
|
-
*/
|
|
413
|
-
outputFormat?: OutputFormat;
|
|
414
|
-
/**
|
|
415
|
-
* Path to the Claude Code executable. Uses the built-in executable if not specified.
|
|
416
|
-
*/
|
|
417
|
-
pathToClaudeCodeExecutable?: string;
|
|
418
|
-
/**
|
|
419
|
-
* Permission mode for the session.
|
|
420
|
-
* - `'default'` - Standard permission behavior, prompts for dangerous operations
|
|
421
|
-
* - `'acceptEdits'` - Auto-accept file edit operations
|
|
422
|
-
* - `'bypassPermissions'` - Bypass all permission checks (requires `allowDangerouslySkipPermissions`)
|
|
423
|
-
* - `'plan'` - Planning mode, no execution of tools
|
|
424
|
-
* - `'dontAsk'` - Don't prompt for permissions, deny if not pre-approved
|
|
425
|
-
*/
|
|
426
|
-
permissionMode?: PermissionMode;
|
|
427
|
-
/**
|
|
428
|
-
* Must be set to `true` when using `permissionMode: 'bypassPermissions'`.
|
|
429
|
-
* This is a safety measure to ensure intentional bypassing of permissions.
|
|
430
|
-
*/
|
|
431
|
-
allowDangerouslySkipPermissions?: boolean;
|
|
432
|
-
/**
|
|
433
|
-
* MCP tool name to use for permission prompts. When set, permission requests
|
|
434
|
-
* will be routed through this MCP tool instead of the default handler.
|
|
435
|
-
*/
|
|
436
|
-
permissionPromptToolName?: string;
|
|
437
|
-
/**
|
|
438
|
-
* Load plugins for this session. Plugins provide custom commands, agents,
|
|
439
|
-
* skills, and hooks that extend Claude Code's capabilities.
|
|
440
|
-
*
|
|
441
|
-
* Currently only local plugins are supported via the 'local' type.
|
|
442
|
-
*
|
|
443
|
-
* @example
|
|
444
|
-
* ```typescript
|
|
445
|
-
* plugins: [
|
|
446
|
-
* { type: 'local', path: './my-plugin' },
|
|
447
|
-
* { type: 'local', path: '/absolute/path/to/plugin' }
|
|
448
|
-
* ]
|
|
449
|
-
* ```
|
|
450
|
-
*/
|
|
451
|
-
plugins?: SdkPluginConfig[];
|
|
452
|
-
/**
|
|
453
|
-
* Session ID to resume. Loads the conversation history from the specified session.
|
|
454
|
-
*/
|
|
455
|
-
resume?: string;
|
|
456
|
-
/**
|
|
457
|
-
* When resuming, only resume messages up to and including the message with this UUID.
|
|
458
|
-
* Use with `resume`. This allows you to resume from a specific point in the conversation.
|
|
459
|
-
* The message ID should be from `SDKAssistantMessage.uuid`.
|
|
460
|
-
*/
|
|
461
|
-
resumeSessionAt?: string;
|
|
462
|
-
/**
|
|
463
|
-
* Sandbox settings for command execution isolation.
|
|
464
|
-
*
|
|
465
|
-
* When enabled, commands are executed in a sandboxed environment that restricts
|
|
466
|
-
* filesystem and network access. This provides an additional security layer.
|
|
467
|
-
*
|
|
468
|
-
* **Important:** Filesystem and network restrictions are configured via permission
|
|
469
|
-
* rules, not via these sandbox settings:
|
|
470
|
-
* - Filesystem access: Use `Read` and `Edit` permission rules
|
|
471
|
-
* - Network access: Use `WebFetch` permission rules
|
|
472
|
-
*
|
|
473
|
-
* These sandbox settings control sandbox behavior (enabled, auto-allow, etc.),
|
|
474
|
-
* while the actual access restrictions come from your permission configuration.
|
|
475
|
-
*
|
|
476
|
-
* @example Enable sandboxing with auto-allow
|
|
477
|
-
* ```typescript
|
|
478
|
-
* sandbox: {
|
|
479
|
-
* enabled: true,
|
|
480
|
-
* autoAllowBashIfSandboxed: true
|
|
481
|
-
* }
|
|
482
|
-
* ```
|
|
483
|
-
*
|
|
484
|
-
* @example Configure network options (not restrictions)
|
|
485
|
-
* ```typescript
|
|
486
|
-
* sandbox: {
|
|
487
|
-
* enabled: true,
|
|
488
|
-
* network: {
|
|
489
|
-
* allowLocalBinding: true,
|
|
490
|
-
* allowUnixSockets: ['/var/run/docker.sock']
|
|
491
|
-
* }
|
|
492
|
-
* }
|
|
493
|
-
* ```
|
|
494
|
-
*
|
|
495
|
-
* @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
|
|
496
|
-
*/
|
|
497
|
-
sandbox?: SandboxSettings;
|
|
498
|
-
/**
|
|
499
|
-
* Control which filesystem settings to load.
|
|
500
|
-
* - `'user'` - Global user settings (`~/.claude/settings.json`)
|
|
501
|
-
* - `'project'` - Project settings (`.claude/settings.json`)
|
|
502
|
-
* - `'local'` - Local settings (`.claude/settings.local.json`)
|
|
503
|
-
*
|
|
504
|
-
* When omitted or empty, no filesystem settings are loaded (SDK isolation mode).
|
|
505
|
-
* Must include `'project'` to load CLAUDE.md files.
|
|
506
|
-
*/
|
|
507
|
-
settingSources?: SettingSource[];
|
|
508
|
-
/**
|
|
509
|
-
* Callback for stderr output from the Claude Code process.
|
|
510
|
-
* Useful for debugging and logging.
|
|
511
|
-
*/
|
|
512
|
-
stderr?: (data: string) => void;
|
|
513
|
-
/**
|
|
514
|
-
* Enforce strict validation of MCP server configurations.
|
|
515
|
-
* When true, invalid configurations will cause errors instead of warnings.
|
|
516
|
-
*/
|
|
517
|
-
strictMcpConfig?: boolean;
|
|
518
|
-
/**
|
|
519
|
-
* System prompt configuration.
|
|
520
|
-
* - `string` - Use a custom system prompt
|
|
521
|
-
* - `{ type: 'preset', preset: 'claude_code' }` - Use Claude Code's default system prompt
|
|
522
|
-
* - `{ type: 'preset', preset: 'claude_code', append: '...' }` - Use default prompt with appended instructions
|
|
523
|
-
*
|
|
524
|
-
* @example Custom prompt
|
|
525
|
-
* ```typescript
|
|
526
|
-
* systemPrompt: 'You are a helpful coding assistant.'
|
|
527
|
-
* ```
|
|
528
|
-
*
|
|
529
|
-
* @example Default with additions
|
|
530
|
-
* ```typescript
|
|
531
|
-
* systemPrompt: {
|
|
532
|
-
* type: 'preset',
|
|
533
|
-
* preset: 'claude_code',
|
|
534
|
-
* append: 'Always explain your reasoning.'
|
|
535
|
-
* }
|
|
536
|
-
* ```
|
|
537
|
-
*/
|
|
538
|
-
systemPrompt?: string | {
|
|
539
|
-
type: 'preset';
|
|
540
|
-
preset: 'claude_code';
|
|
541
|
-
append?: string;
|
|
542
|
-
};
|
|
543
|
-
/**
|
|
544
|
-
* Custom function to spawn the Claude Code process.
|
|
545
|
-
* Use this to run Claude Code in VMs, containers, or remote environments.
|
|
546
|
-
*
|
|
547
|
-
* When provided, this function is called instead of the default local spawn.
|
|
548
|
-
* The default behavior checks if the executable exists before spawning.
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```typescript
|
|
552
|
-
* spawnClaudeCodeProcess: (options) => {
|
|
553
|
-
* // Custom spawn logic for VM execution
|
|
554
|
-
* // options contains: command, args, cwd, env, signal
|
|
555
|
-
* return myVMProcess; // Must satisfy SpawnedProcess interface
|
|
556
|
-
* }
|
|
557
|
-
* ```
|
|
558
|
-
*/
|
|
559
|
-
spawnClaudeCodeProcess?: (options: SpawnOptions) => SpawnedProcess;
|
|
560
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Readable, Writable } from 'stream';
|
|
2
|
-
/**
|
|
3
|
-
* Represents a spawned process with stdin/stdout streams and lifecycle management.
|
|
4
|
-
* Implementers provide this interface to abstract the process spawning mechanism.
|
|
5
|
-
* ChildProcess already satisfies this interface.
|
|
6
|
-
*/
|
|
7
|
-
export interface SpawnedProcess {
|
|
8
|
-
/** Writable stream for sending data to the process stdin */
|
|
9
|
-
stdin: Writable;
|
|
10
|
-
/** Readable stream for receiving data from the process stdout */
|
|
11
|
-
stdout: Readable;
|
|
12
|
-
/** Whether the process has been killed */
|
|
13
|
-
readonly killed: boolean;
|
|
14
|
-
/** Exit code if the process has exited, null otherwise */
|
|
15
|
-
readonly exitCode: number | null;
|
|
16
|
-
/**
|
|
17
|
-
* Kill the process with the given signal
|
|
18
|
-
* @param signal - The signal to send (e.g., 'SIGTERM', 'SIGKILL')
|
|
19
|
-
*/
|
|
20
|
-
kill(signal: NodeJS.Signals): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Register a callback for when the process exits
|
|
23
|
-
* @param event - Must be 'exit'
|
|
24
|
-
* @param listener - Callback receiving exit code and signal
|
|
25
|
-
*/
|
|
26
|
-
on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
|
|
27
|
-
/**
|
|
28
|
-
* Register a callback for process errors
|
|
29
|
-
* @param event - Must be 'error'
|
|
30
|
-
* @param listener - Callback receiving the error
|
|
31
|
-
*/
|
|
32
|
-
on(event: 'error', listener: (error: Error) => void): void;
|
|
33
|
-
/**
|
|
34
|
-
* Register a one-time callback for when the process exits
|
|
35
|
-
*/
|
|
36
|
-
once(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
|
|
37
|
-
once(event: 'error', listener: (error: Error) => void): void;
|
|
38
|
-
/**
|
|
39
|
-
* Remove an event listener
|
|
40
|
-
*/
|
|
41
|
-
off(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;
|
|
42
|
-
off(event: 'error', listener: (error: Error) => void): void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Options passed to the spawn function.
|
|
46
|
-
*/
|
|
47
|
-
export interface SpawnOptions {
|
|
48
|
-
/** Command to execute */
|
|
49
|
-
command: string;
|
|
50
|
-
/** Arguments to pass to the command */
|
|
51
|
-
args: string[];
|
|
52
|
-
/** Working directory */
|
|
53
|
-
cwd?: string;
|
|
54
|
-
/** Environment variables */
|
|
55
|
-
env: {
|
|
56
|
-
[envVar: string]: string | undefined;
|
|
57
|
-
};
|
|
58
|
-
/** Abort signal for cancellation */
|
|
59
|
-
signal: AbortSignal;
|
|
60
|
-
}
|
package/transport/transport.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { StdoutMessage } from '../entrypoints/sdk/controlTypes.js';
|
|
2
|
-
/**
|
|
3
|
-
* Transport interface for Claude Code SDK communication
|
|
4
|
-
* Abstracts the communication layer to support both process and WebSocket transports
|
|
5
|
-
*/
|
|
6
|
-
export interface Transport {
|
|
7
|
-
/**
|
|
8
|
-
* Write data to the transport
|
|
9
|
-
* May be async for network-based transports
|
|
10
|
-
*/
|
|
11
|
-
write(data: string): void | Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
* Close the transport connection and clean up resources
|
|
14
|
-
* This also closes stdin if still open (eliminating need for endInput)
|
|
15
|
-
*/
|
|
16
|
-
close(): void;
|
|
17
|
-
/**
|
|
18
|
-
* Check if transport is ready for communication
|
|
19
|
-
*/
|
|
20
|
-
isReady(): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Read and parse messages from the transport
|
|
23
|
-
* Each transport handles its own protocol and error checking
|
|
24
|
-
*/
|
|
25
|
-
readMessages(): AsyncGenerator<StdoutMessage, void, unknown>;
|
|
26
|
-
/**
|
|
27
|
-
* End the input stream
|
|
28
|
-
*/
|
|
29
|
-
endInput(): void;
|
|
30
|
-
}
|