claude_agent 0.1.0

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.
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ # Unit tests only (default, fast, no CLI required)
7
+ Minitest::TestTask.create(:test) do |t|
8
+ t.test_globs = [ "test/claude_agent/**/test_*.rb" ]
9
+ t.warning = false
10
+ end
11
+
12
+ # Internal task for running all tests
13
+ Minitest::TestTask.create(:_all) do |t|
14
+ t.test_globs = [ "test/**/test_*.rb" ]
15
+ t.warning = false
16
+ end
17
+
18
+ # All tests - wrapper that sets INTEGRATION=true
19
+ desc "Run all tests including integration (requires Claude CLI)"
20
+ task :test_all do
21
+ ENV["INTEGRATION"] = "true"
22
+ Rake::Task[:_all].invoke
23
+ end
24
+
25
+ # Internal task for running integration tests
26
+ Minitest::TestTask.create(:_integration) do |t|
27
+ t.test_globs = [ "test/integration/**/test_*.rb" ]
28
+ t.warning = false
29
+ end
30
+
31
+ # Integration tests - wrapper that sets INTEGRATION=true
32
+ desc "Run integration tests (requires Claude CLI)"
33
+ task :test_integration do
34
+ ENV["INTEGRATION"] = "true"
35
+ Rake::Task[:_integration].invoke
36
+ end
37
+
38
+ require "rubocop/rake_task"
39
+
40
+ RuboCop::RakeTask.new
41
+
42
+ # RBS validation tasks
43
+ namespace :rbs do
44
+ desc "Validate RBS signatures (syntax + type resolution)"
45
+ task :validate do
46
+ sh "bundle exec rbs -I sig validate"
47
+ end
48
+
49
+ desc "Parse RBS files (syntax check only, faster)"
50
+ task :parse do
51
+ sh "bundle exec rbs parse sig/**/*.rbs"
52
+ end
53
+
54
+ desc "Generate RBS prototype from lib/ (outputs to stdout)"
55
+ task :prototype do
56
+ sh "bundle exec rbs prototype rb lib/**/*.rb"
57
+ end
58
+ end
59
+
60
+ desc "Validate RBS signatures"
61
+ task rbs: "rbs:validate"
62
+
63
+ task default: %i[test rbs rubocop]
data/SPEC.md ADDED
@@ -0,0 +1,558 @@
1
+ # Claude Agent SDK Specification
2
+
3
+ This document provides a comprehensive specification of the Claude Agent SDK, comparing feature parity across the official TypeScript and Python SDKs with this Ruby implementation.
4
+
5
+ **Reference Versions:**
6
+ - TypeScript SDK: v0.2.3 (npm package)
7
+ - Python SDK: Latest from GitHub (commit 55372da)
8
+ - Ruby SDK: This repository
9
+
10
+ ---
11
+
12
+ ## Table of Contents
13
+
14
+ 1. [Options/Configuration](#1-optionsconfiguration)
15
+ 2. [Message Types](#2-message-types)
16
+ 3. [Content Blocks](#3-content-blocks)
17
+ 4. [Control Protocol](#4-control-protocol)
18
+ 5. [Hooks](#5-hooks)
19
+ 6. [Permissions](#6-permissions)
20
+ 7. [MCP Support](#7-mcp-support)
21
+ 8. [Sessions](#8-sessions)
22
+ 9. [Subagents](#9-subagents)
23
+ 10. [Sandbox Settings](#10-sandbox-settings)
24
+ 11. [Error Handling](#11-error-handling)
25
+ 12. [Client API](#12-client-api)
26
+
27
+ ---
28
+
29
+ ## 1. Options/Configuration
30
+
31
+ Configuration options for SDK queries and clients.
32
+
33
+ | Option | TypeScript | Python | Ruby | Notes |
34
+ |-----------------------------------|:----------:|:------:|:----:|-------------------------------------------------------------|
35
+ | `model` | ✅ | ✅ | ✅ | Claude model identifier |
36
+ | `fallbackModel` | ✅ | ✅ | ✅ | Fallback if primary fails |
37
+ | `systemPrompt` | ✅ | ✅ | ✅ | String or preset object |
38
+ | `appendSystemPrompt` | ✅ | ❌ | ✅ | Append to system prompt (TS SDK has via preset) |
39
+ | `tools` | ✅ | ✅ | ✅ | Array or preset |
40
+ | `allowedTools` | ✅ | ✅ | ✅ | Auto-allowed tools |
41
+ | `disallowedTools` | ✅ | ✅ | ✅ | Blocked tools |
42
+ | `permissionMode` | ✅ | ✅ | ✅ | default/acceptEdits/plan/bypassPermissions/delegate/dontAsk |
43
+ | `allowDangerouslySkipPermissions` | ✅ | ❌ | ✅ | Required for bypassPermissions |
44
+ | `canUseTool` | ✅ | ✅ | ✅ | Permission callback |
45
+ | `permissionPromptToolName` | ✅ | ✅ | ✅ | MCP tool for permission prompts |
46
+ | `maxTurns` | ✅ | ✅ | ✅ | Max conversation turns |
47
+ | `maxBudgetUsd` | ✅ | ✅ | ✅ | Max USD budget |
48
+ | `maxThinkingTokens` | ✅ | ✅ | ✅ | Max thinking tokens |
49
+ | `continue` | ✅ | ✅ | ✅ | Continue most recent conversation |
50
+ | `resume` | ✅ | ✅ | ✅ | Resume session by ID |
51
+ | `resumeSessionAt` | ✅ | ❌ | ✅ | Resume to specific message UUID |
52
+ | `forkSession` | ✅ | ✅ | ✅ | Fork on resume |
53
+ | `persistSession` | ✅ | ❌ | ✅ | Whether to persist to disk |
54
+ | `enableFileCheckpointing` | ✅ | ✅ | ✅ | Track file changes for rewind |
55
+ | `includePartialMessages` | ✅ | ✅ | ✅ | Include stream events |
56
+ | `outputFormat` | ✅ | ✅ | ✅ | JSON schema for structured output |
57
+ | `mcpServers` | ✅ | ✅ | ✅ | MCP server configurations |
58
+ | `strictMcpConfig` | ✅ | ❌ | ✅ | Strict validation of MCP config |
59
+ | `hooks` | ✅ | ✅ | ✅ | Hook callbacks |
60
+ | `agents` | ✅ | ✅ | ✅ | Custom subagent definitions |
61
+ | `cwd` | ✅ | ✅ | ✅ | Working directory |
62
+ | `additionalDirectories` | ✅ | ✅ | ✅ | Extra allowed directories |
63
+ | `env` | ✅ | ✅ | ✅ | Environment variables |
64
+ | `sandbox` | ✅ | ✅ | ✅ | Sandbox settings |
65
+ | `settingSources` | ✅ | ✅ | ✅ | Which settings to load |
66
+ | `plugins` | ✅ | ✅ | ✅ | Plugin configurations |
67
+ | `betas` | ✅ | ✅ | ✅ | Beta features (e.g., context-1m) |
68
+ | `abortController` | ✅ | ❌ | ✅ | Cancellation controller |
69
+ | `stderr` | ✅ | ✅ | ✅ | Stderr callback |
70
+ | `spawnClaudeCodeProcess` | ✅ | ❌ | ✅ | Custom spawn function |
71
+ | `pathToClaudeCodeExecutable` | ✅ | ✅ | ✅ | Custom CLI path |
72
+ | `executable` | ✅ | ❌ | ❌ | JS runtime (bun/deno/node) |
73
+ | `executableArgs` | ✅ | ❌ | ❌ | JS runtime args |
74
+ | `extraArgs` | ✅ | ✅ | ✅ | Extra CLI arguments |
75
+ | `user` | ❌ | ✅ | ✅ | User identifier |
76
+
77
+ ---
78
+
79
+ ## 2. Message Types
80
+
81
+ Messages exchanged between SDK and CLI.
82
+
83
+ | Message Type | TypeScript | Python | Ruby | Notes |
84
+ |--------------------------|:----------:|:------:|:----:|---------------------------------|
85
+ | `UserMessage` | ✅ | ✅ | ✅ | User input |
86
+ | `UserMessageReplay` | ✅ | ❌ | ✅ | Replayed user message on resume |
87
+ | `AssistantMessage` | ✅ | ✅ | ✅ | Claude response |
88
+ | `SystemMessage` | ✅ | ✅ | ✅ | System/init messages |
89
+ | `ResultMessage` | ✅ | ✅ | ✅ | Final result with usage |
90
+ | `StreamEvent` | ✅ | ✅ | ✅ | Partial streaming events |
91
+ | `CompactBoundaryMessage` | ✅ | ❌ | ✅ | Conversation compaction marker |
92
+ | `StatusMessage` | ✅ | ❌ | ✅ | Status updates (compacting) |
93
+ | `ToolProgressMessage` | ✅ | ❌ | ✅ | Long-running tool progress |
94
+ | `HookResponseMessage` | ✅ | ❌ | ✅ | Hook execution output |
95
+ | `AuthStatusMessage` | ✅ | ❌ | ✅ | Authentication status |
96
+
97
+ ### Message Fields
98
+
99
+ #### ResultMessage
100
+
101
+ | Field | TypeScript | Python | Ruby | Notes |
102
+ |----------------------|:----------:|:------:|:----:|--------------------------|
103
+ | `subtype` | ✅ | ✅ | ✅ | success/error_* |
104
+ | `duration_ms` | ✅ | ✅ | ✅ | Total duration |
105
+ | `duration_api_ms` | ✅ | ✅ | ✅ | API call duration |
106
+ | `is_error` | ✅ | ✅ | ✅ | Error flag |
107
+ | `num_turns` | ✅ | ✅ | ✅ | Turn count |
108
+ | `result` | ✅ | ✅ | ✅ | Text result (on success) |
109
+ | `total_cost_usd` | ✅ | ✅ | ✅ | Total cost |
110
+ | `usage` | ✅ | ✅ | ✅ | Token usage |
111
+ | `modelUsage` | ✅ | ❌ | ✅ | Per-model usage |
112
+ | `permission_denials` | ✅ | ❌ | ✅ | Denied permissions |
113
+ | `structured_output` | ✅ | ✅ | ✅ | JSON schema output |
114
+ | `errors` | ✅ | ❌ | ✅ | Error messages |
115
+ | `uuid` | ✅ | ❌ | ✅ | Message UUID |
116
+ | `session_id` | ✅ | ✅ | ✅ | Session ID |
117
+
118
+ #### Result Subtypes
119
+
120
+ | Subtype | TypeScript | Python | Ruby | Notes |
121
+ |---------------------------------------|:----------:|:------:|:----:|------------------------------------|
122
+ | `success` | ✅ | ✅ | ✅ | Successful completion |
123
+ | `error_during_execution` | ✅ | ✅ | ✅ | Runtime error |
124
+ | `error_max_turns` | ✅ | ✅ | ✅ | Max turns exceeded |
125
+ | `error_max_budget_usd` | ✅ | ✅ | ✅ | Budget exceeded |
126
+ | `error_max_structured_output_retries` | ✅ | ❌ | ✅ | Structured output retries exceeded |
127
+
128
+ ---
129
+
130
+ ## 3. Content Blocks
131
+
132
+ Content block types within messages.
133
+
134
+ | Block Type | TypeScript | Python | Ruby | Notes |
135
+ |-------------------------|:----------:|:------:|:----:|-------------------------|
136
+ | `TextBlock` | ✅ | ✅ | ✅ | Text content |
137
+ | `ThinkingBlock` | ✅ | ✅ | ✅ | Extended thinking |
138
+ | `ToolUseBlock` | ✅ | ✅ | ✅ | Tool invocation |
139
+ | `ToolResultBlock` | ✅ | ✅ | ✅ | Tool result |
140
+ | `ServerToolUseBlock` | ✅ | ❌ | ✅ | MCP server tool use |
141
+ | `ServerToolResultBlock` | ✅ | ❌ | ✅ | MCP server tool result |
142
+ | `ImageContentBlock` | ✅ | ❌ | ✅ | Image data (base64/URL) |
143
+
144
+ ### Block Fields
145
+
146
+ #### ToolUseBlock
147
+
148
+ | Field | TypeScript | Python | Ruby |
149
+ |---------|:----------:|:------:|:----:|
150
+ | `id` | ✅ | ✅ | ✅ |
151
+ | `name` | ✅ | ✅ | ✅ |
152
+ | `input` | ✅ | ✅ | ✅ |
153
+
154
+ #### ThinkingBlock
155
+
156
+ | Field | TypeScript | Python | Ruby |
157
+ |-------------|:----------:|:------:|:----:|
158
+ | `thinking` | ✅ | ✅ | ✅ |
159
+ | `signature` | ✅ | ✅ | ✅ |
160
+
161
+ ---
162
+
163
+ ## 4. Control Protocol
164
+
165
+ Bidirectional control protocol for SDK-CLI communication.
166
+
167
+ ### Control Request Types
168
+
169
+ | Request Subtype | TypeScript | Python | Ruby | Notes |
170
+ |---------------------------|:----------:|:------:|:----:|-----------------------------------|
171
+ | `initialize` | ✅ | ✅ | ✅ | Initialize session with hooks/MCP |
172
+ | `interrupt` | ✅ | ✅ | ✅ | Interrupt current operation |
173
+ | `can_use_tool` | ✅ | ✅ | ✅ | Permission callback |
174
+ | `hook_callback` | ✅ | ✅ | ✅ | Execute hook callback |
175
+ | `set_permission_mode` | ✅ | ✅ | ✅ | Change permission mode |
176
+ | `set_model` | ✅ | ❌ | ✅ | Change model |
177
+ | `set_max_thinking_tokens` | ✅ | ❌ | ✅ | Change thinking tokens limit |
178
+ | `rewind_files` | ✅ | ✅ | ✅ | Rewind file checkpoints |
179
+ | `mcp_message` | ✅ | ✅ | ✅ | Route MCP message |
180
+ | `mcp_set_servers` | ✅ | ❌ | ✅ | Dynamically set MCP servers |
181
+ | `mcp_status` | ✅ | ❌ | ✅ | Get MCP server status |
182
+ | `supported_commands` | ✅ | ❌ | ✅ | Get available slash commands |
183
+ | `supported_models` | ✅ | ❌ | ✅ | Get available models |
184
+ | `account_info` | ✅ | ❌ | ✅ | Get account information |
185
+
186
+ ### Return Types
187
+
188
+ | Type | TypeScript | Python | Ruby | Notes |
189
+ |-----------------------|:----------:|:------:|:----:|------------------------|
190
+ | `SlashCommand` | ✅ | ❌ | ✅ | Available command info |
191
+ | `ModelInfo` | ✅ | ❌ | ✅ | Model information |
192
+ | `McpServerStatus` | ✅ | ❌ | ✅ | MCP server status |
193
+ | `AccountInfo` | ✅ | ❌ | ✅ | Account information |
194
+ | `McpSetServersResult` | ✅ | ❌ | ✅ | Set servers result |
195
+ | `RewindFilesResult` | ✅ | ✅ | ✅ | Rewind result |
196
+
197
+ ---
198
+
199
+ ## 5. Hooks
200
+
201
+ Event hooks for intercepting and modifying SDK behavior.
202
+
203
+ ### Hook Events
204
+
205
+ | Event | TypeScript | Python | Ruby | Notes |
206
+ |----------------------|:----------:|:------:|:----:|------------------------|
207
+ | `PreToolUse` | ✅ | ✅ | ✅ | Before tool execution |
208
+ | `PostToolUse` | ✅ | ✅ | ✅ | After tool execution |
209
+ | `PostToolUseFailure` | ✅ | ❌ | ✅ | After tool failure |
210
+ | `Notification` | ✅ | ❌ | ✅ | System notifications |
211
+ | `UserPromptSubmit` | ✅ | ✅ | ✅ | User message submitted |
212
+ | `SessionStart` | ✅ | ❌ | ✅ | Session starts |
213
+ | `SessionEnd` | ✅ | ❌ | ✅ | Session ends |
214
+ | `Stop` | ✅ | ✅ | ✅ | Agent stops |
215
+ | `SubagentStart` | ✅ | ❌ | ✅ | Subagent starts |
216
+ | `SubagentStop` | ✅ | ✅ | ✅ | Subagent stops |
217
+ | `PreCompact` | ✅ | ✅ | ✅ | Before compaction |
218
+ | `PermissionRequest` | ✅ | ❌ | ✅ | Permission requested |
219
+
220
+ ### Hook Input Types
221
+
222
+ | Input Type | TypeScript | Python | Ruby |
223
+ |-------------------------------|:----------:|:------:|:----:|
224
+ | `PreToolUseHookInput` | ✅ | ✅ | ✅ |
225
+ | `PostToolUseHookInput` | ✅ | ✅ | ✅ |
226
+ | `PostToolUseFailureHookInput` | ✅ | ❌ | ✅ |
227
+ | `NotificationHookInput` | ✅ | ❌ | ✅ |
228
+ | `UserPromptSubmitHookInput` | ✅ | ✅ | ✅ |
229
+ | `SessionStartHookInput` | ✅ | ❌ | ✅ |
230
+ | `SessionEndHookInput` | ✅ | ❌ | ✅ |
231
+ | `StopHookInput` | ✅ | ✅ | ✅ |
232
+ | `SubagentStartHookInput` | ✅ | ❌ | ✅ |
233
+ | `SubagentStopHookInput` | ✅ | ✅ | ✅ |
234
+ | `PreCompactHookInput` | ✅ | ✅ | ✅ |
235
+ | `PermissionRequestHookInput` | ✅ | ❌ | ✅ |
236
+
237
+ ### Hook Output Types
238
+
239
+ | Output Field | TypeScript | Python | Ruby | Notes |
240
+ |----------------------|:----------:|:------:|:----:|-----------------------|
241
+ | `continue` | ✅ | ✅ | ✅ | Continue execution |
242
+ | `async` | ✅ | ✅ | ✅ | Async hook execution |
243
+ | `asyncTimeout` | ✅ | ✅ | ✅ | Async timeout |
244
+ | `suppressOutput` | ✅ | ✅ | ✅ | Hide stdout |
245
+ | `stopReason` | ✅ | ✅ | ✅ | Stop message |
246
+ | `decision` | ✅ | ✅ | ✅ | Block decision |
247
+ | `systemMessage` | ✅ | ✅ | ✅ | System message |
248
+ | `reason` | ✅ | ✅ | ✅ | Reason feedback |
249
+ | `hookSpecificOutput` | ✅ | ✅ | ✅ | Event-specific output |
250
+
251
+ ### Hook Matcher
252
+
253
+ | Field | TypeScript | Python | Ruby |
254
+ |-----------------------|:----------:|:------:|:----:|
255
+ | `matcher` | ✅ | ✅ | ✅ |
256
+ | `hooks` / `callbacks` | ✅ | ✅ | ✅ |
257
+ | `timeout` | ✅ | ✅ | ✅ |
258
+
259
+ ---
260
+
261
+ ## 6. Permissions
262
+
263
+ Permission handling and updates.
264
+
265
+ ### Permission Modes
266
+
267
+ | Mode | TypeScript | Python | Ruby | Notes |
268
+ |---------------------|:----------:|:------:|:----:|--------------------|
269
+ | `default` | ✅ | ✅ | ✅ | Standard prompting |
270
+ | `acceptEdits` | ✅ | ✅ | ✅ | Auto-accept edits |
271
+ | `plan` | ✅ | ✅ | ✅ | Planning mode |
272
+ | `bypassPermissions` | ✅ | ✅ | ✅ | Skip all checks |
273
+ | `delegate` | ✅ | ❌ | ✅ | Delegate mode |
274
+ | `dontAsk` | ✅ | ❌ | ✅ | Never prompt |
275
+
276
+ ### Permission Result Types
277
+
278
+ | Type | TypeScript | Python | Ruby |
279
+ |-------------------------|:----------:|:------:|:----:|
280
+ | `PermissionResultAllow` | ✅ | ✅ | ✅ |
281
+ | `PermissionResultDeny` | ✅ | ✅ | ✅ |
282
+
283
+ ### Permission Result Fields
284
+
285
+ | Field | TypeScript | Python | Ruby |
286
+ |----------------------|:----------:|:------:|:----:|
287
+ | `behavior` | ✅ | ✅ | ✅ |
288
+ | `updatedInput` | ✅ | ✅ | ✅ |
289
+ | `updatedPermissions` | ✅ | ✅ | ✅ |
290
+ | `message` (deny) | ✅ | ✅ | ✅ |
291
+ | `interrupt` (deny) | ✅ | ✅ | ✅ |
292
+ | `toolUseID` | ✅ | ❌ | ❌ |
293
+
294
+ ### Permission Update Types
295
+
296
+ | Update Type | TypeScript | Python | Ruby |
297
+ |---------------------|:----------:|:------:|:----:|
298
+ | `addRules` | ✅ | ✅ | ✅ |
299
+ | `replaceRules` | ✅ | ✅ | ✅ |
300
+ | `removeRules` | ✅ | ✅ | ✅ |
301
+ | `setMode` | ✅ | ✅ | ✅ |
302
+ | `addDirectories` | ✅ | ✅ | ✅ |
303
+ | `removeDirectories` | ✅ | ✅ | ✅ |
304
+
305
+ ### Permission Update Destinations
306
+
307
+ | Destination | TypeScript | Python | Ruby |
308
+ |-------------------|:----------:|:------:|:----:|
309
+ | `userSettings` | ✅ | ✅ | ✅ |
310
+ | `projectSettings` | ✅ | ✅ | ✅ |
311
+ | `localSettings` | ✅ | ✅ | ✅ |
312
+ | `session` | ✅ | ✅ | ✅ |
313
+ | `cliArg` | ✅ | ❌ | ✅ |
314
+
315
+ ### ToolPermissionContext
316
+
317
+ | Field | TypeScript | Python | Ruby | Notes |
318
+ |------------------|:----------:|:------:|:----:|---------------------------|
319
+ | `signal` | ✅ | ✅ | ❌ | Abort signal |
320
+ | `suggestions` | ✅ | ✅ | ✅ | Permission suggestions |
321
+ | `blockedPath` | ✅ | ✅ | ✅ | Blocked file path |
322
+ | `decisionReason` | ✅ | ❌ | ✅ | Why permission triggered |
323
+ | `toolUseID` | ✅ | ❌ | ✅ | Tool call ID |
324
+ | `agentID` | ✅ | ❌ | ✅ | Subagent ID if applicable |
325
+
326
+ ---
327
+
328
+ ## 7. MCP Support
329
+
330
+ Model Context Protocol server support.
331
+
332
+ ### MCP Server Types
333
+
334
+ | Type | TypeScript | Python | Ruby | Notes |
335
+ |---------|:----------:|:------:|:----:|-----------------------|
336
+ | `stdio` | ✅ | ✅ | ✅ | Subprocess with stdio |
337
+ | `sse` | ✅ | ✅ | ✅ | Server-sent events |
338
+ | `http` | ✅ | ✅ | ✅ | HTTP transport |
339
+ | `sdk` | ✅ | ✅ | ✅ | In-process SDK server |
340
+
341
+ ### MCP Server Config Fields
342
+
343
+ #### stdio
344
+
345
+ | Field | TypeScript | Python | Ruby |
346
+ |-----------|:----------:|:------:|:----:|
347
+ | `type` | ✅ | ✅ | ✅ |
348
+ | `command` | ✅ | ✅ | ✅ |
349
+ | `args` | ✅ | ✅ | ✅ |
350
+ | `env` | ✅ | ✅ | ✅ |
351
+
352
+ #### sse/http
353
+
354
+ | Field | TypeScript | Python | Ruby |
355
+ |-----------|:----------:|:------:|:----:|
356
+ | `type` | ✅ | ✅ | ✅ |
357
+ | `url` | ✅ | ✅ | ✅ |
358
+ | `headers` | ✅ | ✅ | ✅ |
359
+
360
+ #### sdk
361
+
362
+ | Field | TypeScript | Python | Ruby |
363
+ |------------|:----------:|:------:|:----:|
364
+ | `type` | ✅ | ✅ | ✅ |
365
+ | `name` | ✅ | ✅ | ✅ |
366
+ | `instance` | ✅ | ✅ | ✅ |
367
+
368
+ ### SDK MCP Server
369
+
370
+ | Feature | TypeScript | Python | Ruby | Notes |
371
+ |----------------------|:----------:|:------:|:--------------------:|------------------------|
372
+ | `createSdkMcpServer` | ✅ | ❌ | ✅ | Create SDK server |
373
+ | `tool()` helper | ✅ | ❌ | ✅ | Create tool definition |
374
+ | Tool input schema | ✅ (Zod) | ❌ | ✅ (Hash/JSON Schema) | Schema definition |
375
+
376
+ ---
377
+
378
+ ## 8. Sessions
379
+
380
+ Session management and resumption.
381
+
382
+ | Feature | TypeScript | Python | Ruby | Notes |
383
+ |----------------------|:----------:|:------:|:----:|-------------------------|
384
+ | Session ID tracking | ✅ | ✅ | ✅ | Via messages |
385
+ | Resume by ID | ✅ | ✅ | ✅ | `resume` option |
386
+ | Resume at message | ✅ | ❌ | ✅ | `resumeSessionAt` |
387
+ | Fork session | ✅ | ✅ | ✅ | `forkSession` option |
388
+ | Persist session | ✅ | ❌ | ✅ | `persistSession` option |
389
+ | Continue most recent | ✅ | ✅ | ✅ | `continue` option |
390
+
391
+ ### V2 Session API (Unstable)
392
+
393
+ | Feature | TypeScript | Python | Ruby | Notes |
394
+ |-----------------------------|:----------:|:------:|:----:|---------------------------|
395
+ | `SDKSession` interface | ✅ | ❌ | ❌ | Multi-turn session object |
396
+ | `unstable_v2_createSession` | ✅ | ❌ | ❌ | Create new session |
397
+ | `unstable_v2_resumeSession` | ✅ | ❌ | ❌ | Resume existing session |
398
+ | `unstable_v2_prompt` | ✅ | ❌ | ❌ | One-shot prompt |
399
+
400
+ ---
401
+
402
+ ## 9. Subagents
403
+
404
+ Custom subagent definitions.
405
+
406
+ ### AgentDefinition
407
+
408
+ | Field | TypeScript | Python | Ruby | Notes |
409
+ |---------------------------------------|:----------:|:------:|:----:|--------------------------------------------|
410
+ | `description` | ✅ | ✅ | ✅ | When to use agent |
411
+ | `prompt` | ✅ | ✅ | ✅ | Agent system prompt |
412
+ | `tools` | ✅ | ✅ | ✅ | Allowed tools |
413
+ | `disallowedTools` | ✅ | ❌ | ✅ | Blocked tools |
414
+ | `model` | ✅ | ✅ | ✅ | Model override (sonnet/opus/haiku/inherit) |
415
+ | `mcpServers` | ✅ | ❌ | ✅ | Agent-specific MCP servers |
416
+ | `criticalSystemReminder_EXPERIMENTAL` | ✅ | ❌ | ✅ | Critical reminder (experimental) |
417
+
418
+ ---
419
+
420
+ ## 10. Sandbox Settings
421
+
422
+ Sandbox configuration for command execution isolation.
423
+
424
+ ### SandboxSettings
425
+
426
+ | Field | TypeScript | Python | Ruby |
427
+ |-----------------------------|:----------:|:------:|:----:|
428
+ | `enabled` | ✅ | ✅ | ✅ |
429
+ | `autoAllowBashIfSandboxed` | ✅ | ✅ | ✅ |
430
+ | `excludedCommands` | ✅ | ✅ | ✅ |
431
+ | `allowUnsandboxedCommands` | ✅ | ✅ | ✅ |
432
+ | `network` | ✅ | ✅ | ✅ |
433
+ | `ignoreViolations` | ✅ | ✅ | ✅ |
434
+ | `enableWeakerNestedSandbox` | ✅ | ✅ | ✅ |
435
+ | `ripgrep` | ✅ | ❌ | ✅ |
436
+
437
+ ### SandboxNetworkConfig
438
+
439
+ | Field | TypeScript | Python | Ruby |
440
+ |-----------------------|:----------:|:------:|:----:|
441
+ | `allowedDomains` | ✅ | ❌ | ✅ |
442
+ | `allowUnixSockets` | ✅ | ✅ | ✅ |
443
+ | `allowAllUnixSockets` | ✅ | ✅ | ✅ |
444
+ | `allowLocalBinding` | ✅ | ✅ | ✅ |
445
+ | `httpProxyPort` | ✅ | ✅ | ✅ |
446
+ | `socksProxyPort` | ✅ | ✅ | ✅ |
447
+
448
+ ---
449
+
450
+ ## 11. Error Handling
451
+
452
+ Error types and hierarchy.
453
+
454
+ | Error Type | TypeScript | Python | Ruby | Notes |
455
+ |----------------------|:----------:|:------:|:----:|--------------------------------|
456
+ | Base Error | ✅ | ✅ | ✅ | `Error` / `ClaudeAgent::Error` |
457
+ | `AbortError` | ✅ | ❌ | ✅ | Operation cancelled |
458
+ | `CLINotFoundError` | ❌ | ❌ | ✅ | CLI not found |
459
+ | `CLIVersionError` | ❌ | ❌ | ✅ | CLI version too old |
460
+ | `CLIConnectionError` | ❌ | ❌ | ✅ | Connection failed |
461
+ | `ProcessError` | ❌ | ❌ | ✅ | CLI process failed |
462
+ | `JSONDecodeError` | ❌ | ❌ | ✅ | JSON parsing failed |
463
+ | `MessageParseError` | ❌ | ❌ | ✅ | Message parsing failed |
464
+ | `TimeoutError` | ❌ | ❌ | ✅ | Control request timeout |
465
+ | `ConfigurationError` | ❌ | ❌ | ✅ | Invalid configuration |
466
+
467
+ ### Assistant Message Errors
468
+
469
+ | Error Type | TypeScript | Python | Ruby |
470
+ |-------------------------|:----------:|:------:|:----:|
471
+ | `authentication_failed` | ✅ | ✅ | ✅ |
472
+ | `billing_error` | ✅ | ✅ | ✅ |
473
+ | `rate_limit` | ✅ | ✅ | ✅ |
474
+ | `invalid_request` | ✅ | ✅ | ✅ |
475
+ | `server_error` | ✅ | ✅ | ✅ |
476
+ | `unknown` | ✅ | ✅ | ✅ |
477
+
478
+ ---
479
+
480
+ ## 12. Client API
481
+
482
+ Public API surface for SDK clients.
483
+
484
+ ### Query Interface
485
+
486
+ | Feature | TypeScript | Python | Ruby | Notes |
487
+ |-------------------------|:-----------:|:-----------:|:-----------------------:|--------------------|
488
+ | One-shot query function | ✅ `query()` | ✅ `query()` | ✅ `ClaudeAgent.query()` | Simple prompts |
489
+ | Returns async generator | ✅ | ✅ | ✅ (Enumerator) | Streaming messages |
490
+
491
+ ### Query Control Methods (TypeScript)
492
+
493
+ | Method | TypeScript | Python | Ruby | Notes |
494
+ |--------------------------|:----------:|:------:|:----:|------------------------|
495
+ | `interrupt()` | ✅ | ❌ | ✅ | Interrupt execution |
496
+ | `setPermissionMode()` | ✅ | ❌ | ✅ | Change permission mode |
497
+ | `setModel()` | ✅ | ❌ | ✅ | Change model |
498
+ | `setMaxThinkingTokens()` | ✅ | ❌ | ✅ | Set thinking limit |
499
+ | `supportedCommands()` | ✅ | ❌ | ✅ | Get slash commands |
500
+ | `supportedModels()` | ✅ | ❌ | ✅ | Get available models |
501
+ | `mcpServerStatus()` | ✅ | ❌ | ✅ | Get MCP status |
502
+ | `accountInfo()` | ✅ | ❌ | ✅ | Get account info |
503
+ | `rewindFiles()` | ✅ | ✅ | ✅ | Rewind file changes |
504
+ | `setMcpServers()` | ✅ | ❌ | ✅ | Dynamic MCP servers |
505
+ | `streamInput()` | ✅ | ❌ | ✅ | Stream user input |
506
+
507
+ ### Client Class
508
+
509
+ | Feature | TypeScript | Python | Ruby | Notes |
510
+ |----------------------|:----------:|:-------------------:|:-----------------------:|--------------------------------|
511
+ | Multi-turn client | ❌ | ✅ `ClaudeSDKClient` | ✅ `ClaudeAgent::Client` | Interactive sessions |
512
+ | `connect()` | N/A | ✅ | ✅ | Start session |
513
+ | `disconnect()` | N/A | ✅ | ✅ | End session |
514
+ | `send_message()` | N/A | ✅ | ✅ | Send user message |
515
+ | `receive_response()` | N/A | ✅ | ✅ | Receive until result |
516
+ | `stream_input()` | N/A | ❌ | ✅ | Stream input messages |
517
+ | `abort!()` | N/A | ❌ | ✅ | Abort operations |
518
+ | Control methods | N/A | Partial | ✅ | All TypeScript control methods |
519
+
520
+ ### Transport
521
+
522
+ | Feature | TypeScript | Python | Ruby | Notes |
523
+ |-----------------------|:----------:|:------:|:----:|--------------------------|
524
+ | `Transport` interface | ✅ | ❌ | ✅ | Transport abstraction |
525
+ | Process transport | ✅ | ✅ | ✅ | Subprocess communication |
526
+ | Custom spawn | ✅ | ❌ | ✅ | VM/container support |
527
+
528
+ ---
529
+
530
+ ## Legend
531
+
532
+ - ✅ = Fully implemented
533
+ - ❌ = Not implemented
534
+ - Partial = Partially implemented
535
+
536
+ ---
537
+
538
+ ## Notes
539
+
540
+ ### TypeScript SDK
541
+ - Primary reference for API surface (most comprehensive)
542
+ - Source is bundled/minified, but `sdk.d.ts` provides complete type definitions
543
+ - Includes unstable V2 session API
544
+ - Version 0.2.3 adds `maxOutputTokens` field to `ModelUsage`
545
+
546
+ ### Python SDK
547
+ - Full source available
548
+ - Fewer control protocol features than TypeScript
549
+ - Does not support SessionStart/SessionEnd/Notification hooks due to setup limitations
550
+ - Missing several permission modes (delegate, dontAsk)
551
+ - `excludedCommands` in sandbox now supported
552
+
553
+ ### Ruby SDK (This Repository)
554
+ - Aims for TypeScript SDK parity
555
+ - Ruby-idiomatic patterns (Data.define, snake_case)
556
+ - Complete control protocol support
557
+ - Dedicated Client class for multi-turn conversations
558
+ - Full hook event support including all 12 events