class LittleGhost::Harnesses::ClaudeCode
Runs Claude Code in non-interactive print mode with --output-format stream-json.
The command uses --bare, so the tool ignores hooks, skills, and settings found in the working directory, and --strict-mcp-config, so it starts with only the request’s mcp_servers, whose tools are allowed. Automatic updates and nonessential traffic are disabled, and configuration lives under home.
In :isolated mode the allowed tools run without permission prompts and ANTHROPIC_API_KEY is the placeholder. In :native_guards mode the command uses --permission-mode dontAsk, so only the allowed tools run and everything else is denied; the default list allows file and search tools and denies shell and web access. Claude Code then authenticates from the inherited environment, such as ANTHROPIC_API_KEY.
defaults accepts:
:base_url-
Sets
ANTHROPIC_BASE_URL, for example aNetwork::Facadeaddress. :api_key-
Placeholder sent as
ANTHROPIC_API_KEYin:isolatedmode. A gateway replaces it. :model-
Modelused when the request does not name one. :effort-
Effort level used when the request does not name one.
:allowed_tools,:disallowed_tools-
Claude Code tool names. In
:isolatedmode the defaults allow file, search, shell, and subagent tools and disallow web access.
Claude Code enforces budget_usd and max_turns itself and reports cost, turns, and token usage in its final result.
Public Instance Methods
Source
# File lib/little_ghost/harnesses/claude_code.rb, line 56 def command(request) arguments = [ executable, "-p", "--bare", "--allowedTools", allowed_tools(request).join(","), "--disallowedTools", Array(defaults.fetch(:disallowed_tools, isolated? ? DISALLOWED_TOOLS : NATIVE_DISALLOWED_TOOLS)).join(","), *(isolated? ? ["--permission-prompts", "none"] : ["--permission-mode", "dontAsk"]), "--strict-mcp-config", "--mcp-config", JSON.generate({mcpServers: request.mcp_servers.transform_values { |url| {type: "http", url:} }}) ] arguments.push("--max-budget-usd", request.budget_usd.to_s) if request.budget_usd arguments.push("--max-turns", request.max_turns.to_s) if request.max_turns request.add_dirs.each { |directory| arguments.push("--add-dir", directory) } model = request.model || defaults[:model] arguments.push("--model", model.to_s) if model effort = request.effort || defaults[:effort] arguments.push("--effort", effort.to_s) if effort arguments.push("--append-system-prompt", request.instructions) if request.instructions arguments.push("--resume", request.session_id) if request.session_id arguments.push("--output-format", "stream-json", "--verbose") arguments.concat(positional(request.prompt)) end
Returns the Claude Code command line for request.
Source
# File lib/little_ghost/harnesses/claude_code.rb, line 79 def environment(request) values = { "CLAUDE_CONFIG_DIR" => File.join(home, ".claude"), "DISABLE_AUTOUPDATER" => "1", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC" => "1" } values["ANTHROPIC_API_KEY"] = api_key if isolated? values["ANTHROPIC_BASE_URL"] = defaults[:base_url].to_s if defaults[:base_url] values end
Returns Claude Code’s configuration and update settings, and in :isolated mode its credential placeholder.
Source
# File lib/little_ghost/harnesses/claude_code.rb, line 91 def parse_line(line, state) data = JSON.parse(line) return [] unless data.is_a?(Hash) state.session_id = data["session_id"] if data["session_id"].is_a?(String) case data["type"] when "system" then system_events(data, state) when "assistant" then assistant_events(data) when "user" then tool_result_events(data) when "result" then result_events(data, state) else [] end end
Parses one stream-json message.