Skip to main content

query

Function query 

Source
pub async fn query(
    prompt: impl Into<String>,
    options: Option<ClaudeAgentOptions>,
) -> Result<QueryResult>
Expand description

Perform a one-shot query to Claude Code.

This is a convenience function for simple, stateless interactions where you do not need bidirectional communication or conversation management. It creates a temporary client, sends a single prompt, and returns the complete response.

§Arguments

  • prompt - The prompt to send to Claude.
  • options - Optional configuration options. If None, default options are used.

§Returns

A QueryResult containing the response content, usage statistics, and finish reason.

§Example

use claude_code_sdk_rust::query;

async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let result = query("What is Rust?", None).await?;
    println!("{}", result.content);
    Ok(())
}