claude_agent 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +87 -2
- data/SPEC.md +12 -7
- data/lib/claude_agent/hooks.rb +4 -2
- data/lib/claude_agent/options.rb +2 -1
- data/lib/claude_agent/version.rb +1 -1
- data/sig/claude_agent.rbs +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c630af2842675c8aa126588105617fa1af823c437ef1095029b3f7e9efbc982c
|
|
4
|
+
data.tar.gz: 16199aa31e03d542bf9128356594a0ea6659a16ecfba7fa2b3e1a97429662ef2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f555706af9480e572d8f310a73ab0d1294b9eaf6b162146364032450bbad86f0a2e962649f12e74e48dae4155fd1929221efd46a349253d1bf96ad09249db54
|
|
7
|
+
data.tar.gz: fbf3a236589cad360dbfff15dfa8164a353a973e211e5f4ab4802d8b383d803359a137a9a312478bbd0175f7b866c4f40795f55c6d8b2eb8f028992f403b5182
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-01-16
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `agent` option for specifying main thread agent name (TypeScript SDK v0.2.9 parity)
|
|
14
|
+
- `model` field in `SessionStartInput` hook input
|
|
15
|
+
|
|
10
16
|
## [0.2.0] - 2026-01-11
|
|
11
17
|
|
|
12
18
|
### Added
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ClaudeAgent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ruby gem for building AI-powered applications with the [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview). This library essentially wraps the Claude Code CLI, providing both simple one-shot queries and interactive bidirectional sessions.
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
@@ -95,6 +95,9 @@ options = ClaudeAgent::Options.new(
|
|
|
95
95
|
cwd: "/path/to/project",
|
|
96
96
|
add_dirs: ["/additional/path"],
|
|
97
97
|
|
|
98
|
+
# Agent configuration
|
|
99
|
+
agent: "my-agent", # Agent name for main thread
|
|
100
|
+
|
|
98
101
|
# Session management
|
|
99
102
|
resume: "session-id",
|
|
100
103
|
continue_conversation: true,
|
|
@@ -456,7 +459,7 @@ All available hook events:
|
|
|
456
459
|
| PostToolUseFailure | `PostToolUseFailureInput` | tool_name, tool_input, error, tool_use_id, is_interrupt |
|
|
457
460
|
| Notification | `NotificationInput` | message, title, notification_type |
|
|
458
461
|
| UserPromptSubmit | `UserPromptSubmitInput` | prompt |
|
|
459
|
-
| SessionStart | `SessionStartInput` | source, agent_type
|
|
462
|
+
| SessionStart | `SessionStartInput` | source, agent_type, model |
|
|
460
463
|
| SessionEnd | `SessionEndInput` | reason |
|
|
461
464
|
| Stop | `StopInput` | stop_hook_active |
|
|
462
465
|
| SubagentStart | `SubagentStartInput` | agent_id, agent_type |
|
|
@@ -591,6 +594,88 @@ puts client.account_info.email
|
|
|
591
594
|
client.disconnect
|
|
592
595
|
```
|
|
593
596
|
|
|
597
|
+
## V2 Session API (Unstable)
|
|
598
|
+
|
|
599
|
+
> **⚠️ Alpha API**: This API is unstable and may change without notice.
|
|
600
|
+
|
|
601
|
+
The V2 Session API provides a simpler interface for multi-turn conversations, matching the TypeScript SDK's `SDKSession` interface.
|
|
602
|
+
|
|
603
|
+
### Create a Session
|
|
604
|
+
|
|
605
|
+
```ruby
|
|
606
|
+
# Create a new session
|
|
607
|
+
session = ClaudeAgent.unstable_v2_create_session(
|
|
608
|
+
model: "claude-sonnet-4-5-20250514",
|
|
609
|
+
permission_mode: "acceptEdits"
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
# Send a message
|
|
613
|
+
session.send("Hello, Claude!")
|
|
614
|
+
|
|
615
|
+
# Stream responses
|
|
616
|
+
session.stream.each do |msg|
|
|
617
|
+
case msg
|
|
618
|
+
when ClaudeAgent::AssistantMessage
|
|
619
|
+
puts msg.text
|
|
620
|
+
when ClaudeAgent::ResultMessage
|
|
621
|
+
puts "Done! Cost: $#{msg.total_cost_usd}"
|
|
622
|
+
end
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
# Continue the conversation
|
|
626
|
+
session.send("Tell me more")
|
|
627
|
+
session.stream.each { |msg| puts msg.text if msg.is_a?(ClaudeAgent::AssistantMessage) }
|
|
628
|
+
|
|
629
|
+
# Close when done
|
|
630
|
+
session.close
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### Resume a Session
|
|
634
|
+
|
|
635
|
+
```ruby
|
|
636
|
+
# Resume an existing session by ID
|
|
637
|
+
session = ClaudeAgent.unstable_v2_resume_session(
|
|
638
|
+
"session-abc123",
|
|
639
|
+
model: "claude-sonnet-4-5-20250514"
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
session.send("What were we discussing?")
|
|
643
|
+
session.stream.each { |msg| puts msg.text if msg.is_a?(ClaudeAgent::AssistantMessage) }
|
|
644
|
+
session.close
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
### One-Shot Prompt
|
|
648
|
+
|
|
649
|
+
```ruby
|
|
650
|
+
# Simple one-shot prompt (auto-closes session)
|
|
651
|
+
result = ClaudeAgent.unstable_v2_prompt(
|
|
652
|
+
"What is 2 + 2?",
|
|
653
|
+
model: "claude-sonnet-4-5-20250514"
|
|
654
|
+
)
|
|
655
|
+
|
|
656
|
+
puts "Success: #{result.success?}"
|
|
657
|
+
puts "Cost: $#{result.total_cost_usd}"
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
### SessionOptions
|
|
661
|
+
|
|
662
|
+
The V2 API uses a simplified options type:
|
|
663
|
+
|
|
664
|
+
```ruby
|
|
665
|
+
options = ClaudeAgent::SessionOptions.new(
|
|
666
|
+
model: "claude-sonnet-4-5-20250514", # Required
|
|
667
|
+
permission_mode: "acceptEdits", # Optional
|
|
668
|
+
allowed_tools: ["Read", "Grep"], # Optional
|
|
669
|
+
disallowed_tools: ["Write"], # Optional
|
|
670
|
+
can_use_tool: ->(name, input, ctx) { ... }, # Optional
|
|
671
|
+
hooks: { "PreToolUse" => [...] }, # Optional
|
|
672
|
+
env: { "MY_VAR" => "value" }, # Optional
|
|
673
|
+
path_to_claude_code_executable: "/custom/path" # Optional
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
session = ClaudeAgent.unstable_v2_create_session(options)
|
|
677
|
+
```
|
|
678
|
+
|
|
594
679
|
## Types Reference
|
|
595
680
|
|
|
596
681
|
### Return Types
|
data/SPEC.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
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
4
|
|
|
5
5
|
**Reference Versions:**
|
|
6
|
-
- TypeScript SDK: v0.2.
|
|
7
|
-
- Python SDK:
|
|
6
|
+
- TypeScript SDK: v0.2.9 (npm package)
|
|
7
|
+
- Python SDK: v0.1.20 from GitHub (commit 04da88d)
|
|
8
8
|
- Ruby SDK: This repository
|
|
9
9
|
|
|
10
10
|
---
|
|
@@ -65,12 +65,13 @@ Configuration options for SDK queries and clients.
|
|
|
65
65
|
| `settingSources` | ✅ | ✅ | ✅ | Which settings to load |
|
|
66
66
|
| `plugins` | ✅ | ✅ | ✅ | Plugin configurations |
|
|
67
67
|
| `betas` | ✅ | ✅ | ✅ | Beta features (e.g., context-1m-2025-08-07) |
|
|
68
|
+
| `agent` | ✅ | ❌ | ✅ | Agent name for main thread |
|
|
68
69
|
| `abortController` | ✅ | ❌ | ✅ | Cancellation controller |
|
|
69
70
|
| `stderr` | ✅ | ✅ | ✅ | Stderr callback |
|
|
70
71
|
| `spawnClaudeCodeProcess` | ✅ | ❌ | ✅ | Custom spawn function |
|
|
71
72
|
| `pathToClaudeCodeExecutable` | ✅ | ✅ | ✅ | Custom CLI path |
|
|
72
|
-
| `executable` | ✅ |
|
|
73
|
-
| `executableArgs` | ✅ |
|
|
73
|
+
| `executable` | ✅ | N/A | N/A | JS runtime (node/bun/deno) - JS-specific |
|
|
74
|
+
| `executableArgs` | ✅ | N/A | N/A | JS runtime args - JS-specific |
|
|
74
75
|
| `extraArgs` | ✅ | ✅ | ✅ | Extra CLI arguments |
|
|
75
76
|
| `user` | ❌ | ✅ | ✅ | User identifier |
|
|
76
77
|
|
|
@@ -531,6 +532,7 @@ Public API surface for SDK clients.
|
|
|
531
532
|
|
|
532
533
|
- ✅ = Fully implemented
|
|
533
534
|
- ❌ = Not implemented
|
|
535
|
+
- N/A = Not applicable (language-specific feature)
|
|
534
536
|
- Partial = Partially implemented
|
|
535
537
|
|
|
536
538
|
---
|
|
@@ -541,21 +543,24 @@ Public API surface for SDK clients.
|
|
|
541
543
|
- Primary reference for API surface (most comprehensive)
|
|
542
544
|
- Source is bundled/minified, but `sdk.d.ts` provides complete type definitions
|
|
543
545
|
- Includes unstable V2 session API
|
|
544
|
-
- Version 0.2.
|
|
546
|
+
- Version 0.2.9 adds `agent` option for specifying main thread agent
|
|
545
547
|
- Adds `deno` as supported executable option
|
|
546
548
|
- Includes experimental `criticalSystemReminder_EXPERIMENTAL` for agent definitions
|
|
549
|
+
- `SessionStartHookInput` includes `model` field
|
|
547
550
|
|
|
548
551
|
### Python SDK
|
|
549
|
-
- Full source available
|
|
552
|
+
- Full source available (v0.1.20)
|
|
550
553
|
- Fewer control protocol features than TypeScript
|
|
551
554
|
- Does not support SessionStart/SessionEnd/Notification hooks due to setup limitations
|
|
552
555
|
- Missing several permission modes (delegate, dontAsk)
|
|
553
556
|
- `excludedCommands` in sandbox now supported
|
|
557
|
+
- `tool_use_id` now included in PreToolUseHookInput
|
|
554
558
|
|
|
555
559
|
### Ruby SDK (This Repository)
|
|
556
|
-
-
|
|
560
|
+
- Full TypeScript SDK feature parity achieved
|
|
557
561
|
- Ruby-idiomatic patterns (Data.define, snake_case)
|
|
558
562
|
- Complete control protocol support
|
|
559
563
|
- Dedicated Client class for multi-turn conversations
|
|
560
564
|
- Full hook event support including all 12 events
|
|
561
565
|
- Full V2 Session API support (unstable)
|
|
566
|
+
- `executable`/`executableArgs` marked N/A (JS runtime options not applicable to Ruby)
|
data/lib/claude_agent/hooks.rb
CHANGED
|
@@ -141,14 +141,16 @@ module ClaudeAgent
|
|
|
141
141
|
# Input for SessionStart hook (TypeScript SDK parity)
|
|
142
142
|
#
|
|
143
143
|
class SessionStartInput < BaseHookInput
|
|
144
|
-
attr_reader :source, :agent_type
|
|
144
|
+
attr_reader :source, :agent_type, :model
|
|
145
145
|
|
|
146
146
|
# @param source [String] One of: "startup", "resume", "clear", "compact"
|
|
147
147
|
# @param agent_type [String, nil] Type of agent if running in subagent context
|
|
148
|
-
|
|
148
|
+
# @param model [String, nil] Model being used for this session
|
|
149
|
+
def initialize(source:, agent_type: nil, model: nil, **kwargs)
|
|
149
150
|
super(hook_event_name: "SessionStart", **kwargs)
|
|
150
151
|
@source = source
|
|
151
152
|
@agent_type = agent_type
|
|
153
|
+
@model = model
|
|
152
154
|
end
|
|
153
155
|
end
|
|
154
156
|
|
data/lib/claude_agent/options.rb
CHANGED
|
@@ -50,7 +50,7 @@ module ClaudeAgent
|
|
|
50
50
|
continue_conversation resume fork_session resume_session_at
|
|
51
51
|
max_turns max_budget_usd max_thinking_tokens
|
|
52
52
|
strict_mcp_config mcp_servers hooks
|
|
53
|
-
settings sandbox cwd add_dirs env user
|
|
53
|
+
settings sandbox cwd add_dirs env user agent
|
|
54
54
|
cli_path extra_args agents setting_sources plugins
|
|
55
55
|
include_partial_messages output_format enable_file_checkpointing
|
|
56
56
|
persist_session betas max_buffer_size stderr_callback
|
|
@@ -206,6 +206,7 @@ module ClaudeAgent
|
|
|
206
206
|
def environment_args
|
|
207
207
|
[].tap do |args|
|
|
208
208
|
args.push("--user", user) if user
|
|
209
|
+
args.push("--agent", agent) if agent
|
|
209
210
|
add_dirs.each { |dir| args.push("--add-dir", dir.to_s) }
|
|
210
211
|
args.push("--setting-sources", setting_sources.join(",")) if setting_sources&.any?
|
|
211
212
|
plugins.each do |plugin|
|
data/lib/claude_agent/version.rb
CHANGED
data/sig/claude_agent.rbs
CHANGED
|
@@ -279,6 +279,7 @@ module ClaudeAgent
|
|
|
279
279
|
attr_accessor add_dirs: Array[String]
|
|
280
280
|
attr_accessor env: Hash[String, String]
|
|
281
281
|
attr_accessor user: String?
|
|
282
|
+
attr_accessor agent: String?
|
|
282
283
|
|
|
283
284
|
# CLI configuration
|
|
284
285
|
attr_accessor cli_path: String?
|
|
@@ -633,8 +634,9 @@ module ClaudeAgent
|
|
|
633
634
|
class SessionStartInput < BaseHookInput
|
|
634
635
|
attr_reader source: String
|
|
635
636
|
attr_reader agent_type: String?
|
|
637
|
+
attr_reader model: String?
|
|
636
638
|
|
|
637
|
-
def initialize: (source: String, ?agent_type: String?, **untyped) -> void
|
|
639
|
+
def initialize: (source: String, ?agent_type: String?, ?model: String?, **untyped) -> void
|
|
638
640
|
end
|
|
639
641
|
|
|
640
642
|
class SessionEndInput < BaseHookInput
|