@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/sdk.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.
3
3
 
4
- // Version: 0.2.0
4
+ // Version: 0.2.2
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -7178,7 +7178,8 @@ function getInitialState() {
7178
7178
  teleportedSessionInfo: null,
7179
7179
  invokedSkills: new Map,
7180
7180
  slowOperations: [],
7181
- sdkBetas: undefined
7181
+ sdkBetas: undefined,
7182
+ mainThreadAgentType: undefined
7182
7183
  };
7183
7184
  }
7184
7185
  var STATE = getInitialState();
@@ -8606,22 +8607,22 @@ class SessionImpl {
8606
8607
  maxBudgetUsd: undefined,
8607
8608
  model: options.model,
8608
8609
  fallbackModel: undefined,
8609
- permissionMode: "default",
8610
+ permissionMode: options.permissionMode ?? "default",
8610
8611
  allowDangerouslySkipPermissions: false,
8611
8612
  continueConversation: false,
8612
8613
  resume: options.resume,
8613
8614
  settingSources: [],
8614
- allowedTools: [],
8615
- disallowedTools: [],
8615
+ allowedTools: options.allowedTools ?? [],
8616
+ disallowedTools: options.disallowedTools ?? [],
8616
8617
  mcpServers: {},
8617
8618
  strictMcpConfig: false,
8618
- canUseTool: false,
8619
- hooks: false,
8619
+ canUseTool: !!options.canUseTool,
8620
+ hooks: !!options.hooks,
8620
8621
  includePartialMessages: false,
8621
8622
  forkSession: false,
8622
8623
  resumeSessionAt: undefined
8623
8624
  });
8624
- this.query = new Query(transport, false, undefined, undefined, this.abortController, new Map);
8625
+ this.query = new Query(transport, false, options.canUseTool, options.hooks, this.abortController, new Map);
8625
8626
  this.query.streamInput(this.inputStream);
8626
8627
  }
8627
8628
  async send(message) {
@@ -21329,7 +21330,7 @@ function query({
21329
21330
  const dirname2 = join5(filename, "..");
21330
21331
  pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
21331
21332
  }
21332
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.2.0";
21333
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.2.2";
21333
21334
  const {
21334
21335
  abortController = createAbortController(),
21335
21336
  additionalDirectories = [],
@@ -1,56 +0,0 @@
1
- /**
2
- * Main entrypoint for Claude Code Agent SDK types.
3
- *
4
- * This file re-exports the public SDK API from:
5
- * - sdk/coreTypes.ts - Common serializable types (messages, configs)
6
- * - sdk/runtimeTypes.ts - Non-serializable types (callbacks, interfaces)
7
- *
8
- * SDK builders who need control protocol types should import from
9
- * sdk/controlTypes.ts directly.
10
- */
11
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
12
- export * from './sdk/coreTypes.js';
13
- export * from './sdk/runtimeTypes.js';
14
- import type { Query, Options, SDKSessionOptions, SDKSession, SdkMcpToolDefinition, McpSdkServerConfigWithInstance, AnyZodRawShape, InferShape } from './sdk/runtimeTypes.js';
15
- import type { SDKUserMessage, SDKResultMessage } from './sdk/coreTypes.js';
16
- export declare function tool<Schema extends AnyZodRawShape>(_name: string, _description: string, _inputSchema: Schema, _handler: (args: InferShape<Schema>, extra: unknown) => Promise<CallToolResult>): SdkMcpToolDefinition<Schema>;
17
- type CreateSdkMcpServerOptions = {
18
- name: string;
19
- version?: string;
20
- tools?: Array<SdkMcpToolDefinition<any>>;
21
- };
22
- /**
23
- * Creates an MCP server instance that can be used with the SDK transport.
24
- * This allows SDK users to define custom tools that run in the same process.
25
- *
26
- * If your SDK MCP calls will run longer than 60s, override CLAUDE_CODE_STREAM_CLOSE_TIMEOUT
27
- */
28
- export declare function createSdkMcpServer(_options: CreateSdkMcpServerOptions): McpSdkServerConfigWithInstance;
29
- export declare class AbortError extends Error {
30
- }
31
- export declare function query(_params: {
32
- prompt: string | AsyncIterable<SDKUserMessage>;
33
- options?: Options;
34
- }): Query;
35
- /**
36
- * V2 API - UNSTABLE
37
- * Create a persistent session for multi-turn conversations.
38
- */
39
- export declare function unstable_v2_createSession(_options: SDKSessionOptions): SDKSession;
40
- /**
41
- * V2 API - UNSTABLE
42
- * Resume an existing session by ID.
43
- */
44
- export declare function unstable_v2_resumeSession(_sessionId: string, _options: SDKSessionOptions): SDKSession;
45
- /**
46
- * V2 API - UNSTABLE
47
- * One-shot convenience function for single prompts.
48
- *
49
- * @example
50
- * ```typescript
51
- * const result = await unstable_v2_prompt("What files are here?", {
52
- * model: 'claude-sonnet-4-5-20250929'
53
- * })
54
- * ```
55
- */
56
- export declare function unstable_v2_prompt(_message: string, _options: SDKSessionOptions): Promise<SDKResultMessage>;
@@ -1,44 +0,0 @@
1
- /**
2
- * Sandbox types for the Claude Code Agent SDK
3
- *
4
- * This file is the single source of truth for sandbox configuration types.
5
- * Both the SDK and the settings validation import from here.
6
- */
7
- import { z } from 'zod/v4';
8
- /**
9
- * Network configuration schema for sandbox.
10
- */
11
- export declare const SandboxNetworkConfigSchema: z.ZodOptional<z.ZodObject<{
12
- allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
- allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
- allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
15
- allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
16
- httpProxyPort: z.ZodOptional<z.ZodNumber>;
17
- socksProxyPort: z.ZodOptional<z.ZodNumber>;
18
- }, z.core.$strip>>;
19
- /**
20
- * Sandbox settings schema.
21
- */
22
- export declare const SandboxSettingsSchema: z.ZodObject<{
23
- enabled: z.ZodOptional<z.ZodBoolean>;
24
- autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
25
- allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
26
- network: z.ZodOptional<z.ZodObject<{
27
- allowedDomains: z.ZodOptional<z.ZodArray<z.ZodString>>;
28
- allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
- allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
30
- allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
31
- httpProxyPort: z.ZodOptional<z.ZodNumber>;
32
- socksProxyPort: z.ZodOptional<z.ZodNumber>;
33
- }, z.core.$strip>>;
34
- ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
35
- enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
36
- excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString>>;
37
- ripgrep: z.ZodOptional<z.ZodObject<{
38
- command: z.ZodString;
39
- args: z.ZodOptional<z.ZodArray<z.ZodString>>;
40
- }, z.core.$strip>>;
41
- }, z.core.$loose>;
42
- export type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
43
- export type SandboxNetworkConfig = NonNullable<z.infer<typeof SandboxNetworkConfigSchema>>;
44
- export type SandboxIgnoreViolations = NonNullable<SandboxSettings['ignoreViolations']>;
@@ -1,2 +0,0 @@
1
- export * from './coreTypes.js';
2
- export * from './controlTypes.generated.js';
@@ -1,135 +0,0 @@
1
- /**
2
- * AUTO-GENERATED - DO NOT EDIT
3
- *
4
- * This file is auto-generated from Zod schemas in controlSchemas.ts.
5
- * To modify these types, edit the Zod schemas and run:
6
- *
7
- * bun scripts/generate-sdk-types.ts
8
- */
9
- import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
10
- import type * as coreTypes from './coreTypes.js';
11
- export type ControlErrorResponse = {
12
- subtype: 'error';
13
- request_id: string;
14
- error: string;
15
- pending_permission_requests?: SDKControlRequest[];
16
- };
17
- export type ControlResponse = {
18
- subtype: 'success';
19
- request_id: string;
20
- response?: Record<string, unknown>;
21
- };
22
- /**
23
- * Cancels a currently open control request.
24
- */
25
- export type SDKControlCancelRequest = {
26
- type: 'control_cancel_request';
27
- request_id: string;
28
- };
29
- export type SDKControlInitializeRequest = {
30
- subtype: 'initialize';
31
- hooks?: Partial<Record<coreTypes.HookEvent, SDKHookCallbackMatcher[]>>;
32
- sdkMcpServers?: string[];
33
- jsonSchema?: Record<string, unknown>;
34
- systemPrompt?: string;
35
- appendSystemPrompt?: string;
36
- agents?: Record<string, coreTypes.AgentDefinition>;
37
- };
38
- export type SDKControlInitializeResponse = {
39
- commands: coreTypes.SlashCommand[];
40
- output_style: string;
41
- available_output_styles: string[];
42
- models: coreTypes.ModelInfo[];
43
- /** Information about the logged in user's account. */
44
- account: coreTypes.AccountInfo;
45
- };
46
- export type SDKControlInterruptRequest = {
47
- subtype: 'interrupt';
48
- };
49
- export type SDKControlMcpMessageRequest = {
50
- subtype: 'mcp_message';
51
- server_name: string;
52
- message: JSONRPCMessage;
53
- };
54
- export type SDKControlMcpSetServersRequest = {
55
- subtype: 'mcp_set_servers';
56
- servers: Record<string, coreTypes.McpServerConfigForProcessTransport>;
57
- };
58
- export type SDKControlMcpSetServersResponse = {
59
- added: string[];
60
- removed: string[];
61
- errors: Record<string, string>;
62
- };
63
- export type SDKControlMcpStatusRequest = {
64
- subtype: 'mcp_status';
65
- };
66
- export type SDKControlPermissionRequest = {
67
- subtype: 'can_use_tool';
68
- tool_name: string;
69
- input: Record<string, unknown>;
70
- permission_suggestions?: coreTypes.PermissionUpdate[];
71
- blocked_path?: string;
72
- decision_reason?: string;
73
- tool_use_id: string;
74
- agent_id?: string;
75
- };
76
- export type SDKControlRequestInner = SDKControlInterruptRequest | SDKControlPermissionRequest | SDKControlInitializeRequest | SDKControlSetPermissionModeRequest | SDKControlSetModelRequest | SDKControlSetMaxThinkingTokensRequest | SDKControlMcpStatusRequest | SDKHookCallbackRequest | SDKControlMcpMessageRequest | SDKControlRewindFilesRequest | SDKControlMcpSetServersRequest;
77
- export type SDKControlRequest = {
78
- type: 'control_request';
79
- request_id: string;
80
- request: SDKControlRequestInner;
81
- };
82
- export type SDKControlResponse = {
83
- type: 'control_response';
84
- response: ControlResponse | ControlErrorResponse;
85
- };
86
- export type SDKControlRewindFilesRequest = {
87
- subtype: 'rewind_files';
88
- user_message_id: string;
89
- dry_run?: boolean;
90
- };
91
- /**
92
- * Result of a rewindFiles operation.
93
- */
94
- export type SDKControlRewindFilesResponse = {
95
- canRewind: boolean;
96
- error?: string;
97
- filesChanged?: string[];
98
- insertions?: number;
99
- deletions?: number;
100
- };
101
- export type SDKControlSetMaxThinkingTokensRequest = {
102
- subtype: 'set_max_thinking_tokens';
103
- max_thinking_tokens: number | null;
104
- };
105
- export type SDKControlSetModelRequest = {
106
- subtype: 'set_model';
107
- model?: string;
108
- };
109
- export type SDKControlSetPermissionModeRequest = {
110
- subtype: 'set_permission_mode';
111
- /** Permission mode for controlling how tool executions are handled. 'default' - Standard behavior, prompts for dangerous operations. 'acceptEdits' - Auto-accept file edit operations. 'bypassPermissions' - Bypass all permission checks (requires allowDangerouslySkipPermissions). 'plan' - Planning mode, no actual tool execution. 'delegate' - Delegate mode, restricts team leader to only Teammate and Task tools. 'dontAsk' - Don't prompt for permissions, deny if not pre-approved. */
112
- mode: coreTypes.PermissionMode;
113
- };
114
- /**
115
- * Configuration for matching and routing hook callbacks.
116
- */
117
- export type SDKHookCallbackMatcher = {
118
- matcher?: string;
119
- hookCallbackIds: string[];
120
- timeout?: number;
121
- };
122
- export type SDKHookCallbackRequest = {
123
- subtype: 'hook_callback';
124
- callback_id: string;
125
- input: coreTypes.HookInput;
126
- tool_use_id?: string;
127
- };
128
- /**
129
- * Keep-alive message to maintain WebSocket connection.
130
- */
131
- export type SDKKeepAliveMessage = {
132
- type: 'keep_alive';
133
- };
134
- export type StdinMessage = coreTypes.SDKUserMessage | SDKControlRequest | SDKControlResponse | SDKKeepAliveMessage;
135
- export type StdoutMessage = coreTypes.SDKMessage | SDKControlResponse | SDKControlRequest | SDKControlCancelRequest | SDKKeepAliveMessage;
@@ -1,5 +0,0 @@
1
- export * from './coreTypes.generated.js';
2
- export type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations, } from '../sandboxTypes.js';
3
- export type { NonNullableUsage } from './sdkUtilityTypes.js';
4
- export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
5
- export declare const EXIT_REASONS: readonly ["clear", "logout", "prompt_input_exit", "other", "bypass_permissions_disabled"];