@anthropic-ai/claude-agent-sdk 0.1.36 → 0.1.39

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.
Files changed (4) hide show
  1. package/cli.js +1768 -1683
  2. package/package.json +1 -1
  3. package/sdk.d.ts +2 -0
  4. package/sdk.mjs +43 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.36",
3
+ "version": "0.1.39",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
package/sdk.d.ts CHANGED
@@ -143,6 +143,8 @@ export type HookCallback = (input: HookInput, toolUseID: string | undefined, opt
143
143
  export interface HookCallbackMatcher {
144
144
  matcher?: string;
145
145
  hooks: HookCallback[];
146
+ /** Timeout in seconds for all hooks in this matcher */
147
+ timeout?: number;
146
148
  }
147
149
  export type BaseHookInput = {
148
150
  session_id: string;
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.36
4
+ // Version: 0.1.39
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -6251,11 +6251,14 @@ var NodeFsOperations = {
6251
6251
  }
6252
6252
  },
6253
6253
  writeFileSync(fsPath, data, options) {
6254
+ const fileExists = fs.existsSync(fsPath);
6254
6255
  if (!options.flush) {
6255
6256
  const writeOptions = {
6256
6257
  encoding: options.encoding
6257
6258
  };
6258
- if (options.mode !== undefined) {
6259
+ if (!fileExists) {
6260
+ writeOptions.mode = options.mode ?? 384;
6261
+ } else if (options.mode !== undefined) {
6259
6262
  writeOptions.mode = options.mode;
6260
6263
  }
6261
6264
  fs.writeFileSync(fsPath, data, writeOptions);
@@ -6263,7 +6266,7 @@ var NodeFsOperations = {
6263
6266
  }
6264
6267
  let fd;
6265
6268
  try {
6266
- const mode = options.mode !== undefined ? options.mode : undefined;
6269
+ const mode = !fileExists ? options.mode ?? 384 : options.mode;
6267
6270
  fd = fs.openSync(fsPath, "w", mode);
6268
6271
  fs.writeFileSync(fd, data, { encoding: options.encoding });
6269
6272
  fs.fsyncSync(fd);
@@ -6273,8 +6276,18 @@ var NodeFsOperations = {
6273
6276
  }
6274
6277
  }
6275
6278
  },
6276
- appendFileSync(path, data) {
6277
- fs.appendFileSync(path, data);
6279
+ appendFileSync(path, data, options) {
6280
+ if (!fs.existsSync(path)) {
6281
+ const mode = options?.mode ?? 384;
6282
+ const fd = fs.openSync(path, "a", mode);
6283
+ try {
6284
+ fs.appendFileSync(fd, data);
6285
+ } finally {
6286
+ fs.closeSync(fd);
6287
+ }
6288
+ } else {
6289
+ fs.appendFileSync(path, data);
6290
+ }
6278
6291
  },
6279
6292
  copyFileSync(src, dest) {
6280
6293
  fs.copyFileSync(src, dest);
@@ -6959,12 +6972,6 @@ function getNative(object, key) {
6959
6972
  }
6960
6973
  var _getNative_default = getNative;
6961
6974
 
6962
- // ../node_modules/lodash-es/eq.js
6963
- function eq(value, other) {
6964
- return value === other || value !== value && other !== other;
6965
- }
6966
- var eq_default = eq;
6967
-
6968
6975
  // ../node_modules/lodash-es/_nativeCreate.js
6969
6976
  var nativeCreate = _getNative_default(Object, "create");
6970
6977
  var _nativeCreate_default = nativeCreate;
@@ -7040,6 +7047,12 @@ function listCacheClear() {
7040
7047
  }
7041
7048
  var _listCacheClear_default = listCacheClear;
7042
7049
 
7050
+ // ../node_modules/lodash-es/eq.js
7051
+ function eq(value, other) {
7052
+ return value === other || value !== value && other !== other;
7053
+ }
7054
+ var eq_default = eq;
7055
+
7043
7056
  // ../node_modules/lodash-es/_assocIndexOf.js
7044
7057
  function assocIndexOf(array, key) {
7045
7058
  var length = array.length;
@@ -7207,6 +7220,7 @@ function memoize(func, resolver) {
7207
7220
  }
7208
7221
  memoize.Cache = _MapCache_default;
7209
7222
  var memoize_default = memoize;
7223
+
7210
7224
  // ../src/utils/process.ts
7211
7225
  var CHUNK_SIZE = 2000;
7212
7226
  function writeToStderr(data) {
@@ -7387,10 +7401,8 @@ function getInitialState() {
7387
7401
  cwd: resolvedCwd,
7388
7402
  modelUsage: {},
7389
7403
  mainLoopModelOverride: undefined,
7390
- maxRateLimitFallbackActive: false,
7391
7404
  initialMainLoopModel: null,
7392
7405
  modelStrings: null,
7393
- isNonInteractiveSession: true,
7394
7406
  isInteractive: false,
7395
7407
  clientType: "cli",
7396
7408
  sessionIngressToken: undefined,
@@ -7465,7 +7477,8 @@ function logForDebugging(message, { level } = {
7465
7477
  `)) {
7466
7478
  message = JSON.stringify(message);
7467
7479
  }
7468
- const output = `[${level.toUpperCase()}] ${message.trim()}
7480
+ const timestamp = new Date().toISOString();
7481
+ const output = `${timestamp} [${level.toUpperCase()}] ${message.trim()}
7469
7482
  `;
7470
7483
  if (isDebugToStdErr()) {
7471
7484
  writeToStderr(output);
@@ -7498,6 +7511,8 @@ var updateLatestDebugLogSymlink = memoize_default(() => {
7498
7511
  });
7499
7512
 
7500
7513
  // ../src/core/Query.ts
7514
+ import { randomUUID as randomUUID2 } from "crypto";
7515
+
7501
7516
  class Query {
7502
7517
  transport;
7503
7518
  isSingleUserTurn;
@@ -7696,7 +7711,8 @@ class Query {
7696
7711
  }
7697
7712
  return {
7698
7713
  matcher: matcher.matcher,
7699
- hookCallbackIds: callbackIds
7714
+ hookCallbackIds: callbackIds,
7715
+ timeout: matcher.timeout
7700
7716
  };
7701
7717
  });
7702
7718
  }
@@ -7843,7 +7859,17 @@ class Query {
7843
7859
  return;
7844
7860
  }
7845
7861
  }
7846
- throw new Error("No pending request found");
7862
+ const controlRequest = {
7863
+ type: "control_request",
7864
+ request_id: randomUUID2(),
7865
+ request: {
7866
+ subtype: "mcp_message",
7867
+ server_name: serverName,
7868
+ message
7869
+ }
7870
+ };
7871
+ this.transport.write(JSON.stringify(controlRequest) + `
7872
+ `);
7847
7873
  }
7848
7874
  handleMcpControlRequest(serverName, mcpRequest, transport) {
7849
7875
  const messageId = "id" in mcpRequest.message ? mcpRequest.message.id : null;
@@ -14776,7 +14802,7 @@ function query({
14776
14802
  const dirname2 = join3(filename, "..");
14777
14803
  pathToClaudeCodeExecutable = join3(dirname2, "cli.js");
14778
14804
  }
14779
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.36";
14805
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.39";
14780
14806
  const {
14781
14807
  abortController = createAbortController(),
14782
14808
  additionalDirectories = [],