Creates a SubprocessCLITransport, connects to the CLI, sends the
prompt, and returns a coro generator that yields typed message objects.
The generator terminates automatically after the ResultMessage.
Usage
claude_query(prompt, options = ClaudeAgentOptions(), transport = NULL)Arguments
- prompt
Character(1) or list. Prompt text, or a list of content blocks.
- options
A
ClaudeAgentOptionsfromClaudeAgentOptions().- transport
Optional
SubprocessCLITransportR6 object. When supplied,connect()is NOT called automatically — the caller must have already connected.
Details
The caller is responsible for disconnecting the transport after the
generator is exhausted. For a simpler synchronous API see claude_run().
Examples
if (FALSE) { # \dontrun{
gen <- claude_query("What is 2 + 2?", ClaudeAgentOptions(max_turns = 1L))
coro::loop(for (msg in gen) {
if (inherits(msg, "AssistantMessage")) {
for (blk in msg$content)
if (inherits(blk, "TextBlock")) cat(blk$text)
}
})
} # }