use claude_codes::AsyncClient;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
let mut client = AsyncClient::with_defaults().await?;
println!("Sending query: What is the capital of France?");
println!("Waiting for response...\n");
let mut stream = client
.query_stream("What is the capital of France?")
.await?;
let mut response_count = 0;
while let Some(result) = stream.next().await {
response_count += 1;
match result {
Ok(output) => {
println!("Response {}: {}", response_count, output.message_type());
if let claude_codes::ClaudeOutput::Assistant(msg) = &output {
for content in &msg.message.content {
if let claude_codes::io::ContentBlock::Text(text) = content {
println!(" Claude says: {}", text.text);
}
}
}
}
Err(e) => {
eprintln!("Error receiving response: {}", e);
break;
}
}
}
println!("\nClient session complete");
Ok(())
}