pub struct QueryCommand { /* private fields */ }Expand description
Builder for claude -p <prompt> (oneshot print-mode queries).
This is the primary command for programmatic use. It runs a single prompt through Claude and returns the result.
§Example
use claude_wrapper::{Claude, ClaudeCommand, QueryCommand, OutputFormat};
let claude = Claude::builder().build()?;
let output = QueryCommand::new("explain this error: file not found")
.model("sonnet")
.output_format(OutputFormat::Json)
.max_turns(1)
.execute(&claude)
.await?;Implementations§
Source§impl QueryCommand
impl QueryCommand
Sourcepub fn new(prompt: impl Into<String>) -> Self
pub fn new(prompt: impl Into<String>) -> Self
Create a new query command with the given prompt.
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
Set the model to use (e.g. “sonnet”, “opus”, or a full model ID).
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Set a custom system prompt (replaces the default).
Sourcepub fn append_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn append_system_prompt(self, prompt: impl Into<String>) -> Self
Append to the default system prompt.
Sourcepub fn output_format(self, format: OutputFormat) -> Self
pub fn output_format(self, format: OutputFormat) -> Self
Set the output format.
Sourcepub fn max_budget_usd(self, budget: f64) -> Self
pub fn max_budget_usd(self, budget: f64) -> Self
Set the maximum budget in USD.
Sourcepub fn permission_mode(self, mode: PermissionMode) -> Self
pub fn permission_mode(self, mode: PermissionMode) -> Self
Set the permission mode.
Sourcepub fn allowed_tools(
self,
tools: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn allowed_tools( self, tools: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Add allowed tools (e.g. “Bash”, “Read”, “mcp__my-server__*”).
Sourcepub fn allowed_tool(self, tool: impl Into<String>) -> Self
pub fn allowed_tool(self, tool: impl Into<String>) -> Self
Add a single allowed tool.
Sourcepub fn disallowed_tools(
self,
tools: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn disallowed_tools( self, tools: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Add disallowed tools.
Sourcepub fn mcp_config(self, path: impl Into<String>) -> Self
pub fn mcp_config(self, path: impl Into<String>) -> Self
Add an MCP config file path.
Sourcepub fn add_dir(self, dir: impl Into<String>) -> Self
pub fn add_dir(self, dir: impl Into<String>) -> Self
Add an additional directory for tool access.
Sourcepub fn json_schema(self, schema: impl Into<String>) -> Self
pub fn json_schema(self, schema: impl Into<String>) -> Self
Set a JSON schema for structured output validation.
Sourcepub fn continue_session(self) -> Self
pub fn continue_session(self) -> Self
Continue the most recent conversation.
Sourcepub fn session_id(self, id: impl Into<String>) -> Self
pub fn session_id(self, id: impl Into<String>) -> Self
Use a specific session ID.
Sourcepub fn fallback_model(self, model: impl Into<String>) -> Self
pub fn fallback_model(self, model: impl Into<String>) -> Self
Set a fallback model for when the primary model is overloaded.
Sourcepub fn no_session_persistence(self) -> Self
pub fn no_session_persistence(self) -> Self
Disable session persistence (sessions won’t be saved to disk).
Sourcepub fn dangerously_skip_permissions(self) -> Self
pub fn dangerously_skip_permissions(self) -> Self
Bypass all permission checks. Only use in sandboxed environments.
Sourcepub fn agents_json(self, json: impl Into<String>) -> Self
pub fn agents_json(self, json: impl Into<String>) -> Self
Set custom agents as a JSON object.
Example: {"reviewer": {"description": "Reviews code", "prompt": "You are a code reviewer"}}
Sourcepub fn tools(self, tools: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn tools(self, tools: impl IntoIterator<Item = impl Into<String>>) -> Self
Set the list of available built-in tools.
Use "" to disable all tools, "default" for all tools, or
specific tool names like ["Bash", "Edit", "Read"].
This is different from allowed_tools which controls MCP tool permissions.
Sourcepub fn file(self, spec: impl Into<String>) -> Self
pub fn file(self, spec: impl Into<String>) -> Self
Add a file resource to download at startup.
Format: file_id:relative_path (e.g. file_abc:doc.txt).
Sourcepub fn include_partial_messages(self) -> Self
pub fn include_partial_messages(self) -> Self
Include partial message chunks as they arrive.
Only works with --output-format stream-json.
Sourcepub fn input_format(self, format: InputFormat) -> Self
pub fn input_format(self, format: InputFormat) -> Self
Set the input format.
Sourcepub fn strict_mcp_config(self) -> Self
pub fn strict_mcp_config(self) -> Self
Only use MCP servers from --mcp-config, ignoring all other MCP configurations.
Sourcepub fn settings(self, settings: impl Into<String>) -> Self
pub fn settings(self, settings: impl Into<String>) -> Self
Path to a settings JSON file or a JSON string.
Sourcepub fn fork_session(self) -> Self
pub fn fork_session(self) -> Self
When resuming, create a new session ID instead of reusing the original.
Sourcepub async fn execute_json(&self, claude: &Claude) -> Result<QueryResult>
pub async fn execute_json(&self, claude: &Claude) -> Result<QueryResult>
Execute the query and parse the JSON result.
This is a convenience method that sets OutputFormat::Json and
deserializes the response into a QueryResult.
Trait Implementations§
Source§impl ClaudeCommand for QueryCommand
impl ClaudeCommand for QueryCommand
Source§impl Clone for QueryCommand
impl Clone for QueryCommand
Source§fn clone(&self) -> QueryCommand
fn clone(&self) -> QueryCommand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for QueryCommand
impl RefUnwindSafe for QueryCommand
impl Send for QueryCommand
impl Sync for QueryCommand
impl Unpin for QueryCommand
impl UnsafeUnpin for QueryCommand
impl UnwindSafe for QueryCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more