anthropics / anthropics/claude-agent-sdk-typescript
Query.interrupt() after system/init segfaults claude.exe on Windows (0xC0000005)
- Vorherrschende Sprache
- Shell
- Sterne
- 1.8k
- Forks
- 226
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
## Summary
On **Windows (win32-x64)**, calling `Query.interrupt()` immediately after receiving a `system`/`init` message during a streaming `query()` session causes the bundled `claude.exe` subprocess to exit with code **3221225477** (`0xC0000005`, `STATUS_ACCESS_VIOLATION`).
The same sequence works on **macOS** — the subprocess survives, the turn resolves with a terminal `result`, and the session remains reusable.
This breaks host applications that use **abort-after-init** warm-up: pre-spawn the CLI, push a minimal priming user message, drain to `init` (paying subprocess spawn + MCP connect cost), then `interrupt()` before the model answers so the first real user turn reuses the warm session.
## Environment
- OS: Windows 11 (x64)
- `@anthropic-ai/claude-agent-sdk`: 0.2.120 (also observed on nearby versions)
- `@anthropic-ai/claude-agent-sdk-win32-x64`: 0.2.120
- Claude Code CLI bundled with SDK: 2.1.120
- Host: Electron main process spawning SDK via TypeScript SDK `query()` with streaming `AsyncIterable` prompt
## Steps to reproduce
1. On Windows, create a persistent streaming `query({ prompt: asyncIterable, options })` session (same pattern as multi-turn chat hosts).
2. Push a minimal user message (e.g. warmup`) into the prompt iterable.
3. Drain messages until `type: system, subtype: init` arrives (~6s — subprocess spawn + MCP init).
4. Call `await query.interrupt()`.
5. Continue draining (or observe subprocess exit).
## Expected
- Subprocess survives
- Turn resolves with a terminal `result` message
- Session stays open for the next user turn (turn 2 skips cold init)
## Actual
- `claude.exe` exits with code **3221225477** (`0xC0000005`)
- Stdin write fails with EOF
- Session is dead; host warm-up fails
Example log lines from host:
```
CLI stdin error: write EOF
CLI subprocess exited (code=3221225477, signal=null)
warm-up failed: Claude Code process exited with code 3221225477
```
## A/B confirmation
| Variant | Windows warm-up |
|---------|-----------------|
| **With** `interrupt()` after `init` | Fails (segfault) |
| **Without** `interrupt()` — drain priming turn to natural `result` | Succeeds; first real turn reuses session |
Timing: warm session spawned, MCP init completes, crash occurs at interrupt (~13s after spawn in one trace) — not at spawn.
## Impact
Any Windows host using `Query.interrupt()` for session-preserving mid-turn stop (warm-up, deferred delegation short-circuit, etc.) may hit this. Hosts currently platform-gate warm-up to skip interrupt on Windows and accept a full priming model turn instead.
## Related
- Same exit code appears in various Windows `claude-code` issues (general AV crashes, ARM64 binary mismatch, etc.) — this report is specifically **`interrupt()` immediately after `init` in Agent SDK streaming mode**.
- Python SDK #1153 covers interrupt *ignored* when called too early (race) — different failure mode (no segfault).
## Request
Please investigate why `interrupt()` after `init` segfaults win32 `claude.exe` and fix so Windows matches macOS behavior (session-preserving interrupt with terminal `result`).
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.