claude-code-sdk-ruby 0.1.5 → 0.1.6

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: 17f03088a7ce2f00f3f3fedc4c1b6fdece21831a6d3ccbc90bcefab2faaf5a75
4
- data.tar.gz: 5d2dc1e635eef3e3fcd94f0587961df9e87eb0f26172c15f568742c5ee859a4b
3
+ metadata.gz: 271d1f22697c1e35a2b9bbea19c7258ed714009bb9237bc2a5482af44ec6a32f
4
+ data.tar.gz: 692fe7861052964d3511166afc95551552ffed534e723f764d5fd5301b7a0e3c
5
5
  SHA512:
6
- metadata.gz: c44a60dca629d3be19f8a27acf421962f7aeb9cf5a0b54492dee5c86350252648c4b927e8e3b43b63135159c8581c1f895d31b418053958eb092a72059dc5441
7
- data.tar.gz: 749804df124c0b048b1664771c05b97cde812fb732d3ffb0a44c6334a872f891c387dfa09065f91cb9733d7d10a238340e00efca1d790f02f7005ad41bf210c3
6
+ metadata.gz: 7033b78c154965204db8cba25b144c920bf62cc7481e39addb823837bdd118f1c5a35a383d58eccc49c3b29a8021d7576dee5ff4765b88f153a83f700eb22ed4
7
+ data.tar.gz: 1df5a522cf96cb11e4ad0da37fd9c2a83988928e1d5eb4c04f2643c3f26378d3dd5fd99687fd950fce69bf6dd5f31bee14a5086778a44389f65dbf6e6f16f1ab
data/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.6] - 2025-07-30
11
+
12
+ ### Added
13
+ - Support for `--settings` flag to load additional settings from a JSON file
14
+ - Added `settings` parameter to `ClaudeCodeOptions`
15
+ - CLI command now includes `--settings` when settings file path is provided
16
+ - Added example demonstrating how to use settings files
17
+ - Updated documentation with Claude Code settings format
18
+
10
19
  ## [0.1.4] - 2025-07-18
11
20
 
12
21
  ### Fixed
data/README.md CHANGED
@@ -107,6 +107,48 @@ messages.each do |message|
107
107
  end
108
108
  ```
109
109
 
110
+ ### Using Settings Files
111
+
112
+ You can load additional settings from a JSON file:
113
+
114
+ ```ruby
115
+ require 'claude_sdk'
116
+
117
+ # Create options with a settings file path
118
+ options = ClaudeSDK::ClaudeCodeOptions.new(
119
+ settings: '/path/to/claude-settings.json',
120
+ model: 'sonnet' # Other options can still be specified
121
+ )
122
+
123
+ ClaudeSDK.query("Hello", options: options) do |message|
124
+ puts message
125
+ end
126
+ ```
127
+
128
+ The settings file should be a valid JSON file containing Claude Code configuration options:
129
+
130
+ ```json
131
+ {
132
+ "permissions": {
133
+ "allow": [
134
+ "Bash(npm run lint)",
135
+ "Bash(npm run test:*)",
136
+ "Read(~/.zshrc)"
137
+ ],
138
+ "deny": [
139
+ "Bash(curl:*)"
140
+ ]
141
+ },
142
+ "env": {
143
+ "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
144
+ "OTEL_METRICS_EXPORTER": "otlp"
145
+ },
146
+ "model": "claude-3-5-sonnet-20241022",
147
+ "cleanupPeriodDays": 20,
148
+ "includeCoAuthoredBy": true
149
+ }
150
+ ```
151
+
110
152
  ### Advanced: Using the Internal Client Directly
111
153
 
112
154
  ```ruby
@@ -166,6 +208,7 @@ The `ClaudeCodeOptions` class supports all Claude Code CLI options:
166
208
  - `continue_conversation` - Whether to continue from previous conversation
167
209
  - `resume` - Resume from a specific conversation ID
168
210
  - `mcp_servers` - MCP server configuration
211
+ - `settings` - Path to a settings JSON file to load additional settings from
169
212
 
170
213
  ## Error Handling
171
214
 
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "claude_sdk"
6
+ require "json"
7
+ require "tmpdir"
8
+
9
+ # Example demonstrating how to use the --settings flag
10
+ # This creates a temporary settings file and uses it with the SDK
11
+
12
+ Dir.mktmpdir do |tmpdir|
13
+ # Create a sample settings file
14
+ settings_path = File.join(tmpdir, "claude-settings.json")
15
+
16
+ settings_content = {
17
+ "permissions" => {
18
+ "allow" => [
19
+ "Bash(npm run lint)",
20
+ "Bash(npm run test:*)",
21
+ "Read(~/.zshrc)",
22
+ ],
23
+ "deny" => [
24
+ "Bash(curl:*)",
25
+ ],
26
+ },
27
+ "env" => {
28
+ "CLAUDE_CODE_ENABLE_TELEMETRY" => "1",
29
+ "OTEL_METRICS_EXPORTER" => "otlp",
30
+ },
31
+ "model" => "claude-3-5-sonnet-20241022",
32
+ "cleanupPeriodDays" => 20,
33
+ "includeCoAuthoredBy" => true,
34
+ }
35
+
36
+ File.write(settings_path, JSON.pretty_generate(settings_content))
37
+
38
+ puts "Created settings file at: #{settings_path}"
39
+ puts "Settings content:"
40
+ puts JSON.pretty_generate(settings_content)
41
+ puts "\n---\n\n"
42
+
43
+ # Create options with the settings file path
44
+ options = ClaudeSDK::ClaudeCodeOptions.new(
45
+ settings: settings_path,
46
+ model: "sonnet",
47
+ )
48
+
49
+ # Query Claude with the settings
50
+ puts "Querying Claude with settings file..."
51
+
52
+ ClaudeSDK.query("What is 2 + 2?", options: options) do |message|
53
+ if message.is_a?(Hash)
54
+ type = message["type"]
55
+
56
+ case type
57
+ when "text"
58
+ print(message["text"])
59
+ when "result"
60
+ puts "\n\nResult: #{message["result"]}" if message["result"]
61
+ end
62
+ end
63
+ end
64
+ end
@@ -342,6 +342,8 @@ module ClaudeSDK
342
342
 
343
343
  cmd.push("--session-id", @options.session_id) if @options.session_id
344
344
 
345
+ cmd.push("--settings", @options.settings.to_s) if @options.settings
346
+
345
347
  if @options.mcp_servers && !@options.mcp_servers.empty?
346
348
  mcp_config = { "mcpServers" => serialize_mcp_servers }
347
349
  cmd.push("--mcp-config", JSON.generate(mcp_config))
@@ -322,6 +322,7 @@ module ClaudeSDK
322
322
  # @!attribute model [String, nil] model to use
323
323
  # @!attribute permission_prompt_tool_name [String, nil] permission prompt tool
324
324
  # @!attribute cwd [String, Pathname, nil] working directory
325
+ # @!attribute settings [String, Pathname, nil] path to settings JSON file
325
326
  class ClaudeCodeOptions
326
327
  attr_accessor :allowed_tools,
327
328
  :max_thinking_tokens,
@@ -337,7 +338,8 @@ module ClaudeSDK
337
338
  :model,
338
339
  :permission_prompt_tool_name,
339
340
  :cwd,
340
- :session_id
341
+ :session_id,
342
+ :settings
341
343
 
342
344
  # Initialize with default values
343
345
  #
@@ -356,6 +358,7 @@ module ClaudeSDK
356
358
  # @param permission_prompt_tool_name [String, nil] permission tool
357
359
  # @param cwd [String, Pathname, nil] working directory
358
360
  # @param session_id [String, nil] session ID (must be a valid UUID)
361
+ # @param settings [String, Pathname, nil] path to settings JSON file
359
362
  def initialize(allowed_tools: [],
360
363
  max_thinking_tokens: 8000,
361
364
  system_prompt: nil,
@@ -370,7 +373,8 @@ module ClaudeSDK
370
373
  model: nil,
371
374
  permission_prompt_tool_name: nil,
372
375
  cwd: nil,
373
- session_id: nil)
376
+ session_id: nil,
377
+ settings: nil)
374
378
  @allowed_tools = allowed_tools
375
379
  @max_thinking_tokens = max_thinking_tokens
376
380
  @system_prompt = system_prompt
@@ -386,6 +390,7 @@ module ClaudeSDK
386
390
  @permission_prompt_tool_name = permission_prompt_tool_name
387
391
  @cwd = cwd
388
392
  @session_id = session_id
393
+ @settings = settings
389
394
 
390
395
  validate_permission_mode! if permission_mode
391
396
  end
@@ -410,6 +415,7 @@ module ClaudeSDK
410
415
  hash[:permission_prompt_tool_name] = permission_prompt_tool_name if permission_prompt_tool_name
411
416
  hash[:cwd] = cwd.to_s if cwd
412
417
  hash[:session_id] = session_id if session_id
418
+ hash[:settings] = settings.to_s if settings
413
419
  hash
414
420
  end
415
421
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClaudeSDK
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: claude-code-sdk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Arruda
@@ -60,6 +60,7 @@ files:
60
60
  - examples/error_handling.rb
61
61
  - examples/mcp_servers.rb
62
62
  - examples/with_options.rb
63
+ - examples/with_settings.rb
63
64
  - lib/claude_sdk.rb
64
65
  - lib/claude_sdk/errors.rb
65
66
  - lib/claude_sdk/internal/client.rb