fix: update to @anthropic-ai/claude-agent-sdk 0.3.328 (#1668)

## Summary

Updates `@anthropic-ai/claude-agent-sdk` from 0.3.326 to 0.3.328, which
bundles Claude Code 2.1.328. The new version needs one adapter fix,
included here: a session's settings are released when the SDK refuses
the session's options.

Also bumps these dev dependencies: `@anthropic-ai/sdk` 1.9.0 → 1.10.0
and `vitest` 5.1.0 → 5.1.1.

`npm update` brings the in-range lockfile bumps: `express-rate-limit`
8.7.4 → 8.7.5, `jose` 6.2.17 → 6.2.18, `object-inspect` 1.13.4 → 1.14.0,
`standardwebhooks` 1.1.1 → 1.3.0, `source-map-js` 1.2.2 → 1.2.3 and
`tinybench` 6.2.3 → 6.2.4.

TypeScript stays at 6.0.3: 7.0.2 is out, but `@typescript-eslint/parser`
8.73.0 still requires `typescript <6.1.0`.

## Options that the SDK refuses

SDK 0.3.327 has a breaking change: `query()` refuses options that it
cannot send to Claude Code, and it does so by throwing at once. Recorded
with the real SDK for `hooks: { PreToolUse: [{ matcher: "Bash" }] }`, a
matcher without `hooks`:

- 0.3.326: `query()` returns, and `initializationResult()` rejects with
"a.hooks is not iterable".
- 0.3.328: `query()` throws "The session was not started, because the
hooks option can't be sent to Claude Code: hooks.PreToolUse[0].hooks
must be an array of callbacks. Fix that value and try again."

Both cores disposed the settings of a session that fails to start (the
`SettingsManager` and its file watchers) only when
`initializationResult()` rejected. A `query()` that throws skipped that,
and v1 also left the session's input open. Both cores now release them
there too. On v1, `discardUnregisteredQuery` does it, and takes no query
for this case.

What changes for a client:

- The error for such options is still `-32603`, now with the SDK's
message in `data.details`. Checked through the built adapter on v1 and
v2. The adapter serves the next request as before.
- **The SDK is stricter.** `hooks` with an event that is no list of
matchers, such as `{ "SessionStart": { … } }`, started a session on
0.3.326. It is refused now ("hooks.SessionStart must be an array of
matchers"), for the events that the adapter adds no hooks of its own to.

## Changelog review

Read the SDK changelog for 0.3.327 and 0.3.328 and the Claude Code
changelog for 2.1.327 and 2.1.328. No other entry needs a code change:

- **Types.** Doc text and new optional members, plus one new
`SDKStartupFailureReason` (`initialize_fields_not_delivered`).
`startupFailureError` treats a reason it does not list as an internal
error with the CLI's message.
- **`task_started` has no `prompt` when Claude Code wakes a background
subagent with text of its own**, such as a task notification. Both cores
start a run without a prompt then (`promptText` in
`src/native-subagents.ts`, `startRun` in `src/v2/tasks.ts`), so the
child's session no longer gets that text as a prompt.
- **The error for usage credits that run out mid-response** no longer
names a rate limit. The adapter takes the failure kind from the SDK's
`error` field, not from the text.
- **More calls ask for permission:** `ExitWorktree` for a worktree that
may hold unsaved work, some paths and symbolic links, and a subagent
that a sibling's message resumed. They reach `canUseTool` as any other
request.
- **`agent` and `agents` fixes** (an inline definition wins over one of
the same name, `--agents` survive a plugin reload). Picked up as they
are: the adapter passes a client's `agents` on.
- **"Background agents still running" after an interrupt, and after a
permission request that waited 30 seconds.** Picked up as they are.
- **`CLAUDE_CODE_DISABLE_DEFERRED_TOOL_RESUME`** and
**`CLAUDE_CODE_DISABLE_SHELL_HEAD_START`.** The adapter sets neither, so
it keeps Claude Code's defaults.
- **`getSessionInfo` and `listSessions`** read a transcript as before: a
differential run of 0.3.326 against 0.3.328 over 4,500 generated
transcripts gave no mismatch. The run is not part of this PR.
- **`@anthropic-ai/sdk` 1.10.0.** The adapter uses its types only. The
release adds API error codes and fixes tool runners that the adapter
does not use.
- **`vitest` 5.1.1.** Bug fixes.

## Not in this PR

- A throw of the adapter's own between the settings read and `query()`
still skips the dispose. Example: a client's `hooks.PostToolUse` that is
an object, which the adapter's own merge of the hooks cannot spread.
- `-32602` for options that the SDK refuses. The code is `-32603`, as it
was for these requests before.

## Testing

- `npm run build`, `npm run check`, `npm run test:run` (4,369 tests
pass)
- Each core has a test with a `query()` that throws the SDK's refusal.
Both fail without the fix.
- Real CLI: the integration tests (`RUN_INTEGRATION_TESTS=true`, with
`CLAUDE_CODE_ENTRYPOINT` unset), 941 tests pass, and one that the test
file itself skips
- Real SDK and CLI, without a prompt: the two `hooks` cases above with
0.3.326 and 0.3.328, and through the built adapter on v1 and v2
This commit is contained in:
Ben Brandt
2026-11-19 13:53:15 +01:00
committed by GitHub
parent f31da7f9f5
commit 6e307116d4
6 changed files with 164 additions and 89 deletions

156
package-lock.json generated
View File

@@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@agentclientprotocol/sdk": "2.8.0",
"@anthropic-ai/claude-agent-sdk": "0.3.326",
"@anthropic-ai/claude-agent-sdk": "0.3.328",
"diff": "9.0.0",
"zod": "4.6.7"
},
@@ -18,7 +18,7 @@
"claude-agent-acp": "dist/index.js"
},
"devDependencies": {
"@anthropic-ai/sdk": "1.9.0",
"@anthropic-ai/sdk": "1.10.0",
"@eslint/js": "10.0.1",
"@tsconfig/node22": "22.0.7",
"@types/node": "26.6.6",
@@ -31,7 +31,7 @@
"globals": "17.14.0",
"prettier": "3.10.1",
"typescript": "6.0.3",
"vitest": "5.1.0"
"vitest": "5.1.1"
},
"engines": {
"node": ">=22"
@@ -53,22 +53,22 @@
}
},
"node_modules/@anthropic-ai/claude-agent-sdk": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk/-/claude-agent-sdk-0.3.326.tgz",
"integrity": "sha512-BUTSky/4YWfL/MxC+4kV0NDbJFjbJPoQMFEk/s9G6hV9LUfYPMbsWz94bFQ7ZIo2ubj2xwJ2c2NVxkNlQhVw+Q==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk/-/claude-agent-sdk-0.3.328.tgz",
"integrity": "sha512-YcOWlpXVm7etPjPVrvSJEfynDksMiG11zvEybSBnk1EVWji6rSjU75HbbhJ8XPEB2ECEwRRP597Udu6IWMtsDw==",
"license": "SEE LICENSE IN README.md",
"engines": {
"node": ">=18.14.0"
},
"optionalDependencies": {
"@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.326",
"@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.326",
"@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.326",
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.326",
"@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.326",
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.326",
"@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.326",
"@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.326"
"@anthropic-ai/claude-agent-sdk-darwin-arm64": "0.3.328",
"@anthropic-ai/claude-agent-sdk-darwin-x64": "0.3.328",
"@anthropic-ai/claude-agent-sdk-linux-arm64": "0.3.328",
"@anthropic-ai/claude-agent-sdk-linux-arm64-musl": "0.3.328",
"@anthropic-ai/claude-agent-sdk-linux-x64": "0.3.328",
"@anthropic-ai/claude-agent-sdk-linux-x64-musl": "0.3.328",
"@anthropic-ai/claude-agent-sdk-win32-arm64": "0.3.328",
"@anthropic-ai/claude-agent-sdk-win32-x64": "0.3.328"
},
"peerDependencies": {
"@anthropic-ai/sdk": ">=0.93.0",
@@ -77,9 +77,9 @@
}
},
"node_modules/@anthropic-ai/claude-agent-sdk-darwin-arm64": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-arm64/-/claude-agent-sdk-darwin-arm64-0.3.326.tgz",
"integrity": "sha512-D3ZbowCMdKNet0YPZlsJxdJUW1t1Q8KLy1BwNd+5eilf18TlCRtWZlm8DrewFLmu/gxBK7gcsq6uysrIVbPyQg==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-arm64/-/claude-agent-sdk-darwin-arm64-0.3.328.tgz",
"integrity": "sha512-vjBASSSZFNs5M84XONCM4xAJMKPD0E9RtF0UDQ/a1Qqt5L+slNxhSADkH5n0tEM5HJMK7j9DCPi+0FVOBpZr3w==",
"cpu": [
"arm64"
],
@@ -90,9 +90,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-darwin-x64": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-x64/-/claude-agent-sdk-darwin-x64-0.3.326.tgz",
"integrity": "sha512-m8K3Im2S8STdAVBrriuDZyJcnjsu/Vc3476wIOqTAefnCCdtdZ4AHcOcWxt+4KIHE5Vx1qT2qacTRrQBaVVweA==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-x64/-/claude-agent-sdk-darwin-x64-0.3.328.tgz",
"integrity": "sha512-pkZuDNi16H4yJFo6cS2sw8mFj7m7ESAxV74t2gQ9EFzZOpXbQoJqhPBHNEZJ2q/+kr/3vHUtRc2W6jURA6nS+A==",
"cpu": [
"x64"
],
@@ -103,9 +103,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-linux-arm64": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64/-/claude-agent-sdk-linux-arm64-0.3.326.tgz",
"integrity": "sha512-nYVN8jCcH490DCXIvby7rllzQFxLzKeKClfo2u/yv7mx3ipZQv344caULL/amwZ8w8GUzYyZ8hnS6pI9goSq+A==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64/-/claude-agent-sdk-linux-arm64-0.3.328.tgz",
"integrity": "sha512-VvsUzOEf7r3ZtOPfliNGxqknsIvxEmnUOtQnq4+uw7MsfiALKR4s0bx2SP32UuXpqbmqxR1gn456D27XgsAmnA==",
"cpu": [
"arm64"
],
@@ -119,9 +119,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-linux-arm64-musl": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64-musl/-/claude-agent-sdk-linux-arm64-musl-0.3.326.tgz",
"integrity": "sha512-baSsuP2/wuWujRpHjKT4WkJB5lhttqKq9jcTfY2KRtQpylbk8E5PWcct/pmwJfNCKIUoE8CD+JpmoWzsdd5Ajw==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64-musl/-/claude-agent-sdk-linux-arm64-musl-0.3.328.tgz",
"integrity": "sha512-4Vui26/OZwr8AU7FpAt+R5s/1AKmj5qDorUZIqF1MMfdjAQf8/ut/+HyEkuMom/MVF2JeQLdvnFFFmbfgmAq/g==",
"cpu": [
"arm64"
],
@@ -135,9 +135,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-linux-x64": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64/-/claude-agent-sdk-linux-x64-0.3.326.tgz",
"integrity": "sha512-WMhDY07gk2O0E8FXTbrVYmPjSLFaYPDCPwsNueVxm6vZ7ek+lPaKuOMAxTb1K07TzSmTOexoWeX2Y9VrbVDMpw==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64/-/claude-agent-sdk-linux-x64-0.3.328.tgz",
"integrity": "sha512-saP4fWgVZj1n7MYCqvTKADHXIc/hIAMRDpLVpXD5xB0IT68vhWgIMkzIrsg5P02P6zA49TDuoijbP1YBUEXT4A==",
"cpu": [
"x64"
],
@@ -151,9 +151,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-linux-x64-musl": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64-musl/-/claude-agent-sdk-linux-x64-musl-0.3.326.tgz",
"integrity": "sha512-kK9VO3uFqNd4wgeU0Cefluam5AdPu6mvF1nn6aboGy8TA5NoxlWTmA4/AwMhK39zK1S9Q2OjeX0JtAahYlIchw==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64-musl/-/claude-agent-sdk-linux-x64-musl-0.3.328.tgz",
"integrity": "sha512-oJowzzjhWGbdBGyRjqV9CT0nfh4A4/fEI11LjX6b1SkhrNNgy9QT2HzSe8A2yNlliOWo1xJl6nAHT8pLwMNlVg==",
"cpu": [
"x64"
],
@@ -167,9 +167,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-win32-arm64": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-arm64/-/claude-agent-sdk-win32-arm64-0.3.326.tgz",
"integrity": "sha512-S+Ai+HhGRVFfTDmYWRfTrdWF3b4KMsfLSThZCqRJ0WCOKOXrRShMKV1hqqHBljx/wkMDPCpY0V/9S/e6w57eGQ==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-arm64/-/claude-agent-sdk-win32-arm64-0.3.328.tgz",
"integrity": "sha512-FkqzA++c+giPH2k8svb0egWDiGDkvSLQJTp5bq7QFXOxPEael4ct1yjKit/Yu6Sd48uLEgNT1waBYbyApPzhOw==",
"cpu": [
"arm64"
],
@@ -180,9 +180,9 @@
]
},
"node_modules/@anthropic-ai/claude-agent-sdk-win32-x64": {
"version": "0.3.326",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-x64/-/claude-agent-sdk-win32-x64-0.3.326.tgz",
"integrity": "sha512-Yn1gZXYFuHmjHz7SpHx4TqDcRDsC8TfwWcntJdYjFzMWm+caPAp6QRqr/aTvirjqVA1D+D8Rd29xhuytpE3xTQ==",
"version": "0.3.328",
"resolved": "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-x64/-/claude-agent-sdk-win32-x64-0.3.328.tgz",
"integrity": "sha512-9Wd0XrZ0QWkgtcKxObcYDvUpQjUzN3Uq4Chbvu1SOWOoKPfQdD40dwRQMCeKx2KGxAfMrggJ7I3JYnvRWAFYjg==",
"cpu": [
"x64"
],
@@ -193,9 +193,9 @@
]
},
"node_modules/@anthropic-ai/sdk": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-1.9.0.tgz",
"integrity": "sha512-xDu4za3B+rK+5ZI8wLLoosiIuwi1ktZk/3L3KKNahwO50O34H+622hly8JdXzaEerLQDhsqwVzp81Nrw80BYHg==",
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-1.10.0.tgz",
"integrity": "sha512-j4uVct5p3aGIz/BU4K8VU5vt2A6AueHTvx2gfF3xr4mVpwH9IJMWEAUKNwSwdZSJOHQq1Za2tv5huYc5v02D0w==",
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api": "^1.4.1",
@@ -1251,16 +1251,16 @@
}
},
"node_modules/@vitest/mocker": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.0.tgz",
"integrity": "sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ==",
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.1.tgz",
"integrity": "sha512-b2OgTB4+3ImWIVafXKazJXwLKwQxUNnix6b3xUvUTMh7RyXlrtzoxfZr8aEz9zkHOMAS4K5lu3TvFWoiVeVTQg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/trace-mapping": "0.3.31",
"@vitest/spy": "5.1.0",
"@vitest/spy": "5.1.1",
"estree-walker": "^3.0.3",
"magic-string": "^1.4.3"
"magic-string": "^1.4.5"
},
"funding": {
"url": "https://opencollective.com/vitest"
@@ -1279,9 +1279,9 @@
}
},
"node_modules/@vitest/spy": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.0.tgz",
"integrity": "sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A==",
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.1.tgz",
"integrity": "sha512-6K8C6alQG1/Yc8/ZI22iJS7JEsxPdVzqtqDq+/xM4Z0mGVykemMVjLhqMy/q6/IHYG3kKD8hKSwRen/ZdyI9vQ==",
"dev": true,
"license": "MIT",
"funding": {
@@ -2050,9 +2050,9 @@
}
},
"node_modules/express-rate-limit": {
"version": "8.7.4",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.4.tgz",
"integrity": "sha512-LKBXzX700wz3zAGNNmVnjRI5mEbYkLv7UbMI4+9Xa+JPcg2UZh6AgY/2CZh9RrJjFM5ttC/N1lD+KzyFoZITCw==",
"version": "8.7.5",
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.5.tgz",
"integrity": "sha512-wi+v38cx2EqD0JnhE/e74o5tFqKWUOAPFJIgyEiqJ8v2MNpoOAA3kI2hXYOI+YM+HE5yqbdAlVxm2GqOIeYOgA==",
"license": "MIT",
"peer": true,
"dependencies": {
@@ -2513,9 +2513,9 @@
"license": "ISC"
},
"node_modules/jose": {
"version": "6.2.17",
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.17.tgz",
"integrity": "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg==",
"version": "6.2.18",
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.18.tgz",
"integrity": "sha512-doV4thUwgkrycJH4yLeqwTGIIZphHl+pk7CPReuMIhYhncmgzdko85MaCG4YQFTxqMFr1/oEH32tZuKKovcDEg==",
"license": "MIT",
"peer": true,
"funding": {
@@ -3046,9 +3046,9 @@
}
},
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"version": "1.14.0",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz",
"integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==",
"license": "MIT",
"peer": true,
"engines": {
@@ -3609,9 +3609,9 @@
}
},
"node_modules/source-map-js": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz",
"integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==",
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.3.tgz",
"integrity": "sha512-xj+WrAkyv5Qp+t7r9N5HvCBu7g1qOe6CKRNpq22X1GGcPEQADFU54v5qsPVs3/vrUFQ7XivFrcAVKA2stI0kWA==",
"dev": true,
"license": "BSD-3-Clause",
"peer": true,
@@ -3620,9 +3620,9 @@
}
},
"node_modules/standardwebhooks": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/standardwebhooks/-/standardwebhooks-1.1.1.tgz",
"integrity": "sha512-bCbX9ZEyFkWPsRz7Bl3NuQUJohmwGSev/yhr7vhaGPlc4AfIrspIRa6cPTBuI1ItmrTDJ4d/S2hCsfe4+vQGnQ==",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/standardwebhooks/-/standardwebhooks-1.3.0.tgz",
"integrity": "sha512-5W9skHjqAm2dlA9wWvglTP+oX47JX4lFXVk1aJV7+TG1snvTR4QXaVgPscEzvOw9GRreeavMwbqEeL+MGhZHCg==",
"license": "MIT",
"dependencies": {
"@stablelib/base64": "^1.0.0",
@@ -3647,9 +3647,9 @@
"license": "MIT"
},
"node_modules/tinybench": {
"version": "6.2.3",
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.3.tgz",
"integrity": "sha512-Al01C2JIBnO2CXCAPbpAl6sUiOZHeThGtHYNTa51JRw9PyWOCdr+9Ong05R4qg/Sk3+H645E8ov1h2c58ityNw==",
"version": "6.2.4",
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.4.tgz",
"integrity": "sha512-SQ52jEncXxbMCzJuY2A/jGIbbAu6NYsBWW7grz2pNE+EnzQdoGaoBfpk4qC/opE7qiUcGmGgaGIz5EoHdS1O9w==",
"dev": true,
"license": "MIT",
"engines": {
@@ -3898,22 +3898,22 @@
}
},
"node_modules/vitest": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.0.tgz",
"integrity": "sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA==",
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.1.tgz",
"integrity": "sha512-trVmzUFOSraCZcI3uZIMD5FqBh4atFkC/XuJP/IU7qtyQay0FCs3Ia+0QiQ2JJwGyWG/xrcBoJNel2+O7kEZ0g==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/chai": "^5.2.2",
"@vitest/mocker": "5.1.0",
"@vitest/mocker": "5.1.1",
"chai": "^6.3.0",
"es-module-lexer": "^2.3.2",
"expect-type": "^1.4.0",
"magic-string": "^1.4.3",
"magic-string": "^1.4.5",
"obug": "^3.0.0",
"picomatch": "^4.0.7",
"std-env": "^4.3.0",
"tinybench": "^6.2.2",
"tinybench": "^6.2.3",
"tinyexec": "^1.3.1",
"tinyglobby": "^0.2.17",
"why-is-node-running": "3.2.1"
@@ -3931,12 +3931,12 @@
"@edge-runtime/vm": "*",
"@opentelemetry/api": "^1.9.0",
"@types/node": "^22.0.0 || >=24.0.0",
"@vitest/browser-playwright": "5.1.0",
"@vitest/browser-preview": "5.1.0",
"@vitest/browser-playwright": "5.1.1",
"@vitest/browser-preview": "5.1.1",
"@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0",
"@vitest/coverage-istanbul": "5.1.0",
"@vitest/coverage-v8": "5.1.0",
"@vitest/ui": "5.1.0",
"@vitest/coverage-istanbul": "5.1.1",
"@vitest/coverage-v8": "5.1.1",
"@vitest/ui": "5.1.1",
"happy-dom": "*",
"jsdom": "*",
"vite": "^6.4.0 || ^7.0.0 || ^8.0.0"

View File

@@ -69,12 +69,12 @@
},
"dependencies": {
"@agentclientprotocol/sdk": "2.8.0",
"@anthropic-ai/claude-agent-sdk": "0.3.326",
"@anthropic-ai/claude-agent-sdk": "0.3.328",
"diff": "9.0.0",
"zod": "4.6.7"
},
"devDependencies": {
"@anthropic-ai/sdk": "1.9.0",
"@anthropic-ai/sdk": "1.10.0",
"@eslint/js": "10.0.1",
"@tsconfig/node22": "22.0.7",
"@types/node": "26.6.6",
@@ -87,6 +87,6 @@
"globals": "17.14.0",
"prettier": "3.10.1",
"typescript": "6.0.3",
"vitest": "5.1.0"
"vitest": "5.1.1"
}
}

View File

@@ -28,6 +28,8 @@ let initModels: Record<string, unknown>[] | undefined;
/** Holds the CLI initialization until the test resolves it. */
let initGate: Promise<void> | undefined;
let initError: Error | undefined;
/** When set, the SDK refuses the query's options with it: `query()` throws. */
let optionsRefusal: Error | undefined;
let setModelImpl: ((model: string) => Promise<void>) | undefined;
let interruptImpl: (() => Promise<undefined>) | undefined;
let closeSpy: ReturnType<typeof vi.fn<() => void>>;
@@ -45,6 +47,7 @@ vi.mock("@anthropic-ai/claude-agent-sdk", async () => {
return {
...actual,
query: (args: { prompt: unknown; options: Options }) => {
if (optionsRefusal) throw optionsRefusal;
capturedOptions = args.options;
// Like Claude Code's, the stream stays open until the query is closed.
let streamClosed = () => {};
@@ -123,6 +126,7 @@ describe("createSession options merging", () => {
initModels = undefined;
initGate = undefined;
initError = undefined;
optionsRefusal = undefined;
setModelImpl = undefined;
interruptImpl = undefined;
closeSpy = vi.fn<() => void>();
@@ -1747,6 +1751,27 @@ describe("createSession options merging", () => {
initError,
);
});
it("disposes the settings of a session whose options the SDK refuses", async () => {
// What SDK 0.3.328 throws from `query()` for a hook matcher without `hooks`.
optionsRefusal = new Error(
"The session was not started, because the hooks option can't be sent to Claude Code: " +
"hooks.PreToolUse[0].hooks must be an array of callbacks. Fix that value and try again.",
);
// The module that the agent of this test loaded (see `beforeEach`).
const { SettingsManager } = await import("../../settings.js");
const initialized = vi.spyOn(SettingsManager.prototype, "initialize");
const disposed = vi.spyOn(SettingsManager.prototype, "dispose");
await expect(agent.newSession({ cwd: process.cwd(), mcpServers: [] })).rejects.toBe(
optionsRefusal,
);
expect(initialized).toHaveBeenCalled();
expect(disposed).toHaveBeenCalledTimes(initialized.mock.calls.length);
initialized.mockRestore();
disposed.mockRestore();
});
});
describe("elicitation", () => {

View File

@@ -73,6 +73,8 @@ const sdk = vi.hoisted(() => ({
previewGate: undefined as Promise<void> | undefined,
/** When set, Claude Code fails to start with it. */
startFailure: undefined as Error | undefined,
/** When set, the SDK refuses the query's options with it: `query()` throws. */
optionsRefusal: undefined as Error | undefined,
/** When set, Claude Code's start waits for it. */
startGate: undefined as Promise<void> | undefined,
/** When set, the query serves Remote Control with it (`enableRemoteControl`). */
@@ -86,6 +88,7 @@ vi.mock("@anthropic-ai/claude-agent-sdk", async () => {
return {
...actual,
query: ({ prompt, options }: { prompt: AsyncIterable<SDKUserMessage>; options: Options }) => {
if (sdk.optionsRefusal) throw sdk.optionsRefusal;
const queue: Array<IteratorResult<Record<string, unknown>> | Error> = [];
let wake = () => {};
const prompts: SDKUserMessage[] = [];
@@ -219,6 +222,7 @@ beforeEach(async () => {
sdk.subagents = new Map();
sdk.previewGate = undefined;
sdk.startFailure = undefined;
sdk.optionsRefusal = undefined;
sdk.startGate = undefined;
sdk.enableRemoteControl = undefined;
vi.mocked(forkSession).mockClear();
@@ -3540,6 +3544,31 @@ describe("ACP v2 core", () => {
disposed.mockRestore();
});
it("disposes the settings of a session whose options the SDK refuses", async () => {
// What SDK 0.3.328 throws from `query()` for a hook matcher without `hooks`.
sdk.optionsRefusal = new Error(
"The session was not started, because the hooks option can't be sent to Claude Code: " +
"hooks.PreToolUse[0].hooks must be an array of callbacks. Fix that value and try again.",
);
const initialized = vi.spyOn(SettingsManager.prototype, "initialize");
const disposed = vi.spyOn(SettingsManager.prototype, "dispose");
const client = v2Client();
const error = await client.connect(async (agent) => {
await agent.request(v2.methods.agent.initialize, {
protocolVersion: v2.PROTOCOL_VERSION,
info: { name: "v2-test-client", version: "1.0.0" },
capabilities: {},
});
return agent.request(v2.methods.agent.session.new, { cwd }).catch((error: unknown) => error);
});
expect(error).toMatchObject({ data: { details: sdk.optionsRefusal.message } });
expect(initialized).toHaveBeenCalled();
expect(disposed).toHaveBeenCalledTimes(initialized.mock.calls.length);
initialized.mockRestore();
disposed.mockRestore();
});
describe("subagents and background work", () => {
it("announces a subagent before its traffic, and reports its runs on its own stream", async () => {
const client = v2Client();

View File

@@ -7743,16 +7743,18 @@ export class ClaudeAcpAgent {
}
}
/** Release a query that was spawned but never registered as a session. */
/** Release a query that was spawned but never registered as a session, or
* the settings and input of one that the SDK refused to create (`q` is
* undefined). */
private discardUnregisteredQuery(
q: Query,
q: Query | undefined,
input: Pushable<SDKUserMessage>,
settingsManager: SettingsManager,
): void {
settingsManager.dispose();
input.end();
try {
q.close();
q?.close();
} catch (error) {
this.logger.error("Failed to close unregistered Claude query", error);
}
@@ -10415,10 +10417,19 @@ export class ClaudeAcpAgent {
throw new Error("Cancelled");
}
const q = query({
prompt: input,
options,
});
let q: Query;
try {
q = query({
prompt: input,
options,
});
} catch (error) {
// The SDK refuses options that it cannot send to Claude Code, e.g. a
// client's hook matcher without `hooks`: "hooks.PreToolUse[0].hooks must
// be an array of callbacks".
this.discardUnregisteredQuery(undefined, input, settingsManager);
throw error;
}
this.authStatus.useSettings(
settingsManager,
configuredSettingsObject,

View File

@@ -26,6 +26,7 @@ import {
listSessions,
query,
type Options,
type Query,
type SDKUserMessage,
type SessionMessage,
} from "@anthropic-ai/claude-agent-sdk";
@@ -1175,7 +1176,16 @@ class V2Agent implements AgentHandle, SessionConnection {
...(resume !== undefined ? { resume } : { sessionId }),
...(persist ? {} : { persistSession: false }),
};
const q = query({ prompt: input, options });
let q: Query;
try {
q = query({ prompt: input, options });
} catch (error) {
// The SDK refuses options that it cannot send to Claude Code, e.g. a
// client's hook matcher without `hooks`: "hooks.PreToolUse[0].hooks must
// be an array of callbacks".
settings.dispose();
throw error;
}
let initialization;
try {
initialization = await q.initializationResult();