@anthropic-ai/claude-agent-sdk 0.3.143 → 0.3.144

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.
@@ -0,0 +1 @@
1
+ export function extractFromBunfs(embeddedPath: string): string
@@ -0,0 +1,156 @@
1
+ /* eslint-disable custom-rules/no-sync-fs */
2
+ // Extracts a file from Bun's $bunfs virtual filesystem to a real temp directory
3
+ // so it can be spawned as a subprocess (child processes cannot access $bunfs).
4
+ //
5
+ // Ships verbatim (unbundled) as the @anthropic-ai/claude-agent-sdk `./extract`
6
+ // export — keep it standalone and Node-importable (no Bun globals, no
7
+ // local-relative imports).
8
+
9
+ import { createHash } from 'crypto'
10
+ import {
11
+ chmodSync,
12
+ existsSync,
13
+ lstatSync,
14
+ mkdirSync,
15
+ readFileSync,
16
+ renameSync,
17
+ unlinkSync,
18
+ writeFileSync,
19
+ } from 'fs'
20
+ import { tmpdir as osTmpdir } from 'os'
21
+ import { basename, join } from 'path'
22
+
23
+ // Inlined from src/utils/tempfile.ts — this file ships verbatim (unbundled) as
24
+ // the @anthropic-ai/claude-agent-sdk/extract export, so it must have zero
25
+ // local-relative imports. Keep behavior in sync with tempfile.ts#tmpdir.
26
+ function tmpdir() {
27
+ if (process.env.CLAUDE_CODE_TMPDIR) {
28
+ return process.env.CLAUDE_CODE_TMPDIR
29
+ }
30
+ if (process.platform === 'darwin') {
31
+ // eslint-disable-next-line custom-rules/no-hardcoded-tmp -- mirrors tempfile.ts: macOS /tmp works fine; os.tmpdir() below is for Android-on-Linux where /tmp isn't writable.
32
+ return '/tmp'
33
+ }
34
+ return osTmpdir()
35
+ }
36
+
37
+ // Inlined from src/utils/tempfile.ts#claudeTempDir + verifyTempDirOwnership —
38
+ // keep behavior in sync. Per-UID Claude temp directory: `{tmpdir()}/claude-{uid}`
39
+ // on Unix, `{tmpdir()}/claude` on Windows (where %TEMP% is already per-user).
40
+ //
41
+ // Defense-in-depth against a local attacker pre-creating the extraction dir
42
+ // before the victim's first run: the content-hash dir name is fully predictable
43
+ // (sha256 of a public npm binary) under shared `/tmp`, and
44
+ // `mkdirSync({recursive:true})` is a silent no-op on a pre-existing dir without
45
+ // enforcing owner or mode. Without this check an attacker-owned directory would
46
+ // be used as-is, letting them swap the binary the SDK later spawns.
47
+ function safeTempBase() {
48
+ const dir = join(
49
+ tmpdir(),
50
+ process.platform === 'win32'
51
+ ? 'claude'
52
+ : `claude-${process.getuid?.() ?? 0}`,
53
+ )
54
+ // Gate on getuid (POSIX-only) rather than process.platform: getuid presence
55
+ // reflects the real OS. No-op on Windows where %TEMP% is already per-user.
56
+ if (typeof process.getuid === 'function') {
57
+ mkdirSync(dir, { recursive: true, mode: 0o700 })
58
+ const uid = process.getuid()
59
+ const st = lstatSync(dir)
60
+ if (!st.isDirectory()) {
61
+ throw new Error(
62
+ `Temp directory ${dir} is not a directory (may be an attacker-planted symlink). Refusing to use it.`,
63
+ )
64
+ }
65
+ if (st.uid !== uid) {
66
+ throw new Error(
67
+ `Temp directory ${dir} is owned by uid ${st.uid}, expected ${uid}. Refusing to use it — another user may have pre-created it.`,
68
+ )
69
+ }
70
+ if ((st.mode & 0o777) !== 0o700) {
71
+ // Owner matches, so this is our own dir from a prior run with a looser
72
+ // umask rather than an attacker pre-create. Tighten it.
73
+ chmodSync(dir, 0o700)
74
+ }
75
+ } else {
76
+ // Windows: best-effort create; verification is skipped (%TEMP% is per-user).
77
+ try {
78
+ mkdirSync(dir, { recursive: true, mode: 0o700 })
79
+ } catch {
80
+ // best-effort; see comment above
81
+ }
82
+ }
83
+ return dir
84
+ }
85
+
86
+ /**
87
+ * If `embeddedPath` is inside Bun's $bunfs virtual filesystem, extract it to a
88
+ * temp directory and return the real path. Otherwise return the path unchanged.
89
+ *
90
+ * Uses a content hash for the directory name so that:
91
+ * - Same binary version reuses the same extracted file (no accumulation)
92
+ * - Different versions get separate directories (no collision)
93
+ * - Concurrent instances are safe (atomic write via temp file + rename)
94
+ *
95
+ * @param {string} embeddedPath — path returned by `import ... with { type: 'file' }`
96
+ * @returns {string} — a real filesystem path that can be spawned as a subprocess
97
+ */
98
+ export function extractFromBunfs(embeddedPath) {
99
+ // Bun single-file embed: `/$bunfs/root/...` (POSIX) or `B:\~BUN\root\...`
100
+ // (Windows — Bun's StandaloneModuleGraph uses `~BUN`, not `$bunfs`, on Windows).
101
+ if (!embeddedPath.includes('$bunfs') && !embeddedPath.includes('~BUN')) {
102
+ return embeddedPath
103
+ }
104
+
105
+ try {
106
+ const content = readFileSync(embeddedPath)
107
+ const hash = createHash('sha256').update(content).digest('hex').slice(0, 16)
108
+ const tmpDir = join(safeTempBase(), `claude-agent-sdk-${hash}`)
109
+ // Preserve the embedded file's basename — ProcessTransport.isNativeBinary()
110
+ // decides whether to spawn directly or via node/bun based on extension, so
111
+ // a native binary must not come out named cli.js.
112
+ const fileName = basename(embeddedPath)
113
+ const tmpPath = join(tmpDir, fileName)
114
+ mkdirSync(tmpDir, { recursive: true, mode: 0o700 })
115
+ // The directory is content-hash-keyed, so an existing tmpPath is byte-
116
+ // identical to what we would write — short-circuit. This is a write
117
+ // idempotency check on a content-addressed path, not a read TOCTOU
118
+ // (the existence IS the contract). Without it, a second call (or a
119
+ // concurrent app instance) on Windows would hit EPERM/EBUSY renaming over
120
+ // the memory-mapped running .exe and fall back to the unspawnable $bunfs
121
+ // path. It also skips a redundant write+chmod on every call.
122
+ if (existsSync(tmpPath)) {
123
+ return tmpPath
124
+ }
125
+ // Write to a temp file and atomically rename to avoid truncation races —
126
+ // concurrent readers always see either the old complete file or the new one.
127
+ const tmpFile = join(tmpDir, `${fileName}.tmp.${process.pid}`)
128
+ writeFileSync(tmpFile, content)
129
+ chmodSync(tmpFile, 0o755)
130
+ try {
131
+ renameSync(tmpFile, tmpPath)
132
+ } catch (e) {
133
+ if ((e.code === 'EPERM' || e.code === 'EBUSY') && existsSync(tmpPath)) {
134
+ // Lost a concurrent first-time-extraction race on Windows: the winner's
135
+ // child holds tmpPath memory-mapped, so the loser's rename over it fails.
136
+ // The content-hash dir guarantees byte-identity, so the winner's file is
137
+ // exactly what we'd have written — use it.
138
+ try {
139
+ unlinkSync(tmpFile)
140
+ } catch {
141
+ // best-effort cleanup of our orphaned .tmp.{pid} file
142
+ }
143
+ return tmpPath
144
+ }
145
+ throw e
146
+ }
147
+ return tmpPath
148
+ } catch (err) {
149
+ // biome-ignore lint/suspicious/noConsole: intentional user-facing warning in standalone SDK helper
150
+ console.warn(
151
+ `[claude-agent-sdk] Failed to extract CLI from $bunfs: ${err.message}. ` +
152
+ `Child processes cannot access $bunfs paths — the CLI will likely fail to start.`,
153
+ )
154
+ return embeddedPath
155
+ }
156
+ }
package/manifest.json CHANGED
@@ -1,47 +1,47 @@
1
1
  {
2
- "version": "2.1.143",
3
- "commit": "cfb8132e4c3551e2773f41a1900efd1cc93637db",
4
- "buildDate": "2026-05-15T17:47:13Z",
2
+ "version": "2.1.144",
3
+ "commit": "32281b6b930f7e2ab4f0b5e2494e263b9c1ffb7e",
4
+ "buildDate": "2026-05-18T18:52:18Z",
5
5
  "platforms": {
6
6
  "darwin-arm64": {
7
7
  "binary": "claude",
8
- "checksum": "2701c6cfd68483f8faf0316a1ba6481a1455a90645ada179f0c48d8c36d722ef",
9
- "size": 207605280
8
+ "checksum": "9886baa4ec4c455f86108464f121732193ee76e5dfceb031005f59f31276a5df",
9
+ "size": 207919008
10
10
  },
11
11
  "darwin-x64": {
12
12
  "binary": "claude",
13
- "checksum": "bc8ff4ce02b765a033808fb596f9522306cbe5c50d21344ed8752c08966f362c",
14
- "size": 210119440
13
+ "checksum": "d225c07b713615ceda54cebcfb6280942b113c64dccbaa114b12204e917087f8",
14
+ "size": 210433168
15
15
  },
16
16
  "linux-arm64": {
17
17
  "binary": "claude",
18
- "checksum": "32e8edc4a5c3c41d18607c75d1b8e7bec643330c03e266be46ac3b41a446c4eb",
19
- "size": 232961672
18
+ "checksum": "c8ccccbfce12d684588bd3af366394132f614dcf3c86beb2066f86bde2704513",
19
+ "size": 233289352
20
20
  },
21
21
  "linux-x64": {
22
22
  "binary": "claude",
23
- "checksum": "f75fdc3ff9d9cd494b86192f9e349b5c5c6d3970ed4d5cd5c7b330c5a2b1dcc4",
24
- "size": 233088720
23
+ "checksum": "147480774472e5720fd5e83617b3e9299344e7213efa84c326b25bd5a0f20b4e",
24
+ "size": 233404112
25
25
  },
26
26
  "linux-arm64-musl": {
27
27
  "binary": "claude",
28
- "checksum": "e68903ec56ddd5560bb0820c96c8f7a4193e7eab6236ede56cb2e05f450ce44f",
29
- "size": 225816408
28
+ "checksum": "68a92c68f18cd25676259b12cd799ddf1e8bdac24f927ac50defd8be26a1448d",
29
+ "size": 226144088
30
30
  },
31
31
  "linux-x64-musl": {
32
32
  "binary": "claude",
33
- "checksum": "e4cb8588ed6e38f9920bdaa2611263d4a0b0d11300f1d23945df234fdf5e278a",
34
- "size": 227482672
33
+ "checksum": "f1f736eb04632ce3f720e04a67ba0209d55726cb88e8e23f6f33b8cd6481b6ca",
34
+ "size": 227798064
35
35
  },
36
36
  "win32-x64": {
37
37
  "binary": "claude.exe",
38
- "checksum": "e480244f2a4660fe76ed32442c1e3e2edda8fb5433417e73faba39f0e7f69eb6",
39
- "size": 228902560
38
+ "checksum": "ae150c7d6100e14c67efc90c2b55e0db9cdbcef2b2c7b3cb56998331182e3d2f",
39
+ "size": 229302432
40
40
  },
41
41
  "win32-arm64": {
42
42
  "binary": "claude.exe",
43
- "checksum": "5cbad78d2f316fedd0d621289aae558aaf259b404d0a46e0e49662ef3b397986",
44
- "size": 224866976
43
+ "checksum": "2871ae906ed83f826ce9fa721ec82418c15315e11ab3cb3fe821f3c056fcff4d",
44
+ "size": 225266848
45
45
  }
46
46
  }
47
47
  }
package/manifest.zst.json CHANGED
@@ -1,55 +1,55 @@
1
1
  {
2
- "version": "2.1.143",
3
- "commit": "cfb8132e4c3551e2773f41a1900efd1cc93637db",
4
- "buildDate": "2026-05-15T17:54:02Z",
2
+ "version": "2.1.144",
3
+ "commit": "32281b6b930f7e2ab4f0b5e2494e263b9c1ffb7e",
4
+ "buildDate": "2026-05-18T18:59:24Z",
5
5
  "platforms": {
6
6
  "darwin-arm64": {
7
7
  "binary": "claude.zst",
8
- "checksum": "de2803764796c6b908c203b330c4aa152be67291b85afb11777a9705b9f3133a",
9
- "size": 42998050,
8
+ "checksum": "ee45631e54620b1493a186c3f68737a586bb9743e8bedd7d40d663ef1488ef72",
9
+ "size": 43055466,
10
10
  "bundle": {
11
- "checksum": "ed3695422acd6338ab038aa0964b00c98d6e2cd0b17bb5b482d5f66082294038",
12
- "size": 43008215
11
+ "checksum": "ca17f3dffb8230ec6ccedf35bec149e9ab3a616509d2bc55ae90ed84f88d13e3",
12
+ "size": 43067561
13
13
  }
14
14
  },
15
15
  "darwin-x64": {
16
16
  "binary": "claude.zst",
17
- "checksum": "e0c65fc323f611df3d5093f8f21494a6f811f39de7f28bf93b552902f1fe9abf",
18
- "size": 44914712,
17
+ "checksum": "d4023e18885bda3f0edea593cabe97f1d71912b8f3d1daeebb28551fdca2ccb1",
18
+ "size": 44977785,
19
19
  "bundle": {
20
- "checksum": "f89d54e92a526eab1c1441ad716941c8c20462809d692ae5a03d29fc475913e6",
21
- "size": 44916790
20
+ "checksum": "0c04c6b629f308b19e1f4048c37fd6705c8e75c236e8f9350b8b20449f06eb1a",
21
+ "size": 44989436
22
22
  }
23
23
  },
24
24
  "linux-arm64": {
25
25
  "binary": "claude.zst",
26
- "checksum": "81e45b0efc7cf75298912cbcf953d366f1937c7573fbc3457508cb9022c21bb1",
27
- "size": 50768400
26
+ "checksum": "9e1043902191323aa6e2798d6810028241d8ca166d52133e0565a1cb9b3e2f58",
27
+ "size": 50842663
28
28
  },
29
29
  "linux-x64": {
30
30
  "binary": "claude.zst",
31
- "checksum": "6cbd2d23d9b6f8e06f8a1614f5212d13ae3b1c748b6b59df90157575b3e4f8a1",
32
- "size": 51405057
31
+ "checksum": "11faccc6f4fc49184d8e4a847eb2feb7cda225722395f47cd6b61a93751f3edc",
32
+ "size": 51470721
33
33
  },
34
34
  "linux-arm64-musl": {
35
35
  "binary": "claude.zst",
36
- "checksum": "53b68f1d98c2e24c100f5fc7e873cad7f0470af69c751cd5917460402277fb2f",
37
- "size": 49422676
36
+ "checksum": "f9c4091a1ba8664c20c1e6f77e99a5a76e772e2a1ca5bf217f88567fbb29fb0e",
37
+ "size": 49480624
38
38
  },
39
39
  "linux-x64-musl": {
40
40
  "binary": "claude.zst",
41
- "checksum": "fe24a7fa385ade60594375ec9fada75060bf028d6562b84461f4dd1b13abc521",
42
- "size": 50119926
41
+ "checksum": "4a9a7daa9ff2e36e476196ecc07c305c3e68f36af5dad1a0decdd158525ff204",
42
+ "size": 50191473
43
43
  },
44
44
  "win32-x64": {
45
45
  "binary": "claude.exe.zst",
46
- "checksum": "f1070448e53ffdd83f65b2773bffa2e1136d462e2f3be72cff0f4effd0611ac4",
47
- "size": 52123091
46
+ "checksum": "09ace0211e4eb689df96fca870421a7674ffb15876f1fdb8f887e397141778d1",
47
+ "size": 52206852
48
48
  },
49
49
  "win32-arm64": {
50
50
  "binary": "claude.exe.zst",
51
- "checksum": "967b9e021cdc470d10478e5ff8cfe93624337a7475478658954f275489d28adb",
52
- "size": 50393488
51
+ "checksum": "c061d3098ee1a261375347ffd2350d64d2b8a23a220b68ce3214ebe679395434",
52
+ "size": 50477031
53
53
  }
54
54
  }
55
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.3.143",
3
+ "version": "0.3.144",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "exports": {
@@ -8,6 +8,10 @@
8
8
  "types": "./sdk.d.ts",
9
9
  "default": "./sdk.mjs"
10
10
  },
11
+ "./extract": {
12
+ "types": "./extractFromBunfs.d.ts",
13
+ "default": "./extractFromBunfs.js"
14
+ },
11
15
  "./browser": {
12
16
  "types": "./browser-sdk.d.ts",
13
17
  "default": "./browser-sdk.js"
@@ -35,6 +39,10 @@
35
39
  "license": "SEE LICENSE IN README.md",
36
40
  "description": "SDK for building AI agents with Claude Code's capabilities. Programmatically interact with Claude to build autonomous agents that can understand codebases, edit files, and execute workflows.",
37
41
  "homepage": "https://github.com/anthropics/claude-agent-sdk-typescript",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/anthropics/claude-agent-sdk-typescript.git"
45
+ },
38
46
  "bugs": {
39
47
  "url": "https://github.com/anthropics/claude-agent-sdk-typescript/issues"
40
48
  },
@@ -53,14 +61,14 @@
53
61
  "zod": "^4.0.0"
54
62
  },
55
63
  "optionalDependencies": {
56
- "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.143",
57
- "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.143",
58
- "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.143",
59
- "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.143",
60
- "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.143",
61
- "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.143",
62
- "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.143",
63
- "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.143"
64
+ "@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.144",
65
+ "@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.144",
66
+ "@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.144",
67
+ "@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.144",
68
+ "@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.144",
69
+ "@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.144",
70
+ "@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.144",
71
+ "@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.144"
64
72
  },
65
73
  "files": [
66
74
  "sdk.mjs",
@@ -73,8 +81,10 @@
73
81
  "assistant.d.ts",
74
82
  "browser-sdk.js",
75
83
  "browser-sdk.d.ts",
84
+ "extractFromBunfs.js",
85
+ "extractFromBunfs.d.ts",
76
86
  "manifest.json",
77
87
  "manifest.zst.json"
78
88
  ],
79
- "claudeCodeVersion": "2.1.143"
89
+ "claudeCodeVersion": "2.1.144"
80
90
  }
package/sdk.d.ts CHANGED
@@ -2505,7 +2505,7 @@ export declare type SDKAssistantMessage = {
2505
2505
  task_description?: string;
2506
2506
  };
2507
2507
 
2508
- export declare type SDKAssistantMessageError = 'authentication_failed' | 'oauth_org_not_allowed' | 'billing_error' | 'rate_limit' | 'invalid_request' | 'server_error' | 'unknown' | 'max_output_tokens';
2508
+ export declare type SDKAssistantMessageError = 'authentication_failed' | 'oauth_org_not_allowed' | 'billing_error' | 'rate_limit' | 'invalid_request' | 'model_not_found' | 'server_error' | 'unknown' | 'max_output_tokens';
2509
2509
 
2510
2510
  export declare type SDKAuthStatusMessage = {
2511
2511
  type: 'auth_status';
@@ -3687,7 +3687,7 @@ export declare type SessionMessage = {
3687
3687
  uuid: string;
3688
3688
  session_id: string;
3689
3689
  message: unknown;
3690
- parent_tool_use_id: null;
3690
+ parent_tool_use_id: string | null;
3691
3691
  };
3692
3692
 
3693
3693
  /**