Skip to content

Commit e7e1ad9

Browse files
parrudaclaude
andcommitted
fix: Convert permission modes to camelCase for CLI compatibility
- Fixed permission mode conversion to use camelCase format - :bypass_permissions now correctly converts to "bypassPermissions" - :accept_edits now correctly converts to "acceptEdits" - Added format_permission_mode method to handle conversions - Added tests to verify correct camelCase conversion - Added example showing bypass permissions usage - Bumped version to 0.1.1 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1998bb5 commit e7e1ad9

5 files changed

Lines changed: 102 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.1] - 2025-07-15
11+
12+
### Fixed
13+
- Fixed permission mode conversion to use camelCase format for CLI compatibility
14+
- `:bypass_permissions` now correctly converts to `"bypassPermissions"`
15+
- `:accept_edits` now correctly converts to `"acceptEdits"`
16+
- This ensures the SDK properly passes permission modes to the Claude CLI
17+
1018
## [0.1.0] - 2025-07-15
1119

1220
### Added
@@ -36,5 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3644
- simplecov (~> 0.22)
3745
- yard (~> 0.9)
3846

39-
[Unreleased]: https://github.com/parruda/claude-code-sdk-ruby/compare/v0.1.0...HEAD
47+
[Unreleased]: https://github.com/parruda/claude-code-sdk-ruby/compare/v0.1.1...HEAD
48+
[0.1.1]: https://github.com/parruda/claude-code-sdk-ruby/compare/v0.1.0...v0.1.1
4049
[0.1.0]: https://github.com/parruda/claude-code-sdk-ruby/releases/tag/v0.1.0

examples/bypass_permissions.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/claude_sdk/internal/transport/subprocess_cli.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def build_command
334334
cmd.push("--permission-prompt-tool", @options.permission_prompt_tool_name)
335335
end
336336

337-
cmd.push("--permission-mode", @options.permission_mode.to_s) if @options.permission_mode
337+
cmd.push("--permission-mode", format_permission_mode(@options.permission_mode)) if @options.permission_mode
338338

339339
cmd.push("--continue") if @options.continue_conversation
340340

@@ -357,6 +357,23 @@ def serialize_mcp_servers
357357
server.respond_to?(:to_h) ? server.to_h : server
358358
end
359359
end
360+
361+
# Convert permission mode from Ruby symbol format to CLI camelCase format
362+
#
363+
# @param mode [Symbol] the permission mode symbol
364+
# @return [String] the camelCase formatted mode
365+
def format_permission_mode(mode)
366+
case mode
367+
when :default
368+
"default"
369+
when :accept_edits
370+
"acceptEdits"
371+
when :bypass_permissions
372+
"bypassPermissions"
373+
else
374+
mode.to_s
375+
end
376+
end
360377
end
361378
end
362379
end

lib/claude_sdk/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module ClaudeSDK
4-
VERSION = "0.1.0"
4+
VERSION = "0.1.1"
55
end

spec/claude_sdk/internal/subprocess_cli_spec.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
expect(cmd).to(include("--allowedTools", "Read,Write"))
7474
expect(cmd).to(include("--disallowedTools", "Bash"))
7575
expect(cmd).to(include("--model", "claude-3-5-sonnet"))
76-
expect(cmd).to(include("--permission-mode", "accept_edits"))
76+
expect(cmd).to(include("--permission-mode", "acceptEdits"))
7777
expect(cmd).to(include("--max-turns", "5"))
7878
end
7979

@@ -94,6 +94,44 @@
9494
expect(cmd).to(include("--continue"))
9595
expect(cmd).to(include("--resume", "session-123"))
9696
end
97+
98+
it "converts permission modes to camelCase" do
99+
# Test bypass_permissions
100+
options = ClaudeSDK::ClaudeCodeOptions.new(
101+
permission_mode: :bypass_permissions,
102+
)
103+
transport = described_class.new(
104+
prompt: "test",
105+
options: options,
106+
cli_path: cli_path,
107+
)
108+
cmd = transport.send(:build_command)
109+
expect(cmd).to(include("--permission-mode", "bypassPermissions"))
110+
111+
# Test accept_edits
112+
options = ClaudeSDK::ClaudeCodeOptions.new(
113+
permission_mode: :accept_edits,
114+
)
115+
transport = described_class.new(
116+
prompt: "test",
117+
options: options,
118+
cli_path: cli_path,
119+
)
120+
cmd = transport.send(:build_command)
121+
expect(cmd).to(include("--permission-mode", "acceptEdits"))
122+
123+
# Test default
124+
options = ClaudeSDK::ClaudeCodeOptions.new(
125+
permission_mode: :default,
126+
)
127+
transport = described_class.new(
128+
prompt: "test",
129+
options: options,
130+
cli_path: cli_path,
131+
)
132+
cmd = transport.send(:build_command)
133+
expect(cmd).to(include("--permission-mode", "default"))
134+
end
97135
end
98136

99137
describe "#connect and #disconnect" do

0 commit comments

Comments
 (0)