VS Code extension: Read/Write/Edit fail with "The user doesn't want to take this action right now" after the extension's control stream closes (no user action)
Version: Claude Code VS Code extension 2.1.281 (bundled CLI), Linux (code-server).
What happens
The extension registers SDK PreToolUse hooks for Edit|Write|Read. When its control stream closes (chat panel or session closed while a background agent keeps running in the CLI process), every later Read/Write/Edit fails immediately (under 1 s) with:
The user doesn't want to take this action right now. STOP what you are doing and wait for the user to tell you how to proceed.
The tool result carries toolDenialKind: "cancelled". Internally the hook callback throws "Stream closed", the hook run reports "PreToolUse hook cancelled (control stream closed)", and that is mapped to the generic user-rejection text. The user did nothing. Bash, Grep and Glob are unaffected (no hook). The tool call is lost, and the model is falsely told that the user declined. In our logs the model usually continued in the same turn (83 of 83 cases on one workspace), but without the file content and with a wrong statement about the user in the transcript.
Observed: 86 cases in 14 days across 3 workspaces, 85 of them Read/Write/Edit, 72 inside background agents (sidechains), 58 under 1 s.
Reproduction
- Run
claude -p --input-format stream-json --output-format stream-jsonand register an SDK PreToolUse hook with matcherEdit|Write|Readover the control protocol, the same way the extension does. - Ask the model to run one Bash command and then read a file.
- Close the input/control stream after the Bash call.
- The Read fails after about 0 ms with the text above and
toolDenialKind: "cancelled". With the stream open, the same Read succeeds.
A real user interrupt looks different: it ends the turn and returns "doesn't want to proceed" with error_during_execution.
Expected If the control stream for an SDK hook is closed, do not report a user rejection. Either skip the hook (fail open, as for a hook that is no longer registered) or return a distinct, truthful error such as "PreToolUse hook unavailable: control stream closed", so the agent can continue or retry. Ideally the extension deregisters its hooks when its panel closes.
Same root cause outside the extension: a headless host (claude --print --input-format stream-json --output-format stream-json) that registers a PreToolUse hook callback and then dies mid-turn (OOM kill or crash). Claude Code 2.1.281, linux-arm64.
- Hooks matched every tool, so Bash is affected too, not only Read/Write/Edit.
- In our case the model did not continue. It ended the turn with "Stopped as you asked", and on a later
--resumethe false refusal is part of the history, so the resumed agent believes the user told it to stop. One host crash made 4 concurrent sessions each record that.
Minimal repro (no MCP, no settings): spawn with --tools Bash --setting-sources "" --permission-mode default, send initialize with a PreToolUse hook callback, ask for two sequential Bash calls, answer the first hook_callback with permissionDecision: "allow", then close stdin 1 s later:
2.08s tool_use Bash {"command": "sleep 4; echo first", ...}
2.09s host <- hook_callback #1 PreToolUse
2.09s host -> allow #1, then CLOSE STDIN in 1s
6.21s tool_result is_error=False : 'first'
7.06s tool_use Bash {"command": "echo second", ...}
7.07s tool_result is_error=True : "The user doesn't want to take this action right now. STOP what you are doing and wait for the user to tell you how to proceed."
8.53s assistant text: "The first command printed `first`. The second command (`echo second`) was denied, so I've stopped ..."
The host never receives a second hook_callback. SIGKILLing the host instead of closing stdin gives the same result.
Suggestions, least invasive first:
- A neutral tool_result for the stream-closed PreToolUse outcome, in the style of the existing "[Tool call interrupted: the session ended before this call's result was recorded ...]".
- Do not default to the user-rejection text when the turn was not aborted by the user.
- Once input is closed and the session depends on host callbacks (SDK hooks or
--permission-prompt-tool stdio), end the turn with a shutdown reason instead of running tools that can no longer be authorized.