Class: ClaudeAgentSDK::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_agent_sdk/command_builder.rb

Overview

Builds the CLI argv array from a ClaudeAgentOptions instance.

Constant Summary collapse

EXTRA_ARG_FLAG_REGEXP =
/\A[a-z0-9][a-z0-9-]*\z/

Instance Method Summary collapse

Constructor Details

#initialize(cli_path, options) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.



12
13
14
15
# File 'lib/claude_agent_sdk/command_builder.rb', line 12

def initialize(cli_path, options)
  @cli_path = cli_path
  @options = options
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/claude_agent_sdk/command_builder.rb', line 17

def build
  cmd = [@cli_path, "--output-format", "stream-json", "--verbose"]

  append_system_prompt(cmd)
  append_tools(cmd)
  append_allowed_tools(cmd)
  append_disallowed_tools(cmd)
  append_max_turns(cmd)
  append_model(cmd)
  append_permission(cmd)
  append_session(cmd)
  append_settings(cmd)
  append_budget(cmd)
  append_thinking(cmd)
  append_effort(cmd)
  append_betas(cmd)
  append_append_allowed_tools(cmd)
  append_output_format(cmd)
  append_additional_dirs(cmd)
  append_mcp_servers(cmd)
  append_boolean_flags(cmd)
  append_plugins(cmd)
  append_setting_sources(cmd)
  append_extra_args(cmd)

  # Always use streaming mode for bidirectional control protocol.
  # Prompts and agents are sent via stdin (initialize + user messages),
  # which avoids OS ARG_MAX limits for large prompts and agent configurations.
  cmd.push("--input-format", "stream-json")

  cmd
end