claude-agent-sdk 0.6.0 → 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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +20 -4
- data/lib/claude_agent_sdk/subprocess_cli_transport.rb +37 -7
- data/lib/claude_agent_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8044b53b9c1c89e75c789b94a1ca000bb4a4a6e94d380bef3ded209585517b29
|
|
4
|
+
data.tar.gz: a3effbef7a3cbf1faed47cecb6f69df37e17266eabae7e56a556855b85707c4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/README.md
CHANGED
|
@@ -996,15 +996,18 @@ end
|
|
|
996
996
|
# Base exception class for all SDK errors
|
|
997
997
|
class ClaudeSDKError < StandardError; end
|
|
998
998
|
|
|
999
|
+
# Raised when connection to Claude Code fails
|
|
1000
|
+
class CLIConnectionError < ClaudeSDKError; end
|
|
1001
|
+
|
|
1002
|
+
# Raised when the control protocol does not respond in time
|
|
1003
|
+
class ControlRequestTimeoutError < CLIConnectionError; end
|
|
1004
|
+
|
|
999
1005
|
# Raised when Claude Code CLI is not found
|
|
1000
1006
|
class CLINotFoundError < CLIConnectionError
|
|
1001
1007
|
# @param message [String] Error message (default: "Claude Code not found")
|
|
1002
1008
|
# @param cli_path [String, nil] Optional path to the CLI that was not found
|
|
1003
1009
|
end
|
|
1004
1010
|
|
|
1005
|
-
# Raised when connection to Claude Code fails
|
|
1006
|
-
class CLIConnectionError < ClaudeSDKError; end
|
|
1007
|
-
|
|
1008
1011
|
# Raised when the Claude Code process fails
|
|
1009
1012
|
class ProcessError < ClaudeSDKError
|
|
1010
1013
|
attr_reader :exit_code, # Integer | nil
|
|
@@ -1027,6 +1030,7 @@ end
|
|
|
1027
1030
|
|
|
1028
1031
|
| Type | Description |
|
|
1029
1032
|
|------|-------------|
|
|
1033
|
+
| `Configuration` | Global defaults via `ClaudeAgentSDK.configure` block |
|
|
1030
1034
|
| `ClaudeAgentOptions` | Main configuration for queries and clients |
|
|
1031
1035
|
| `HookMatcher` | Hook configuration with matcher pattern and timeout |
|
|
1032
1036
|
| `PermissionResultAllow` | Permission callback result to allow tool use |
|
|
@@ -1088,6 +1092,8 @@ begin
|
|
|
1088
1092
|
ClaudeAgentSDK.query(prompt: "Hello") do |message|
|
|
1089
1093
|
puts message
|
|
1090
1094
|
end
|
|
1095
|
+
rescue ClaudeAgentSDK::ControlRequestTimeoutError
|
|
1096
|
+
puts "Control protocol timed out — consider increasing the timeout"
|
|
1091
1097
|
rescue ClaudeAgentSDK::CLINotFoundError
|
|
1092
1098
|
puts "Please install Claude Code"
|
|
1093
1099
|
rescue ClaudeAgentSDK::ProcessError => e
|
|
@@ -1097,13 +1103,23 @@ rescue ClaudeAgentSDK::CLIJSONDecodeError => e
|
|
|
1097
1103
|
end
|
|
1098
1104
|
```
|
|
1099
1105
|
|
|
1106
|
+
#### Configuring Timeout
|
|
1107
|
+
|
|
1108
|
+
The control request timeout defaults to **1200 seconds** (20 minutes) to accommodate long-running agent sessions. Override it via environment variable:
|
|
1109
|
+
|
|
1110
|
+
```bash
|
|
1111
|
+
# Set a custom timeout (in seconds)
|
|
1112
|
+
export CLAUDE_AGENT_SDK_CONTROL_REQUEST_TIMEOUT_SECONDS=300 # 5 minutes
|
|
1113
|
+
```
|
|
1114
|
+
|
|
1100
1115
|
### Error Types
|
|
1101
1116
|
|
|
1102
1117
|
| Error | Description |
|
|
1103
1118
|
|-------|-------------|
|
|
1104
1119
|
| `ClaudeSDKError` | Base error for all SDK errors |
|
|
1105
|
-
| `CLINotFoundError` | Claude Code not installed |
|
|
1106
1120
|
| `CLIConnectionError` | Connection issues |
|
|
1121
|
+
| `ControlRequestTimeoutError` | Control protocol timeout (configurable via env var) |
|
|
1122
|
+
| `CLINotFoundError` | Claude Code not installed |
|
|
1107
1123
|
| `ProcessError` | Process failed (includes `exit_code` and `stderr`) |
|
|
1108
1124
|
| `CLIJSONDecodeError` | JSON parsing issues |
|
|
1109
1125
|
| `MessageParseError` | Message parsing issues |
|
|
@@ -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
|
|
@@ -262,7 +273,9 @@ module ClaudeAgentSDK
|
|
|
262
273
|
# Build environment
|
|
263
274
|
# Convert symbol keys to strings for spawn compatibility
|
|
264
275
|
custom_env = @options.env.transform_keys { |k| k.to_s }
|
|
265
|
-
|
|
276
|
+
# Strip CLAUDECODE to prevent "nested session" detection when the SDK
|
|
277
|
+
# launches Claude Code from within an existing Claude Code terminal
|
|
278
|
+
process_env = ENV.to_h.except('CLAUDECODE').merge('CLAUDE_AGENT_SDK_VERSION' => VERSION).merge(custom_env)
|
|
266
279
|
process_env['CLAUDE_CODE_ENTRYPOINT'] ||= 'sdk-rb'
|
|
267
280
|
process_env['PWD'] = @cwd.to_s if @cwd
|
|
268
281
|
|
|
@@ -275,15 +288,32 @@ module ClaudeAgentSDK
|
|
|
275
288
|
|
|
276
289
|
@stdin, @stdout, @stderr, @process = Open3.popen3(process_env, *cmd, opts)
|
|
277
290
|
|
|
278
|
-
#
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
|
284
308
|
end
|
|
285
309
|
end
|
|
286
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
|
+
|
|
287
317
|
# Close stdin for non-streaming mode
|
|
288
318
|
@stdin.close unless @is_streaming
|
|
289
319
|
@stdin = nil unless @is_streaming
|
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.
|
|
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-
|
|
10
|
+
date: 2026-02-16 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: async
|