@anthropic-ai/claude-code 1.0.123 → 1.0.125
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 +1040 -1014
- package/package.json +1 -1
- package/sdk-tools.d.ts +4 -0
- package/sdk.d.ts +20 -1
- package/sdk.mjs +129 -99
package/package.json
CHANGED
package/sdk-tools.d.ts
CHANGED
|
@@ -70,6 +70,10 @@ export interface BashInput {
|
|
|
70
70
|
* Set to true to run this command in the background. Use BashOutput to read the output later.
|
|
71
71
|
*/
|
|
72
72
|
run_in_background?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Set this to true to dangerously override sandbox mode and run commands without sandboxing.
|
|
75
|
+
*/
|
|
76
|
+
dangerouslyOverrideSandbox?: boolean;
|
|
73
77
|
}
|
|
74
78
|
export interface BashOutputInput {
|
|
75
79
|
/**
|
package/sdk.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type ModelUsage = {
|
|
|
14
14
|
cacheCreationInputTokens: number;
|
|
15
15
|
webSearchRequests: number;
|
|
16
16
|
costUSD: number;
|
|
17
|
+
contextWindow: number;
|
|
17
18
|
};
|
|
18
19
|
export type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';
|
|
19
20
|
export type ConfigScope = 'local' | 'user' | 'project';
|
|
@@ -230,6 +231,11 @@ export type Options = {
|
|
|
230
231
|
executableArgs?: string[];
|
|
231
232
|
extraArgs?: Record<string, string | null>;
|
|
232
233
|
fallbackModel?: string;
|
|
234
|
+
/**
|
|
235
|
+
* When true resumed sessions will fork to a new session ID rather than
|
|
236
|
+
* continuing the previous session. Use with --resume.
|
|
237
|
+
*/
|
|
238
|
+
forkSession?: boolean;
|
|
233
239
|
hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
234
240
|
includePartialMessages?: boolean;
|
|
235
241
|
maxThinkingTokens?: number;
|
|
@@ -240,10 +246,17 @@ export type Options = {
|
|
|
240
246
|
permissionMode?: PermissionMode;
|
|
241
247
|
permissionPromptToolName?: string;
|
|
242
248
|
resume?: string;
|
|
249
|
+
/**
|
|
250
|
+
* When resuming, only resume messages up to and including the assistant
|
|
251
|
+
* message with this message.id. Use with --resume.
|
|
252
|
+
* This allows you to resume from a specific point in the conversation.
|
|
253
|
+
* The message ID is expected to be from SDKAssistantMessage.message.id.
|
|
254
|
+
*/
|
|
255
|
+
resumeSessionAt?: string;
|
|
243
256
|
stderr?: (data: string) => void;
|
|
244
257
|
strictMcpConfig?: boolean;
|
|
245
258
|
};
|
|
246
|
-
export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
|
|
259
|
+
export type PermissionMode = 'default' | 'acceptEdits' | 'sandboxBashMode' | 'bypassPermissions' | 'plan';
|
|
247
260
|
export type SlashCommand = {
|
|
248
261
|
name: string;
|
|
249
262
|
description: string;
|
|
@@ -270,6 +283,11 @@ type SDKUserMessageContent = {
|
|
|
270
283
|
type: 'user';
|
|
271
284
|
message: APIUserMessage;
|
|
272
285
|
parent_tool_use_id: string | null;
|
|
286
|
+
/**
|
|
287
|
+
* True if this is a 'synthetic' user message which did not originate from
|
|
288
|
+
* the user directly, but instead was generated by the system.
|
|
289
|
+
*/
|
|
290
|
+
isSynthetic?: boolean;
|
|
273
291
|
};
|
|
274
292
|
export type SDKUserMessage = SDKUserMessageContent & {
|
|
275
293
|
uuid?: UUID;
|
|
@@ -317,6 +335,7 @@ export type SDKResultMessage = (SDKMessageBase & {
|
|
|
317
335
|
export type SDKSystemMessage = SDKMessageBase & {
|
|
318
336
|
type: 'system';
|
|
319
337
|
subtype: 'init';
|
|
338
|
+
agents?: string[];
|
|
320
339
|
apiKeySource: ApiKeySource;
|
|
321
340
|
cwd: string;
|
|
322
341
|
tools: string[];
|
package/sdk.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// (c) Anthropic PBC. All rights reserved. Use is subject to Anthropic's Commercial Terms of Service (https://www.anthropic.com/legal/commercial-terms).
|
|
4
4
|
|
|
5
|
-
// Version: 1.0.
|
|
5
|
+
// Version: 1.0.125
|
|
6
6
|
|
|
7
7
|
// Want to see the unminified source? We're hiring!
|
|
8
8
|
// https://job-boards.greenhouse.io/anthropic/jobs/4816199008
|
|
@@ -6201,7 +6201,7 @@ var require_ajv = __commonJS((exports, module) => {
|
|
|
6201
6201
|
function noop() {}
|
|
6202
6202
|
});
|
|
6203
6203
|
|
|
6204
|
-
// src/
|
|
6204
|
+
// src/core/sharedQuery.ts
|
|
6205
6205
|
import { join } from "path";
|
|
6206
6206
|
import { fileURLToPath } from "url";
|
|
6207
6207
|
|
|
@@ -6365,6 +6365,7 @@ class ProcessTransport {
|
|
|
6365
6365
|
try {
|
|
6366
6366
|
const {
|
|
6367
6367
|
additionalDirectories = [],
|
|
6368
|
+
agents,
|
|
6368
6369
|
cwd,
|
|
6369
6370
|
executable = isRunningWithBun() ? "bun" : "node",
|
|
6370
6371
|
executableArgs = [],
|
|
@@ -6381,6 +6382,7 @@ class ProcessTransport {
|
|
|
6381
6382
|
permissionPromptToolName,
|
|
6382
6383
|
continueConversation,
|
|
6383
6384
|
resume,
|
|
6385
|
+
settingSources,
|
|
6384
6386
|
allowedTools = [],
|
|
6385
6387
|
disallowedTools = [],
|
|
6386
6388
|
mcpServers,
|
|
@@ -6426,6 +6428,12 @@ class ProcessTransport {
|
|
|
6426
6428
|
if (mcpServers && Object.keys(mcpServers).length > 0) {
|
|
6427
6429
|
args.push("--mcp-config", JSON.stringify({ mcpServers }));
|
|
6428
6430
|
}
|
|
6431
|
+
if (agents && Object.keys(agents).length > 0) {
|
|
6432
|
+
args.push("--agents", JSON.stringify(agents));
|
|
6433
|
+
}
|
|
6434
|
+
if (settingSources && settingSources.length > 0) {
|
|
6435
|
+
args.push("--setting-sources", settingSources.join(","));
|
|
6436
|
+
}
|
|
6429
6437
|
if (strictMcpConfig) {
|
|
6430
6438
|
args.push("--strict-mcp-config");
|
|
6431
6439
|
}
|
|
@@ -6444,6 +6452,12 @@ class ProcessTransport {
|
|
|
6444
6452
|
for (const dir of additionalDirectories) {
|
|
6445
6453
|
args.push("--add-dir", dir);
|
|
6446
6454
|
}
|
|
6455
|
+
if (this.options.forkSession) {
|
|
6456
|
+
args.push("--fork-session");
|
|
6457
|
+
}
|
|
6458
|
+
if (this.options.resumeSessionAt) {
|
|
6459
|
+
args.push("--resume-session-at", this.options.resumeSessionAt);
|
|
6460
|
+
}
|
|
6447
6461
|
for (const [flag, value] of Object.entries(extraArgs)) {
|
|
6448
6462
|
if (value === null) {
|
|
6449
6463
|
args.push(`--${flag}`);
|
|
@@ -7131,6 +7145,117 @@ class Query {
|
|
|
7131
7145
|
}
|
|
7132
7146
|
}
|
|
7133
7147
|
|
|
7148
|
+
// src/core/sharedQuery.ts
|
|
7149
|
+
function createSharedQuery({
|
|
7150
|
+
prompt,
|
|
7151
|
+
options: {
|
|
7152
|
+
abortController = createAbortController(),
|
|
7153
|
+
additionalDirectories = [],
|
|
7154
|
+
agents,
|
|
7155
|
+
allowedTools = [],
|
|
7156
|
+
appendSystemPrompt,
|
|
7157
|
+
canUseTool,
|
|
7158
|
+
continue: continueConversation,
|
|
7159
|
+
customSystemPrompt,
|
|
7160
|
+
cwd,
|
|
7161
|
+
disallowedTools = [],
|
|
7162
|
+
env,
|
|
7163
|
+
executable = isRunningWithBun() ? "bun" : "node",
|
|
7164
|
+
executableArgs = [],
|
|
7165
|
+
extraArgs = {},
|
|
7166
|
+
fallbackModel,
|
|
7167
|
+
forkSession,
|
|
7168
|
+
hooks,
|
|
7169
|
+
includePartialMessages,
|
|
7170
|
+
maxTurns,
|
|
7171
|
+
mcpServers,
|
|
7172
|
+
model,
|
|
7173
|
+
pathToClaudeCodeExecutable,
|
|
7174
|
+
permissionMode = "default",
|
|
7175
|
+
permissionPromptToolName,
|
|
7176
|
+
resume,
|
|
7177
|
+
resumeSessionAt,
|
|
7178
|
+
settingSources,
|
|
7179
|
+
stderr,
|
|
7180
|
+
strictMcpConfig
|
|
7181
|
+
} = {}
|
|
7182
|
+
}) {
|
|
7183
|
+
if (!env) {
|
|
7184
|
+
env = { ...process.env };
|
|
7185
|
+
}
|
|
7186
|
+
if (!env.CLAUDE_CODE_ENTRYPOINT) {
|
|
7187
|
+
env.CLAUDE_CODE_ENTRYPOINT = "sdk-ts";
|
|
7188
|
+
}
|
|
7189
|
+
if (pathToClaudeCodeExecutable === undefined) {
|
|
7190
|
+
const filename = fileURLToPath(import.meta.url);
|
|
7191
|
+
const dirname = join(filename, "..");
|
|
7192
|
+
pathToClaudeCodeExecutable = join(dirname, "..", "entrypoints", "cli.js");
|
|
7193
|
+
}
|
|
7194
|
+
const allMcpServers = {};
|
|
7195
|
+
const sdkMcpServers = new Map;
|
|
7196
|
+
if (mcpServers) {
|
|
7197
|
+
for (const [name, config] of Object.entries(mcpServers)) {
|
|
7198
|
+
if (config.type === "sdk" && "instance" in config) {
|
|
7199
|
+
sdkMcpServers.set(name, config.instance);
|
|
7200
|
+
allMcpServers[name] = {
|
|
7201
|
+
type: "sdk",
|
|
7202
|
+
name
|
|
7203
|
+
};
|
|
7204
|
+
} else {
|
|
7205
|
+
allMcpServers[name] = config;
|
|
7206
|
+
}
|
|
7207
|
+
}
|
|
7208
|
+
}
|
|
7209
|
+
const isSingleUserTurn = typeof prompt === "string";
|
|
7210
|
+
const transport = new ProcessTransport({
|
|
7211
|
+
abortController,
|
|
7212
|
+
additionalDirectories,
|
|
7213
|
+
agents,
|
|
7214
|
+
cwd,
|
|
7215
|
+
executable,
|
|
7216
|
+
executableArgs,
|
|
7217
|
+
extraArgs,
|
|
7218
|
+
pathToClaudeCodeExecutable,
|
|
7219
|
+
env,
|
|
7220
|
+
forkSession,
|
|
7221
|
+
stderr,
|
|
7222
|
+
customSystemPrompt,
|
|
7223
|
+
appendSystemPrompt,
|
|
7224
|
+
maxTurns,
|
|
7225
|
+
model,
|
|
7226
|
+
fallbackModel,
|
|
7227
|
+
permissionMode,
|
|
7228
|
+
permissionPromptToolName,
|
|
7229
|
+
continueConversation,
|
|
7230
|
+
resume,
|
|
7231
|
+
resumeSessionAt,
|
|
7232
|
+
settingSources,
|
|
7233
|
+
allowedTools,
|
|
7234
|
+
disallowedTools,
|
|
7235
|
+
mcpServers: allMcpServers,
|
|
7236
|
+
strictMcpConfig,
|
|
7237
|
+
canUseTool: !!canUseTool,
|
|
7238
|
+
hooks: !!hooks,
|
|
7239
|
+
includePartialMessages
|
|
7240
|
+
});
|
|
7241
|
+
const query = new Query(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers);
|
|
7242
|
+
if (typeof prompt === "string") {
|
|
7243
|
+
transport.write(JSON.stringify({
|
|
7244
|
+
type: "user",
|
|
7245
|
+
session_id: "",
|
|
7246
|
+
message: {
|
|
7247
|
+
role: "user",
|
|
7248
|
+
content: [{ type: "text", text: prompt }]
|
|
7249
|
+
},
|
|
7250
|
+
parent_tool_use_id: null
|
|
7251
|
+
}) + `
|
|
7252
|
+
`);
|
|
7253
|
+
} else {
|
|
7254
|
+
query.streamInput(prompt);
|
|
7255
|
+
}
|
|
7256
|
+
return query;
|
|
7257
|
+
}
|
|
7258
|
+
|
|
7134
7259
|
// node_modules/zod/v3/external.js
|
|
7135
7260
|
var exports_external = {};
|
|
7136
7261
|
__export(exports_external, {
|
|
@@ -14014,104 +14139,9 @@ function createSdkMcpServer(options) {
|
|
|
14014
14139
|
// src/entrypoints/sdk.ts
|
|
14015
14140
|
function query({
|
|
14016
14141
|
prompt,
|
|
14017
|
-
options
|
|
14018
|
-
abortController = createAbortController(),
|
|
14019
|
-
additionalDirectories = [],
|
|
14020
|
-
allowedTools = [],
|
|
14021
|
-
appendSystemPrompt,
|
|
14022
|
-
canUseTool,
|
|
14023
|
-
continue: continueConversation,
|
|
14024
|
-
customSystemPrompt,
|
|
14025
|
-
cwd,
|
|
14026
|
-
disallowedTools = [],
|
|
14027
|
-
env,
|
|
14028
|
-
executable = isRunningWithBun() ? "bun" : "node",
|
|
14029
|
-
executableArgs = [],
|
|
14030
|
-
extraArgs = {},
|
|
14031
|
-
fallbackModel,
|
|
14032
|
-
hooks,
|
|
14033
|
-
includePartialMessages,
|
|
14034
|
-
maxTurns,
|
|
14035
|
-
mcpServers,
|
|
14036
|
-
model,
|
|
14037
|
-
pathToClaudeCodeExecutable,
|
|
14038
|
-
permissionMode = "default",
|
|
14039
|
-
permissionPromptToolName,
|
|
14040
|
-
resume,
|
|
14041
|
-
stderr,
|
|
14042
|
-
strictMcpConfig
|
|
14043
|
-
} = {}
|
|
14142
|
+
options
|
|
14044
14143
|
}) {
|
|
14045
|
-
|
|
14046
|
-
env = { ...process.env };
|
|
14047
|
-
}
|
|
14048
|
-
if (!env.CLAUDE_CODE_ENTRYPOINT) {
|
|
14049
|
-
env.CLAUDE_CODE_ENTRYPOINT = "sdk-ts";
|
|
14050
|
-
}
|
|
14051
|
-
if (pathToClaudeCodeExecutable === undefined) {
|
|
14052
|
-
const filename = fileURLToPath(import.meta.url);
|
|
14053
|
-
const dirname = join(filename, "..");
|
|
14054
|
-
pathToClaudeCodeExecutable = join(dirname, "cli.js");
|
|
14055
|
-
}
|
|
14056
|
-
const allMcpServers = {};
|
|
14057
|
-
const sdkMcpServers = new Map;
|
|
14058
|
-
if (mcpServers) {
|
|
14059
|
-
for (const [name, config] of Object.entries(mcpServers)) {
|
|
14060
|
-
if (config.type === "sdk") {
|
|
14061
|
-
sdkMcpServers.set(name, config.instance);
|
|
14062
|
-
allMcpServers[name] = {
|
|
14063
|
-
type: "sdk",
|
|
14064
|
-
name
|
|
14065
|
-
};
|
|
14066
|
-
} else {
|
|
14067
|
-
allMcpServers[name] = config;
|
|
14068
|
-
}
|
|
14069
|
-
}
|
|
14070
|
-
}
|
|
14071
|
-
const isSingleUserTurn = typeof prompt === "string";
|
|
14072
|
-
const transport = new ProcessTransport({
|
|
14073
|
-
abortController,
|
|
14074
|
-
additionalDirectories,
|
|
14075
|
-
cwd,
|
|
14076
|
-
executable,
|
|
14077
|
-
executableArgs,
|
|
14078
|
-
extraArgs,
|
|
14079
|
-
pathToClaudeCodeExecutable,
|
|
14080
|
-
env,
|
|
14081
|
-
stderr,
|
|
14082
|
-
customSystemPrompt,
|
|
14083
|
-
appendSystemPrompt,
|
|
14084
|
-
maxTurns,
|
|
14085
|
-
model,
|
|
14086
|
-
fallbackModel,
|
|
14087
|
-
permissionMode,
|
|
14088
|
-
permissionPromptToolName,
|
|
14089
|
-
continueConversation,
|
|
14090
|
-
resume,
|
|
14091
|
-
allowedTools,
|
|
14092
|
-
disallowedTools,
|
|
14093
|
-
mcpServers,
|
|
14094
|
-
strictMcpConfig,
|
|
14095
|
-
canUseTool: !!canUseTool,
|
|
14096
|
-
hooks: !!hooks,
|
|
14097
|
-
includePartialMessages
|
|
14098
|
-
});
|
|
14099
|
-
const query2 = new Query(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers);
|
|
14100
|
-
if (typeof prompt === "string") {
|
|
14101
|
-
transport.write(JSON.stringify({
|
|
14102
|
-
type: "user",
|
|
14103
|
-
session_id: "",
|
|
14104
|
-
message: {
|
|
14105
|
-
role: "user",
|
|
14106
|
-
content: [{ type: "text", text: prompt }]
|
|
14107
|
-
},
|
|
14108
|
-
parent_tool_use_id: null
|
|
14109
|
-
}) + `
|
|
14110
|
-
`);
|
|
14111
|
-
} else {
|
|
14112
|
-
query2.streamInput(prompt);
|
|
14113
|
-
}
|
|
14114
|
-
return query2;
|
|
14144
|
+
return createSharedQuery({ prompt, options });
|
|
14115
14145
|
}
|
|
14116
14146
|
export {
|
|
14117
14147
|
tool,
|