Documentation
¶
Index ¶
- func QueryStream(ctx context.Context, prompt string, options *Options) (<-chan Message, <-chan error)
- func QueryStreamWithRequest(ctx context.Context, request QueryRequest) (<-chan Message, <-chan error)
- type AssistantMessage
- type CLIConnectionError
- type CLIJSONDecodeError
- type CLINotFoundError
- type ClaudeSDKError
- type ContentBlock
- type ContentBlockType
- type MCPServer
- type McpServerConfig
- type Message
- type MessageType
- type Options
- type OutputFormat
- type ProcessError
- type QueryRequest
- type ResultMessage
- type SystemMessage
- type TextBlock
- type ToolResultBlock
- type ToolUseBlock
- type Usage
- type UserMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QueryStream ¶
func QueryStream(ctx context.Context, prompt string, options *Options) (<-chan Message, <-chan error)
QueryStream executes a query against Claude Code and returns a channel of messages This provides true streaming by reading messages in real-time
func QueryStreamWithRequest ¶
func QueryStreamWithRequest(ctx context.Context, request QueryRequest) (<-chan Message, <-chan error)
QueryStreamWithRequest executes a streaming query using the TypeScript/Python SDK compatible request format
Types ¶
type AssistantMessage ¶
type AssistantMessage struct { ContentBlocks []ContentBlock `json:"content"` ParentToolUseID *string `json:"parent_tool_use_id,omitempty"` SessionID string `json:"session_id"` CreatedAt time.Time `json:"created_at"` }
AssistantMessage represents a message from the assistant
func (*AssistantMessage) Content ¶
func (m *AssistantMessage) Content() []ContentBlock
func (*AssistantMessage) Timestamp ¶
func (m *AssistantMessage) Timestamp() time.Time
func (*AssistantMessage) Type ¶
func (m *AssistantMessage) Type() MessageType
type CLIConnectionError ¶
CLIConnectionError is returned when there's an error connecting to the CLI
func (*CLIConnectionError) Error ¶
func (e *CLIConnectionError) Error() string
func (*CLIConnectionError) Unwrap ¶
func (e *CLIConnectionError) Unwrap() error
type CLIJSONDecodeError ¶
CLIJSONDecodeError is returned when JSON from the CLI cannot be decoded
func (*CLIJSONDecodeError) Error ¶
func (e *CLIJSONDecodeError) Error() string
func (*CLIJSONDecodeError) Unwrap ¶
func (e *CLIJSONDecodeError) Unwrap() error
type CLINotFoundError ¶
type CLINotFoundError struct {
Path string
}
CLINotFoundError is returned when the Claude Code CLI cannot be found
func (*CLINotFoundError) Error ¶
func (e *CLINotFoundError) Error() string
type ClaudeSDKError ¶
ClaudeSDKError represents a general SDK error
func (*ClaudeSDKError) Error ¶
func (e *ClaudeSDKError) Error() string
func (*ClaudeSDKError) Unwrap ¶
func (e *ClaudeSDKError) Unwrap() error
type ContentBlock ¶
type ContentBlock interface {
Type() ContentBlockType
}
ContentBlock represents a block of content within a message
type ContentBlockType ¶
type ContentBlockType string
ContentBlockType represents the type of content block
const ( ContentBlockTypeText ContentBlockType = "text" ContentBlockTypeToolUse ContentBlockType = "tool_use" ContentBlockTypeToolResult ContentBlockType = "tool_result" )
type McpServerConfig ¶
type McpServerConfig struct { Transport []string `json:"transport"` Env map[string]interface{} `json:"env,omitempty"` }
McpServerConfig represents MCP server configuration
type Message ¶
type Message interface { Type() MessageType Content() []ContentBlock Timestamp() time.Time }
Message represents a message in the conversation
func QueryWithRequest ¶
func QueryWithRequest(ctx context.Context, request QueryRequest) ([]Message, error)
QueryWithRequest executes a query using the TypeScript/Python SDK compatible request format
type MessageType ¶
type MessageType string
MessageType represents the type of message
const ( MessageTypeAssistant MessageType = "assistant" MessageTypeUser MessageType = "user" MessageTypeSystem MessageType = "system" MessageTypeResult MessageType = "result" )
type Options ¶
type Options struct { // Core behavior options // Model specifies the model to use (e.g., 'sonnet', 'opus', or full model name) Model *string `json:"model,omitempty"` // SystemPrompt sets a custom system prompt to guide Claude's behavior SystemPrompt *string `json:"system_prompt,omitempty"` // AppendSystemPrompt appends to the default system prompt AppendSystemPrompt *string `json:"append_system_prompt,omitempty"` // MaxTurns limits the number of conversation turns MaxTurns *int `json:"max_turns,omitempty"` // Session management // Continue indicates whether to continue the latest session Continue *bool `json:"continue,omitempty"` // Resume specifies a session ID to resume Resume *string `json:"resume,omitempty"` // Tool configuration // AllowedTools specifies which tools Claude can use (comma or space-separated) AllowedTools []string `json:"allowed_tools,omitempty"` // DisallowedTools specifies which tools Claude cannot use (comma or space-separated) DisallowedTools []string `json:"disallowed_tools,omitempty"` // MCP (Model Context Protocol) configuration // MCPTools specifies MCP tools to use MCPTools []string `json:"mcp_tools,omitempty"` // MCPServers specifies MCP server configurations MCPServers map[string]McpServerConfig `json:"mcp_servers,omitempty"` // MCPConfig specifies the path to MCP server configuration JSON file or JSON string MCPConfig *string `json:"mcp_config,omitempty"` // Permission and security // PermissionMode defines the interaction permission level // Options: "default", "acceptEdits", "bypassPermissions", "plan" PermissionMode *string `json:"permission_mode,omitempty"` // PermissionPromptTool specifies the MCP tool to use for permission prompts PermissionPromptTool *string `json:"permission_prompt_tool,omitempty"` // DangerouslySkipPermissions bypasses all permission checks // Recommended only for sandboxes with no internet access DangerouslySkipPermissions *bool `json:"dangerously_skip_permissions,omitempty"` // Directory and environment // Cwd sets the working directory for Claude Code Cwd *string `json:"cwd,omitempty"` // AddDir specifies additional directories to allow tool access to AddDir []string `json:"add_dir,omitempty"` // I/O format options // InputFormat specifies the input format: "text" (default) or "stream-json" InputFormat *string `json:"input_format,omitempty"` // OutputFormat specifies the output format: "text", "json", or "stream-json" OutputFormat *OutputFormat `json:"output_format,omitempty"` // Debug and logging // Debug enables debug mode (shows MCP server errors) Debug *bool `json:"debug,omitempty"` // Verbose enables verbose logging (automatically enabled for stream-json output) Verbose *bool `json:"verbose,omitempty"` // SDK-specific options // AbortController allows cancellation of the query (Go context handles this) // This field is not used directly but kept for API compatibility AbortController interface{} `json:"abort_controller,omitempty"` // Executable specifies a custom path to the Claude Code CLI Executable *string `json:"executable,omitempty"` }
Options represents configuration options for Claude Code queries
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the output format for Claude Code queries
const ( OutputFormatText OutputFormat = "text" OutputFormatJSON OutputFormat = "json" OutputFormatStreamJSON OutputFormat = "stream-json" )
type ProcessError ¶
ProcessError is returned when the CLI process encounters an error
func (*ProcessError) Error ¶
func (e *ProcessError) Error() string
type QueryRequest ¶
type QueryRequest struct { // Prompt is the query to send to Claude Code Prompt string `json:"prompt"` // Options contains configuration options for the query Options *Options `json:"options,omitempty"` }
QueryRequest represents a query request compatible with TypeScript/Python SDKs
type ResultMessage ¶
type ResultMessage struct { Subtype string `json:"subtype"` DurationMs int `json:"duration_ms"` DurationAPIMs int `json:"duration_api_ms"` IsError bool `json:"is_error"` NumTurns int `json:"num_turns"` SessionID string `json:"session_id"` TotalCostUSD *float64 `json:"total_cost_usd,omitempty"` Usage *Usage `json:"usage,omitempty"` Result *string `json:"result,omitempty"` CreatedAt time.Time `json:"created_at"` }
ResultMessage represents a result message
func (*ResultMessage) Content ¶
func (m *ResultMessage) Content() []ContentBlock
func (*ResultMessage) Timestamp ¶
func (m *ResultMessage) Timestamp() time.Time
func (*ResultMessage) Type ¶
func (m *ResultMessage) Type() MessageType
type SystemMessage ¶
type SystemMessage struct { Subtype string `json:"subtype"` APIKeySource *string `json:"apiKeySource,omitempty"` Cwd *string `json:"cwd,omitempty"` SessionID string `json:"session_id"` Tools []string `json:"tools,omitempty"` MCPServers []MCPServer `json:"mcp_servers,omitempty"` Model *string `json:"model,omitempty"` PermissionMode *string `json:"permissionMode,omitempty"` CreatedAt time.Time `json:"created_at"` }
SystemMessage represents a system message
func (*SystemMessage) Content ¶
func (m *SystemMessage) Content() []ContentBlock
func (*SystemMessage) Timestamp ¶
func (m *SystemMessage) Timestamp() time.Time
func (*SystemMessage) Type ¶
func (m *SystemMessage) Type() MessageType
type TextBlock ¶
type TextBlock struct {
Text string `json:"text"`
}
TextBlock represents a text content block
func (*TextBlock) Type ¶
func (t *TextBlock) Type() ContentBlockType
type ToolResultBlock ¶
type ToolResultBlock struct { ToolUseID string `json:"tool_use_id"` Content interface{} `json:"content"` IsError bool `json:"is_error,omitempty"` }
ToolResultBlock represents a tool result content block
func (*ToolResultBlock) Type ¶
func (t *ToolResultBlock) Type() ContentBlockType
type ToolUseBlock ¶
type ToolUseBlock struct { ID string `json:"id"` Name string `json:"name"` Input map[string]interface{} `json:"input"` }
ToolUseBlock represents a tool use content block
func (*ToolUseBlock) Type ¶
func (t *ToolUseBlock) Type() ContentBlockType
type UserMessage ¶
type UserMessage struct { ContentBlocks []ContentBlock `json:"content"` ParentToolUseID *string `json:"parent_tool_use_id,omitempty"` SessionID string `json:"session_id"` CreatedAt time.Time `json:"created_at"` }
UserMessage represents a message from the user
func (*UserMessage) Content ¶
func (m *UserMessage) Content() []ContentBlock
func (*UserMessage) Timestamp ¶
func (m *UserMessage) Timestamp() time.Time
func (*UserMessage) Type ¶
func (m *UserMessage) Type() MessageType