claude-code-sdk-ruby 0.1.0 → 0.1.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 +19 -6
- data/README.md +7 -7
- data/examples/bypass_permissions.rb +34 -0
- data/lib/claude_sdk/internal/transport/subprocess_cli.rb +20 -1
- data/lib/claude_sdk/types.rb +7 -2
- data/lib/claude_sdk/version.rb +1 -1
- data/ruby-sdk-maintenance-swarm.yml +4 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 566de0e8ca470f448ccefffcc346d91ae504fc6b3e7bb963d1adf5ff2898de68
|
4
|
+
data.tar.gz: ee8e8fe3255480eaf6c4561502dd97ac8440170e0fed6c129781d59d002488b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14a4b7ce2e81a50ffa22f8f480ca4a18fdd55673b85e6b3459a640d235e433bb839f3e4d57c4d4454a2f07c8c01bd12205060b231d093454bd9a629f92d57cc0
|
7
|
+
data.tar.gz: 4f5511cc26a590d5f6d5cbb675149547e6a935b949d3dd8d2ad30cfcba2cd507f4b02fcd5c3d38ce2dc76c6ec1ec07687252ea3a827c605e2248db164db79af2
|
data/CHANGELOG.md
CHANGED
@@ -7,13 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
-
|
11
|
-
- Removed unused `async-process` dependency
|
10
|
+
## [0.1.2] - 2025-07-16
|
12
11
|
|
13
|
-
|
12
|
+
### Added
|
13
|
+
- Support for `--session-id` argument to specify a session ID (UUID) for conversations
|
14
|
+
- Added `session_id` parameter to `ClaudeCodeOptions`
|
15
|
+
- CLI command now includes `--session-id` when session ID is provided
|
16
|
+
|
17
|
+
## [0.1.1] - 2025-07-15
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
- Fixed permission mode conversion to use camelCase format for CLI compatibility
|
21
|
+
- `:bypass_permissions` now correctly converts to `"bypassPermissions"`
|
22
|
+
- `:accept_edits` now correctly converts to `"acceptEdits"`
|
23
|
+
- This ensures the SDK properly passes permission modes to the Claude CLI
|
24
|
+
|
25
|
+
## [0.1.0] - 2025-07-15
|
14
26
|
|
15
27
|
### Added
|
16
|
-
- Initial release of claude-sdk-ruby
|
28
|
+
- Initial release of claude-code-sdk-ruby
|
17
29
|
- Core SDK functionality for interacting with Claude Code CLI
|
18
30
|
- Support for async query processing
|
19
31
|
- Message types: User, Assistant, System, and Result
|
@@ -39,5 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
39
51
|
- simplecov (~> 0.22)
|
40
52
|
- yard (~> 0.9)
|
41
53
|
|
42
|
-
[Unreleased]: https://github.com/
|
43
|
-
[0.
|
54
|
+
[Unreleased]: https://github.com/parruda/claude-code-sdk-ruby/compare/v0.1.1...HEAD
|
55
|
+
[0.1.1]: https://github.com/parruda/claude-code-sdk-ruby/compare/v0.1.0...v0.1.1
|
56
|
+
[0.1.0]: https://github.com/parruda/claude-code-sdk-ruby/releases/tag/v0.1.0
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Claude SDK Ruby
|
1
|
+
# Claude Code SDK Ruby
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/claude-sdk-ruby)
|
3
|
+
[](https://badge.fury.io/rb/claude-code-sdk-ruby)
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
5
5
|
|
6
6
|
Official Ruby SDK for interacting with Claude Code CLI. This gem provides a Ruby-idiomatic interface to Claude Code with full async support, proper error handling, and comprehensive type definitions.
|
@@ -10,7 +10,7 @@ Official Ruby SDK for interacting with Claude Code CLI. This gem provides a Ruby
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'claude-sdk-ruby'
|
13
|
+
gem 'claude-code-sdk-ruby'
|
14
14
|
```
|
15
15
|
|
16
16
|
And then execute:
|
@@ -22,7 +22,7 @@ bundle install
|
|
22
22
|
Or install it yourself as:
|
23
23
|
|
24
24
|
```bash
|
25
|
-
gem install claude-sdk-ruby
|
25
|
+
gem install claude-code-sdk-ruby
|
26
26
|
```
|
27
27
|
|
28
28
|
## Prerequisites
|
@@ -203,17 +203,17 @@ bundle exec rspec
|
|
203
203
|
COVERAGE=true bundle exec rspec
|
204
204
|
|
205
205
|
# Build the gem
|
206
|
-
gem build claude-sdk-ruby.gemspec
|
206
|
+
gem build claude-code-sdk-ruby.gemspec
|
207
207
|
|
208
208
|
# Install locally
|
209
|
-
gem install ./claude-sdk-ruby-0.1.0.gem
|
209
|
+
gem install ./claude-code-sdk-ruby-0.1.0.gem
|
210
210
|
```
|
211
211
|
|
212
212
|
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
213
213
|
|
214
214
|
## Contributing
|
215
215
|
|
216
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
216
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/parruda/claude-code-sdk-ruby.
|
217
217
|
|
218
218
|
## License
|
219
219
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "claude_sdk"
|
5
|
+
|
6
|
+
# Example showing how to use bypass permissions mode
|
7
|
+
# This will pass --permission-mode bypassPermissions to the CLI
|
8
|
+
|
9
|
+
options = ClaudeSDK::ClaudeCodeOptions.new(
|
10
|
+
permission_mode: :bypass_permissions,
|
11
|
+
)
|
12
|
+
|
13
|
+
client = ClaudeSDK::Client.new(options)
|
14
|
+
|
15
|
+
begin
|
16
|
+
response = client.query("List the files in the current directory")
|
17
|
+
|
18
|
+
response.each do |message|
|
19
|
+
if message["type"] == "user"
|
20
|
+
puts "User: #{message["content"]}"
|
21
|
+
elsif message["type"] == "assistant"
|
22
|
+
message["content"].each do |block|
|
23
|
+
if block["type"] == "text"
|
24
|
+
puts "Assistant: #{block["text"]}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
rescue ClaudeSDK::CLINotFoundError => e
|
30
|
+
puts "Error: #{e.message}"
|
31
|
+
puts "Please install Claude Code CLI first"
|
32
|
+
rescue StandardError => e
|
33
|
+
puts "Error: #{e.message}"
|
34
|
+
end
|
@@ -334,12 +334,14 @@ module ClaudeSDK
|
|
334
334
|
cmd.push("--permission-prompt-tool", @options.permission_prompt_tool_name)
|
335
335
|
end
|
336
336
|
|
337
|
-
cmd.push("--permission-mode", @options.permission_mode
|
337
|
+
cmd.push("--permission-mode", format_permission_mode(@options.permission_mode)) if @options.permission_mode
|
338
338
|
|
339
339
|
cmd.push("--continue") if @options.continue_conversation
|
340
340
|
|
341
341
|
cmd.push("--resume", @options.resume) if @options.resume
|
342
342
|
|
343
|
+
cmd.push("--session-id", @options.session_id) if @options.session_id
|
344
|
+
|
343
345
|
if @options.mcp_servers && !@options.mcp_servers.empty?
|
344
346
|
mcp_config = { "mcpServers" => serialize_mcp_servers }
|
345
347
|
cmd.push("--mcp-config", JSON.generate(mcp_config))
|
@@ -357,6 +359,23 @@ module ClaudeSDK
|
|
357
359
|
server.respond_to?(:to_h) ? server.to_h : server
|
358
360
|
end
|
359
361
|
end
|
362
|
+
|
363
|
+
# Convert permission mode from Ruby symbol format to CLI camelCase format
|
364
|
+
#
|
365
|
+
# @param mode [Symbol] the permission mode symbol
|
366
|
+
# @return [String] the camelCase formatted mode
|
367
|
+
def format_permission_mode(mode)
|
368
|
+
case mode
|
369
|
+
when :default
|
370
|
+
"default"
|
371
|
+
when :accept_edits
|
372
|
+
"acceptEdits"
|
373
|
+
when :bypass_permissions
|
374
|
+
"bypassPermissions"
|
375
|
+
else
|
376
|
+
mode.to_s
|
377
|
+
end
|
378
|
+
end
|
360
379
|
end
|
361
380
|
end
|
362
381
|
end
|
data/lib/claude_sdk/types.rb
CHANGED
@@ -336,7 +336,8 @@ module ClaudeSDK
|
|
336
336
|
:disallowed_tools,
|
337
337
|
:model,
|
338
338
|
:permission_prompt_tool_name,
|
339
|
-
:cwd
|
339
|
+
:cwd,
|
340
|
+
:session_id
|
340
341
|
|
341
342
|
# Initialize with default values
|
342
343
|
#
|
@@ -354,6 +355,7 @@ module ClaudeSDK
|
|
354
355
|
# @param model [String, nil] model name
|
355
356
|
# @param permission_prompt_tool_name [String, nil] permission tool
|
356
357
|
# @param cwd [String, Pathname, nil] working directory
|
358
|
+
# @param session_id [String, nil] session ID (must be a valid UUID)
|
357
359
|
def initialize(allowed_tools: [],
|
358
360
|
max_thinking_tokens: 8000,
|
359
361
|
system_prompt: nil,
|
@@ -367,7 +369,8 @@ module ClaudeSDK
|
|
367
369
|
disallowed_tools: [],
|
368
370
|
model: nil,
|
369
371
|
permission_prompt_tool_name: nil,
|
370
|
-
cwd: nil
|
372
|
+
cwd: nil,
|
373
|
+
session_id: nil)
|
371
374
|
@allowed_tools = allowed_tools
|
372
375
|
@max_thinking_tokens = max_thinking_tokens
|
373
376
|
@system_prompt = system_prompt
|
@@ -382,6 +385,7 @@ module ClaudeSDK
|
|
382
385
|
@model = model
|
383
386
|
@permission_prompt_tool_name = permission_prompt_tool_name
|
384
387
|
@cwd = cwd
|
388
|
+
@session_id = session_id
|
385
389
|
|
386
390
|
validate_permission_mode! if permission_mode
|
387
391
|
end
|
@@ -405,6 +409,7 @@ module ClaudeSDK
|
|
405
409
|
hash[:model] = model if model
|
406
410
|
hash[:permission_prompt_tool_name] = permission_prompt_tool_name if permission_prompt_tool_name
|
407
411
|
hash[:cwd] = cwd.to_s if cwd
|
412
|
+
hash[:session_id] = session_id if session_id
|
408
413
|
hash
|
409
414
|
end
|
410
415
|
|
data/lib/claude_sdk/version.rb
CHANGED
@@ -47,8 +47,8 @@ swarm:
|
|
47
47
|
|
48
48
|
python_sdk_guide:
|
49
49
|
description: "Python SDK consultant providing implementation guidance and best practices"
|
50
|
-
directory: .
|
51
|
-
model:
|
50
|
+
directory: ~/src/github.com/anthropics/claude-code-sdk-python
|
51
|
+
model: opus
|
52
52
|
vibe: true
|
53
53
|
prompt: |
|
54
54
|
You are a Python SDK consultant specializing in the Claude Code Python SDK. Your role is to:
|
@@ -59,9 +59,9 @@ swarm:
|
|
59
59
|
- Help maintain consistency between SDKs while respecting language idioms
|
60
60
|
- Read and understand Python SDK code to inform Ruby development
|
61
61
|
|
62
|
-
You
|
62
|
+
You explore and analyze the Python SDK codebase and provide
|
63
63
|
implementation guidance. Focus on reading the Python SDK codebase to understand
|
64
64
|
patterns and suggest how they should be adapted for Ruby.
|
65
65
|
|
66
66
|
For maximum efficiency, whenever you need to perform multiple independent operations,
|
67
|
-
invoke all relevant tools simultaneously rather than sequentially.
|
67
|
+
invoke all relevant tools simultaneously rather than sequentially.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: claude-code-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Arruda
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: async
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- claude-code-sdk-ruby.gemspec
|
56
56
|
- examples/async_multiple_queries.rb
|
57
57
|
- examples/basic_usage.rb
|
58
|
+
- examples/bypass_permissions.rb
|
58
59
|
- examples/enumerator_usage.rb
|
59
60
|
- examples/error_handling.rb
|
60
61
|
- examples/mcp_servers.rb
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
- !ruby/object:Gem::Version
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
|
-
rubygems_version: 3.6.
|
93
|
+
rubygems_version: 3.6.9
|
93
94
|
specification_version: 4
|
94
95
|
summary: Ruby SDK for Claude Code
|
95
96
|
test_files: []
|