claude-agent-sdk 0.6.1 → 0.6.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74a467e8e7f814ad55325db2de60cee2bd1f7a8bd849945b28302cf7776db2b9
4
- data.tar.gz: b0c9dc121f7500f314ebe03ba77db2e16a112c60222a7e7d50ca68897d36af41
3
+ metadata.gz: 8044b53b9c1c89e75c789b94a1ca000bb4a4a6e94d380bef3ded209585517b29
4
+ data.tar.gz: a3effbef7a3cbf1faed47cecb6f69df37e17266eabae7e56a556855b85707c4f
5
5
  SHA512:
6
- metadata.gz: 5c6b145098e0e8489838f4d9b6e1a3f0af50a18e20a15055497fca65c1922e6f0e556bfb1e1844720989b81811eaf50d1605392d4d6bbf500fe367cbd744c172
7
- data.tar.gz: 7ca8630977ebe60f00d8592c993d80eab1cc9754a1190dbd579b239a6f8ee105c48bbf3e5fe3b1aaa3da26c6ea62f369ee00d040d48eab002253f27aecee26a5
6
+ metadata.gz: 3c9360caa6e3fc1ffa7d359e4d2195aecf003e1fc37655bfe15355efc2dce3cfd896f30a0b7bdc504a88d90056bab05b7ad2a90c33f0ad03867abcaf0ccb16a7
7
+ data.tar.gz: 68059199d80d3f10ff03b18b6fbb505348070f8a1a53d8d00cd56550fdfe7c337a4b53d39d7e41d0238c954dd2106656c6f8eaf6e39b5ac516278ac4c7c57ff4
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.6.2] - 2026-02-17
9
+
10
+ ### Fixed
11
+ - **Large prompt `Errno::E2BIG` crash:** Prompts exceeding 200KB are now piped via stdin instead of passed as CLI arguments, avoiding the OS `ARG_MAX` limit (typically 1MB on macOS/Linux). This fixes `CLIConnectionError: Failed to start Claude Code: Argument list too long` when using `query()` with large prompts.
12
+ - **Stderr pipe deadlock (`Errno::EPIPE`):** Always drain stderr in a background thread, even when `stderr` option is not set. Without this, `--verbose` output fills the 64KB OS pipe buffer, the subprocess blocks on write, and all pipes stall. Previously only manifested with long-running Opus sessions.
13
+
8
14
  ## [0.6.0] - 2026-02-13
9
15
 
10
16
  ### Added
@@ -13,6 +13,11 @@ module ClaudeAgentSDK
13
13
  DEFAULT_MAX_BUFFER_SIZE = 1024 * 1024 # 1MB buffer limit
14
14
  MINIMUM_CLAUDE_CODE_VERSION = '2.0.0'
15
15
 
16
+ # Prompts larger than this are piped via stdin instead of CLI args
17
+ # to avoid Errno::E2BIG (ARG_MAX is typically 1MB on macOS/Linux,
18
+ # shared with environment variables).
19
+ PROMPT_STDIN_THRESHOLD = 200 * 1024 # 200KB
20
+
16
21
  def initialize(prompt, options)
17
22
  @prompt = prompt
18
23
  @is_streaming = !prompt.is_a?(String)
@@ -27,6 +32,7 @@ module ClaudeAgentSDK
27
32
  @exit_error = nil
28
33
  @max_buffer_size = options.max_buffer_size || DEFAULT_MAX_BUFFER_SIZE
29
34
  @stderr_task = nil
35
+ @pipe_prompt_via_stdin = false
30
36
  end
31
37
 
32
38
  def find_cli
@@ -245,6 +251,11 @@ module ClaudeAgentSDK
245
251
  # Prompt handling
246
252
  if @is_streaming
247
253
  cmd.concat(['--input-format', 'stream-json'])
254
+ elsif @prompt.to_s.bytesize > PROMPT_STDIN_THRESHOLD
255
+ # Large prompts are piped via stdin to avoid OS argument size limits.
256
+ # Claude CLI reads from stdin when --print is used without a trailing argument.
257
+ cmd << '--print'
258
+ @pipe_prompt_via_stdin = true
248
259
  else
249
260
  cmd.concat(['--print', '--', @prompt.to_s])
250
261
  end
@@ -277,15 +288,32 @@ module ClaudeAgentSDK
277
288
 
278
289
  @stdin, @stdout, @stderr, @process = Open3.popen3(process_env, *cmd, opts)
279
290
 
280
- # Handle stderr if piped
281
- if should_pipe_stderr && @stderr
282
- @stderr_task = Thread.new do
283
- handle_stderr
284
- rescue StandardError
285
- # Ignore errors during stderr reading
291
+ # Always drain stderr to prevent pipe buffer deadlock.
292
+ # Without this, --verbose output fills the OS pipe buffer (~64KB),
293
+ # the subprocess blocks on write, and all pipes stall → EPIPE.
294
+ if @stderr
295
+ if should_pipe_stderr
296
+ @stderr_task = Thread.new do
297
+ handle_stderr
298
+ rescue StandardError
299
+ # Ignore errors during stderr reading
300
+ end
301
+ else
302
+ # Silently drain stderr so the subprocess never blocks
303
+ @stderr_task = Thread.new do
304
+ @stderr.each_line { |_| } # discard
305
+ rescue StandardError
306
+ # Ignore — process may have already exited
307
+ end
286
308
  end
287
309
  end
288
310
 
311
+ # For large prompts, pipe the prompt text to stdin before closing.
312
+ # This avoids Errno::E2BIG when the prompt exceeds ARG_MAX.
313
+ if @pipe_prompt_via_stdin && @stdin
314
+ @stdin.write(@prompt.to_s)
315
+ end
316
+
289
317
  # Close stdin for non-streaming mode
290
318
  @stdin.close unless @is_streaming
291
319
  @stdin = nil unless @is_streaming
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClaudeAgentSDK
4
- VERSION = '0.6.1'
4
+ VERSION = '0.6.2'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: claude-agent-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Community Contributors
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-02-15 00:00:00.000000000 Z
10
+ date: 2026-02-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: async