@anthropic-ai/claude-agent-sdk 0.1.55 → 0.1.57
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 +1257 -1241
- package/package.json +1 -1
- package/sandboxTypes.d.ts +144 -0
- package/sdk-tools.d.ts +1 -4
- package/sdk.d.ts +61 -3
- package/sdk.mjs +53 -23
package/package.json
CHANGED
|
@@ -0,0 +1,144 @@
|
|
|
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';
|
|
8
|
+
/**
|
|
9
|
+
* Network configuration schema for sandbox.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SandboxNetworkConfigSchema: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
13
|
+
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
httpProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
socksProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
allowUnixSockets?: string[];
|
|
19
|
+
allowAllUnixSockets?: boolean;
|
|
20
|
+
allowLocalBinding?: boolean;
|
|
21
|
+
httpProxyPort?: number;
|
|
22
|
+
socksProxyPort?: number;
|
|
23
|
+
}, {
|
|
24
|
+
allowUnixSockets?: string[];
|
|
25
|
+
allowAllUnixSockets?: boolean;
|
|
26
|
+
allowLocalBinding?: boolean;
|
|
27
|
+
httpProxyPort?: number;
|
|
28
|
+
socksProxyPort?: number;
|
|
29
|
+
}>>;
|
|
30
|
+
/**
|
|
31
|
+
* Sandbox settings schema.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SandboxSettingsSchema: z.ZodObject<{
|
|
34
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
|
|
36
|
+
allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
+
network: z.ZodOptional<z.ZodObject<{
|
|
38
|
+
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
39
|
+
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
httpProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
socksProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
allowUnixSockets?: string[];
|
|
45
|
+
allowAllUnixSockets?: boolean;
|
|
46
|
+
allowLocalBinding?: boolean;
|
|
47
|
+
httpProxyPort?: number;
|
|
48
|
+
socksProxyPort?: number;
|
|
49
|
+
}, {
|
|
50
|
+
allowUnixSockets?: string[];
|
|
51
|
+
allowAllUnixSockets?: boolean;
|
|
52
|
+
allowLocalBinding?: boolean;
|
|
53
|
+
httpProxyPort?: number;
|
|
54
|
+
socksProxyPort?: number;
|
|
55
|
+
}>>;
|
|
56
|
+
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
57
|
+
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
+
excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
59
|
+
ripgrep: z.ZodOptional<z.ZodObject<{
|
|
60
|
+
command: z.ZodString;
|
|
61
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
command?: string;
|
|
64
|
+
args?: string[];
|
|
65
|
+
}, {
|
|
66
|
+
command?: string;
|
|
67
|
+
args?: string[];
|
|
68
|
+
}>>;
|
|
69
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
70
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
+
network: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
75
|
+
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
|
|
76
|
+
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
httpProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
socksProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
}, "strip", z.ZodTypeAny, {
|
|
80
|
+
allowUnixSockets?: string[];
|
|
81
|
+
allowAllUnixSockets?: boolean;
|
|
82
|
+
allowLocalBinding?: boolean;
|
|
83
|
+
httpProxyPort?: number;
|
|
84
|
+
socksProxyPort?: number;
|
|
85
|
+
}, {
|
|
86
|
+
allowUnixSockets?: string[];
|
|
87
|
+
allowAllUnixSockets?: boolean;
|
|
88
|
+
allowLocalBinding?: boolean;
|
|
89
|
+
httpProxyPort?: number;
|
|
90
|
+
socksProxyPort?: number;
|
|
91
|
+
}>>;
|
|
92
|
+
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
93
|
+
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
95
|
+
ripgrep: z.ZodOptional<z.ZodObject<{
|
|
96
|
+
command: z.ZodString;
|
|
97
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
98
|
+
}, "strip", z.ZodTypeAny, {
|
|
99
|
+
command?: string;
|
|
100
|
+
args?: string[];
|
|
101
|
+
}, {
|
|
102
|
+
command?: string;
|
|
103
|
+
args?: string[];
|
|
104
|
+
}>>;
|
|
105
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
106
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
|
|
109
|
+
network: z.ZodOptional<z.ZodObject<{
|
|
110
|
+
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
111
|
+
allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
|
|
112
|
+
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
httpProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
114
|
+
socksProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
115
|
+
}, "strip", z.ZodTypeAny, {
|
|
116
|
+
allowUnixSockets?: string[];
|
|
117
|
+
allowAllUnixSockets?: boolean;
|
|
118
|
+
allowLocalBinding?: boolean;
|
|
119
|
+
httpProxyPort?: number;
|
|
120
|
+
socksProxyPort?: number;
|
|
121
|
+
}, {
|
|
122
|
+
allowUnixSockets?: string[];
|
|
123
|
+
allowAllUnixSockets?: boolean;
|
|
124
|
+
allowLocalBinding?: boolean;
|
|
125
|
+
httpProxyPort?: number;
|
|
126
|
+
socksProxyPort?: number;
|
|
127
|
+
}>>;
|
|
128
|
+
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
129
|
+
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
|
|
130
|
+
excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
131
|
+
ripgrep: z.ZodOptional<z.ZodObject<{
|
|
132
|
+
command: z.ZodString;
|
|
133
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
134
|
+
}, "strip", z.ZodTypeAny, {
|
|
135
|
+
command?: string;
|
|
136
|
+
args?: string[];
|
|
137
|
+
}, {
|
|
138
|
+
command?: string;
|
|
139
|
+
args?: string[];
|
|
140
|
+
}>>;
|
|
141
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
142
|
+
export type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
|
|
143
|
+
export type SandboxNetworkConfig = NonNullable<z.infer<typeof SandboxNetworkConfigSchema>>;
|
|
144
|
+
export type SandboxIgnoreViolations = NonNullable<SandboxSettings['ignoreViolations']>;
|
package/sdk-tools.d.ts
CHANGED
|
@@ -94,10 +94,7 @@ export interface BashOutputInput {
|
|
|
94
94
|
filter?: string;
|
|
95
95
|
}
|
|
96
96
|
export interface ExitPlanModeInput {
|
|
97
|
-
|
|
98
|
-
* The plan you came up with, that you want to run by the user for approval. Supports markdown. The plan should be pretty concise.
|
|
99
|
-
*/
|
|
100
|
-
plan: string;
|
|
97
|
+
[k: string]: unknown;
|
|
101
98
|
}
|
|
102
99
|
export interface FileEditInput {
|
|
103
100
|
/**
|
package/sdk.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { UUID } from 'crypto';
|
|
|
4
4
|
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
6
|
import { type z, type ZodRawShape, type ZodObject } from 'zod';
|
|
7
|
+
import type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations } from './sandboxTypes.js';
|
|
8
|
+
export type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations };
|
|
7
9
|
export type NonNullableUsage = {
|
|
8
10
|
[K in keyof Usage]: NonNullable<Usage[K]>;
|
|
9
11
|
};
|
|
@@ -161,7 +163,7 @@ export type CanUseTool = (toolName: string, input: Record<string, unknown>, opti
|
|
|
161
163
|
/** If running within the context of a sub-agent, the sub-agent's ID. */
|
|
162
164
|
agentID?: string;
|
|
163
165
|
}) => Promise<PermissionResult>;
|
|
164
|
-
export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
|
|
166
|
+
export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "PostToolUseFailure", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStart", "SubagentStop", "PreCompact", "PermissionRequest"];
|
|
165
167
|
export type HookEvent = (typeof HOOK_EVENTS)[number];
|
|
166
168
|
export type HookCallback = (input: HookInput, toolUseID: string | undefined, options: {
|
|
167
169
|
signal: AbortSignal;
|
|
@@ -197,6 +199,14 @@ export type PostToolUseHookInput = BaseHookInput & {
|
|
|
197
199
|
tool_response: unknown;
|
|
198
200
|
tool_use_id: string;
|
|
199
201
|
};
|
|
202
|
+
export type PostToolUseFailureHookInput = BaseHookInput & {
|
|
203
|
+
hook_event_name: 'PostToolUseFailure';
|
|
204
|
+
tool_name: string;
|
|
205
|
+
tool_input: unknown;
|
|
206
|
+
tool_use_id: string;
|
|
207
|
+
error: string;
|
|
208
|
+
is_interrupt?: boolean;
|
|
209
|
+
};
|
|
200
210
|
export type NotificationHookInput = BaseHookInput & {
|
|
201
211
|
hook_event_name: 'Notification';
|
|
202
212
|
message: string;
|
|
@@ -237,7 +247,7 @@ export type SessionEndHookInput = BaseHookInput & {
|
|
|
237
247
|
hook_event_name: 'SessionEnd';
|
|
238
248
|
reason: ExitReason;
|
|
239
249
|
};
|
|
240
|
-
export type HookInput = PreToolUseHookInput | PostToolUseHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PermissionRequestHookInput;
|
|
250
|
+
export type HookInput = PreToolUseHookInput | PostToolUseHookInput | PostToolUseFailureHookInput | NotificationHookInput | UserPromptSubmitHookInput | SessionStartHookInput | SessionEndHookInput | StopHookInput | SubagentStartHookInput | SubagentStopHookInput | PreCompactHookInput | PermissionRequestHookInput;
|
|
241
251
|
export type AsyncHookJSONOutput = {
|
|
242
252
|
async: true;
|
|
243
253
|
asyncTimeout?: number;
|
|
@@ -267,6 +277,9 @@ export type SyncHookJSONOutput = {
|
|
|
267
277
|
hookEventName: 'PostToolUse';
|
|
268
278
|
additionalContext?: string;
|
|
269
279
|
updatedMCPToolOutput?: unknown;
|
|
280
|
+
} | {
|
|
281
|
+
hookEventName: 'PostToolUseFailure';
|
|
282
|
+
additionalContext?: string;
|
|
270
283
|
} | {
|
|
271
284
|
hookEventName: 'PermissionRequest';
|
|
272
285
|
decision: {
|
|
@@ -564,6 +577,16 @@ export type Options = {
|
|
|
564
577
|
continue?: boolean;
|
|
565
578
|
cwd?: string;
|
|
566
579
|
disallowedTools?: string[];
|
|
580
|
+
/**
|
|
581
|
+
* Specify the base set of available built-in tools.
|
|
582
|
+
* - `string[]` - Array of specific tool names (e.g., `['Bash', 'Read', 'Edit']`)
|
|
583
|
+
* - `[]` (empty array) - Disable all built-in tools
|
|
584
|
+
* - `{ type: 'preset'; preset: 'claude_code' }` - Use all default Claude Code tools
|
|
585
|
+
*/
|
|
586
|
+
tools?: string[] | {
|
|
587
|
+
type: 'preset';
|
|
588
|
+
preset: 'claude_code';
|
|
589
|
+
};
|
|
567
590
|
env?: {
|
|
568
591
|
[envVar: string]: string | undefined;
|
|
569
592
|
};
|
|
@@ -610,6 +633,42 @@ export type Options = {
|
|
|
610
633
|
* The message ID is expected to be from SDKAssistantMessage.uuid.
|
|
611
634
|
*/
|
|
612
635
|
resumeSessionAt?: string;
|
|
636
|
+
/**
|
|
637
|
+
* Sandbox settings for command execution isolation.
|
|
638
|
+
*
|
|
639
|
+
* When enabled, commands are executed in a sandboxed environment that restricts
|
|
640
|
+
* filesystem and network access. This provides an additional security layer.
|
|
641
|
+
*
|
|
642
|
+
* **Important:** Filesystem and network restrictions are configured via permission
|
|
643
|
+
* rules, not via these sandbox settings:
|
|
644
|
+
* - Filesystem access: Use `Read` and `Edit` permission rules
|
|
645
|
+
* - Network access: Use `WebFetch` permission rules
|
|
646
|
+
*
|
|
647
|
+
* These sandbox settings control sandbox behavior (enabled, auto-allow, etc.),
|
|
648
|
+
* while the actual access restrictions come from your permission configuration.
|
|
649
|
+
*
|
|
650
|
+
* @example Enable sandboxing with auto-allow
|
|
651
|
+
* ```typescript
|
|
652
|
+
* sandbox: {
|
|
653
|
+
* enabled: true,
|
|
654
|
+
* autoAllowBashIfSandboxed: true
|
|
655
|
+
* }
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @example Configure network options (not restrictions)
|
|
659
|
+
* ```typescript
|
|
660
|
+
* sandbox: {
|
|
661
|
+
* enabled: true,
|
|
662
|
+
* network: {
|
|
663
|
+
* allowLocalBinding: true,
|
|
664
|
+
* allowUnixSockets: ['/var/run/docker.sock']
|
|
665
|
+
* }
|
|
666
|
+
* }
|
|
667
|
+
* ```
|
|
668
|
+
*
|
|
669
|
+
* @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
|
|
670
|
+
*/
|
|
671
|
+
sandbox?: SandboxSettings;
|
|
613
672
|
settingSources?: SettingSource[];
|
|
614
673
|
stderr?: (data: string) => void;
|
|
615
674
|
strictMcpConfig?: boolean;
|
|
@@ -645,4 +704,3 @@ export declare function unstable_v2_resumeSession(_sessionId: string, _options:
|
|
|
645
704
|
* ```
|
|
646
705
|
*/
|
|
647
706
|
export declare function unstable_v2_prompt(_message: string, _options: SDKSessionOptions): Promise<SDKResultMessage>;
|
|
648
|
-
export {};
|
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://docs.claude.com/en/docs/claude-code/legal-and-compliance.
|
|
3
3
|
|
|
4
|
-
// Version: 0.1.
|
|
4
|
+
// Version: 0.1.57
|
|
5
5
|
|
|
6
6
|
// Want to see the unminified source? We're hiring!
|
|
7
7
|
// https://job-boards.greenhouse.io/anthropic/jobs/4816199008
|
|
@@ -6381,6 +6381,7 @@ function getFsImplementation() {
|
|
|
6381
6381
|
var HOOK_EVENTS = [
|
|
6382
6382
|
"PreToolUse",
|
|
6383
6383
|
"PostToolUse",
|
|
6384
|
+
"PostToolUseFailure",
|
|
6384
6385
|
"Notification",
|
|
6385
6386
|
"UserPromptSubmit",
|
|
6386
6387
|
"SessionStart",
|
|
@@ -6457,6 +6458,22 @@ function logForSdkDebugging(message) {
|
|
|
6457
6458
|
appendFileSync2(path, output);
|
|
6458
6459
|
}
|
|
6459
6460
|
|
|
6461
|
+
// ../src/transport/sandboxUtils.ts
|
|
6462
|
+
function mergeSandboxIntoExtraArgs(extraArgs, sandbox) {
|
|
6463
|
+
const effectiveExtraArgs = { ...extraArgs };
|
|
6464
|
+
if (sandbox) {
|
|
6465
|
+
let settingsObj = { sandbox };
|
|
6466
|
+
if (effectiveExtraArgs.settings) {
|
|
6467
|
+
try {
|
|
6468
|
+
const existingSettings = JSON.parse(effectiveExtraArgs.settings);
|
|
6469
|
+
settingsObj = { ...existingSettings, sandbox };
|
|
6470
|
+
} catch {}
|
|
6471
|
+
}
|
|
6472
|
+
effectiveExtraArgs.settings = JSON.stringify(settingsObj);
|
|
6473
|
+
}
|
|
6474
|
+
return effectiveExtraArgs;
|
|
6475
|
+
}
|
|
6476
|
+
|
|
6460
6477
|
// ../src/transport/ProcessTransport.ts
|
|
6461
6478
|
class ProcessTransport {
|
|
6462
6479
|
options;
|
|
@@ -6478,7 +6495,6 @@ class ProcessTransport {
|
|
|
6478
6495
|
try {
|
|
6479
6496
|
const {
|
|
6480
6497
|
additionalDirectories = [],
|
|
6481
|
-
agents,
|
|
6482
6498
|
cwd,
|
|
6483
6499
|
executable = isRunningWithBun() ? "bun" : "node",
|
|
6484
6500
|
executableArgs = [],
|
|
@@ -6486,8 +6502,6 @@ class ProcessTransport {
|
|
|
6486
6502
|
pathToClaudeCodeExecutable,
|
|
6487
6503
|
env = { ...process.env },
|
|
6488
6504
|
stderr,
|
|
6489
|
-
customSystemPrompt,
|
|
6490
|
-
appendSystemPrompt,
|
|
6491
6505
|
maxThinkingTokens,
|
|
6492
6506
|
maxTurns,
|
|
6493
6507
|
maxBudgetUsd,
|
|
@@ -6506,7 +6520,8 @@ class ProcessTransport {
|
|
|
6506
6520
|
strictMcpConfig,
|
|
6507
6521
|
canUseTool,
|
|
6508
6522
|
includePartialMessages,
|
|
6509
|
-
plugins
|
|
6523
|
+
plugins,
|
|
6524
|
+
sandbox
|
|
6510
6525
|
} = this.options;
|
|
6511
6526
|
const args = [
|
|
6512
6527
|
"--output-format",
|
|
@@ -6515,10 +6530,6 @@ class ProcessTransport {
|
|
|
6515
6530
|
"--input-format",
|
|
6516
6531
|
"stream-json"
|
|
6517
6532
|
];
|
|
6518
|
-
if (typeof customSystemPrompt === "string")
|
|
6519
|
-
args.push("--system-prompt", customSystemPrompt);
|
|
6520
|
-
if (appendSystemPrompt)
|
|
6521
|
-
args.push("--append-system-prompt", appendSystemPrompt);
|
|
6522
6533
|
if (maxThinkingTokens !== undefined) {
|
|
6523
6534
|
args.push("--max-thinking-tokens", maxThinkingTokens.toString());
|
|
6524
6535
|
}
|
|
@@ -6553,12 +6564,21 @@ class ProcessTransport {
|
|
|
6553
6564
|
if (disallowedTools.length > 0) {
|
|
6554
6565
|
args.push("--disallowedTools", disallowedTools.join(","));
|
|
6555
6566
|
}
|
|
6567
|
+
const { tools } = this.options;
|
|
6568
|
+
if (tools !== undefined) {
|
|
6569
|
+
if (Array.isArray(tools)) {
|
|
6570
|
+
if (tools.length === 0) {
|
|
6571
|
+
args.push("--tools", "");
|
|
6572
|
+
} else {
|
|
6573
|
+
args.push("--tools", tools.join(","));
|
|
6574
|
+
}
|
|
6575
|
+
} else {
|
|
6576
|
+
args.push("--tools", "default");
|
|
6577
|
+
}
|
|
6578
|
+
}
|
|
6556
6579
|
if (mcpServers && Object.keys(mcpServers).length > 0) {
|
|
6557
6580
|
args.push("--mcp-config", JSON.stringify({ mcpServers }));
|
|
6558
6581
|
}
|
|
6559
|
-
if (agents && Object.keys(agents).length > 0) {
|
|
6560
|
-
args.push("--agents", JSON.stringify(agents));
|
|
6561
|
-
}
|
|
6562
6582
|
if (settingSources) {
|
|
6563
6583
|
args.push("--setting-sources", settingSources.join(","));
|
|
6564
6584
|
}
|
|
@@ -6598,7 +6618,8 @@ class ProcessTransport {
|
|
|
6598
6618
|
if (this.options.resumeSessionAt) {
|
|
6599
6619
|
args.push("--resume-session-at", this.options.resumeSessionAt);
|
|
6600
6620
|
}
|
|
6601
|
-
|
|
6621
|
+
const effectiveExtraArgs = mergeSandboxIntoExtraArgs(extraArgs ?? {}, sandbox);
|
|
6622
|
+
for (const [flag, value] of Object.entries(effectiveExtraArgs)) {
|
|
6602
6623
|
if (value === null) {
|
|
6603
6624
|
args.push(`--${flag}`);
|
|
6604
6625
|
} else {
|
|
@@ -7676,6 +7697,7 @@ class Query {
|
|
|
7676
7697
|
hooks;
|
|
7677
7698
|
abortController;
|
|
7678
7699
|
jsonSchema;
|
|
7700
|
+
initConfig;
|
|
7679
7701
|
pendingControlResponses = new Map;
|
|
7680
7702
|
cleanupPerformed = false;
|
|
7681
7703
|
sdkMessages;
|
|
@@ -7689,13 +7711,14 @@ class Query {
|
|
|
7689
7711
|
firstResultReceivedPromise;
|
|
7690
7712
|
firstResultReceivedResolve;
|
|
7691
7713
|
streamCloseTimeout;
|
|
7692
|
-
constructor(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers = new Map, jsonSchema) {
|
|
7714
|
+
constructor(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers = new Map, jsonSchema, initConfig) {
|
|
7693
7715
|
this.transport = transport;
|
|
7694
7716
|
this.isSingleUserTurn = isSingleUserTurn;
|
|
7695
7717
|
this.canUseTool = canUseTool;
|
|
7696
7718
|
this.hooks = hooks;
|
|
7697
7719
|
this.abortController = abortController;
|
|
7698
7720
|
this.jsonSchema = jsonSchema;
|
|
7721
|
+
this.initConfig = initConfig;
|
|
7699
7722
|
this.streamCloseTimeout = 60000;
|
|
7700
7723
|
if (typeof process !== "undefined" && process.env?.CLAUDE_CODE_STREAM_CLOSE_TIMEOUT) {
|
|
7701
7724
|
this.streamCloseTimeout = parseInt(process.env.CLAUDE_CODE_STREAM_CLOSE_TIMEOUT);
|
|
@@ -7888,7 +7911,10 @@ class Query {
|
|
|
7888
7911
|
subtype: "initialize",
|
|
7889
7912
|
hooks,
|
|
7890
7913
|
sdkMcpServers,
|
|
7891
|
-
jsonSchema: this.jsonSchema
|
|
7914
|
+
jsonSchema: this.jsonSchema,
|
|
7915
|
+
systemPrompt: this.initConfig?.systemPrompt,
|
|
7916
|
+
appendSystemPrompt: this.initConfig?.appendSystemPrompt,
|
|
7917
|
+
agents: this.initConfig?.agents
|
|
7892
7918
|
};
|
|
7893
7919
|
const response = await this.request(initRequest);
|
|
7894
7920
|
return response.response;
|
|
@@ -8102,7 +8128,6 @@ class SessionImpl {
|
|
|
8102
8128
|
executable: options.executable ?? (isRunningWithBun() ? "bun" : "node"),
|
|
8103
8129
|
executableArgs: options.executableArgs ?? [],
|
|
8104
8130
|
extraArgs: {},
|
|
8105
|
-
customSystemPrompt: "",
|
|
8106
8131
|
maxThinkingTokens: undefined,
|
|
8107
8132
|
maxTurns: undefined,
|
|
8108
8133
|
maxBudgetUsd: undefined,
|
|
@@ -15059,7 +15084,7 @@ function query({
|
|
|
15059
15084
|
prompt,
|
|
15060
15085
|
options
|
|
15061
15086
|
}) {
|
|
15062
|
-
const { systemPrompt, settingSources, ...rest } = options ?? {};
|
|
15087
|
+
const { systemPrompt, settingSources, sandbox, ...rest } = options ?? {};
|
|
15063
15088
|
let customSystemPrompt;
|
|
15064
15089
|
let appendSystemPrompt;
|
|
15065
15090
|
if (systemPrompt === undefined) {
|
|
@@ -15075,7 +15100,7 @@ function query({
|
|
|
15075
15100
|
const dirname2 = join5(filename, "..");
|
|
15076
15101
|
pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
|
|
15077
15102
|
}
|
|
15078
|
-
process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.
|
|
15103
|
+
process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.57";
|
|
15079
15104
|
const {
|
|
15080
15105
|
abortController = createAbortController(),
|
|
15081
15106
|
additionalDirectories = [],
|
|
@@ -15085,6 +15110,7 @@ function query({
|
|
|
15085
15110
|
continue: continueConversation,
|
|
15086
15111
|
cwd: cwd2,
|
|
15087
15112
|
disallowedTools = [],
|
|
15113
|
+
tools,
|
|
15088
15114
|
env,
|
|
15089
15115
|
executable = isRunningWithBun() ? "bun" : "node",
|
|
15090
15116
|
executableArgs = [],
|
|
@@ -15138,7 +15164,6 @@ function query({
|
|
|
15138
15164
|
const transport = new ProcessTransport({
|
|
15139
15165
|
abortController,
|
|
15140
15166
|
additionalDirectories,
|
|
15141
|
-
agents,
|
|
15142
15167
|
cwd: cwd2,
|
|
15143
15168
|
executable,
|
|
15144
15169
|
executableArgs,
|
|
@@ -15147,8 +15172,6 @@ function query({
|
|
|
15147
15172
|
env: processEnv,
|
|
15148
15173
|
forkSession,
|
|
15149
15174
|
stderr,
|
|
15150
|
-
customSystemPrompt,
|
|
15151
|
-
appendSystemPrompt,
|
|
15152
15175
|
maxThinkingTokens,
|
|
15153
15176
|
maxTurns,
|
|
15154
15177
|
maxBudgetUsd,
|
|
@@ -15164,14 +15187,21 @@ function query({
|
|
|
15164
15187
|
settingSources: settingSources ?? [],
|
|
15165
15188
|
allowedTools,
|
|
15166
15189
|
disallowedTools,
|
|
15190
|
+
tools,
|
|
15167
15191
|
mcpServers: allMcpServers,
|
|
15168
15192
|
strictMcpConfig,
|
|
15169
15193
|
canUseTool: !!canUseTool,
|
|
15170
15194
|
hooks: !!hooks,
|
|
15171
15195
|
includePartialMessages,
|
|
15172
|
-
plugins
|
|
15196
|
+
plugins,
|
|
15197
|
+
sandbox
|
|
15173
15198
|
});
|
|
15174
|
-
const
|
|
15199
|
+
const initConfig = {
|
|
15200
|
+
systemPrompt: customSystemPrompt,
|
|
15201
|
+
appendSystemPrompt,
|
|
15202
|
+
agents
|
|
15203
|
+
};
|
|
15204
|
+
const queryInstance = new Query(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers, jsonSchema, initConfig);
|
|
15175
15205
|
if (typeof prompt === "string") {
|
|
15176
15206
|
transport.write(JSON.stringify({
|
|
15177
15207
|
type: "user",
|