-
Notifications
You must be signed in to change notification settings - Fork 613
Description
Bug Description
Since upgrading to claude-agent-sdk v0.1.29+, every tool call produces noisy Error in hook callback hook_0: Stream closed errors in the output. The errors are non-fatal (tools complete successfully and execution continues), but they spam the console with ~50 lines of minified Claude CLI source code per tool call, making logs unreadable.
Environment
- claude-agent-sdk: 0.1.31 (also reproduces on 0.1.29 and 0.1.30)
- Python: 3.12
- Platform: Ubuntu 24.04 (Linux 6.14.0)
- Claude CLI bundled version: 2.1.33 (v0.1.31), 2.1.31 (v0.1.29)
- Permission mode:
bypassPermissions - Usage: Programmatic agent via `query()` with `ClaudeAgentOptions(allowed_tools=[...], permission_mode="bypassPermissions")`
Steps to Reproduce
- Install `claude-agent-sdk>=0.1.29`
- Run any agent query using `bypassPermissions` mode
- Observe every tool call (Read, Glob, Grep, Bash, etc.) produces the error
Error Output (per tool call)
[claude 10:58:16] Using tool: Read → CLAUDE.md
Error in hook callback hook_0: 6339 | Claude Code has been suspended...
...~50 lines of minified CLI source code...
6344 | `)}async sendRequest(H,$,A){...if(this.inputClosed)throw Error("Stream closed")...
error: Stream closed
at sendRequest (/$bunfs/root/claude:6344:133)
at sendRequest (/$bunfs/root/claude:6344:627)
at <anonymous> (/$bunfs/root/claude:6344:1305)
at callback (/$bunfs/root/claude:6344:1451)
at _U1 (/$bunfs/root/claude:3151:1288)
at _U1 (/$bunfs/root/claude:3151:1525)
at <anonymous> (/$bunfs/root/claude:3144:1239)
[claude 10:58:16] Tool completed ← tool still succeeds
This repeats for every single tool call in a session. A typical planning phase with 20+ tool calls produces hundreds of lines of error output.
Root Cause Analysis
v0.1.29 introduced new hook event types:
- `SubagentStop`
- `Notification`
- `PermissionRequest`
The error appears to originate from the parent process's hook callback trying to handle permission requests via `sendRequest` over a stream that's closed or not applicable when `bypassPermissions` mode is active. The hook fires, fails to communicate over the stream, throws `Stream closed`, but execution continues because permissions are bypassed.
The minified source visible in the error includes the `SubagentStop` hook handling code:
hookEvent==="Stop"||hookEvent==="SubagentStop"Workaround
Pinning to `claude-agent-sdk<0.1.29` (v0.1.28, CLI v2.1.30) eliminates the errors entirely.
Expected Behavior
Tool calls in `bypassPermissions` mode should not trigger hook callbacks that attempt stream communication, or the errors should be silently caught rather than dumped to stderr with minified source code.
Impact
- Console output is unreadable during agent execution
- Log files become bloated (each tool call adds ~50 lines of noise)
- Makes it difficult to debug actual issues in agent output
- Confusing for users who think the agent is crashing (it's not)