claudecode

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAvailable

func CheckAvailable() (string, error)

CheckAvailable verifies the claude CLI is installed and returns its version.

func FindClaudePath

func FindClaudePath() (string, error)

FindClaudePath locates the claude CLI binary. Returns the full path or an error with installation instructions.

Types

type AssistantMessage

type AssistantMessage struct {
	ID      string           `json:"id,omitempty"`
	Role    string           `json:"role,omitempty"`
	Content []ContentBlock   `json:"content,omitempty"`
	Usage   *json.RawMessage `json:"usage,omitempty"`
}

AssistantMessage is the message object inside an assistant event.

type ContentBlock

type ContentBlock struct {
	Type  string `json:"type"`
	Text  string `json:"text,omitempty"`
	ID    string `json:"id,omitempty"`
	Name  string `json:"name,omitempty"`
	Input any    `json:"input,omitempty"`
}

ContentBlock represents a single block of content in a message.

type Event

type Event struct {
	Type     string
	Text     string
	ToolCall *ToolCallInfo
	Thought  string
	Final    *FinalResult
	Error    error
}

Event is the normalized event type consumed by callers, matching the pattern established by the hermes package.

type FinalResult

type FinalResult struct {
	Text       string
	SessionID  string
	DurationMS int
	CostUSD    float64
}

FinalResult holds the completed response from the agent.

type ResultEvent

type ResultEvent struct {
	Type       string  `json:"type"`
	Subtype    string  `json:"subtype"`
	IsError    bool    `json:"is_error"`
	Result     string  `json:"result"`
	StopReason string  `json:"stop_reason,omitempty"`
	DurationMS int     `json:"duration_ms,omitempty"`
	TotalCost  float64 `json:"total_cost_usd,omitempty"`
	SessionID  string  `json:"session_id,omitempty"`
}

ResultEvent is the final event from a claude --output-format json run.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner manages invocations of the claude CLI binary. It supports both single-shot (Ask) and interactive (Talk) modes.

func NewRunner

func NewRunner(debug bool) *Runner

NewRunner creates a runner for the claude CLI. The binary path is resolved lazily on first use if not already set.

func (*Runner) Ask

func (r *Runner) Ask(ctx context.Context, prompt string) (<-chan Event, error)

Ask sends a single question and returns a channel of streaming events. The channel is closed when the response is complete or an error occurs.

func (*Runner) AskSync

func (r *Runner) AskSync(ctx context.Context, prompt string) (string, error)

AskSync sends a prompt and blocks until the full response is available.

func (*Runner) IsRunning

func (r *Runner) IsRunning() bool

IsRunning reports whether the interactive session is alive.

func (*Runner) Prompt

func (r *Runner) Prompt(ctx context.Context, text string) (<-chan Event, error)

Prompt sends a message in an interactive talk session and returns streaming events.

func (*Runner) SetModel

func (r *Runner) SetModel(model string)

SetModel overrides the model for claude CLI invocations.

func (*Runner) StartTalk

func (r *Runner) StartTalk(ctx context.Context) error

StartTalk launches an interactive session using claude's stdin streaming. The process stays alive across multiple Prompt() calls.

func (*Runner) Stop

func (r *Runner) Stop() error

Stop gracefully shuts down the interactive session.

type StreamEvent

type StreamEvent struct {
	Type    string `json:"type"`
	Subtype string `json:"subtype,omitempty"`

	// Present when Type == "system" && Subtype == "init"
	SessionID string   `json:"session_id,omitempty"`
	Model     string   `json:"model,omitempty"`
	Tools     []string `json:"tools,omitempty"`

	// Present when Type == "assistant"
	Message *AssistantMessage `json:"message,omitempty"`

	// Present when Type == "result"
	Result     string  `json:"result,omitempty"`
	IsError    bool    `json:"is_error,omitempty"`
	StopReason string  `json:"stop_reason,omitempty"`
	DurationMS int     `json:"duration_ms,omitempty"`
	TotalCost  float64 `json:"total_cost_usd,omitempty"`
}

StreamEvent represents a single line of output from claude --output-format stream-json.

type ToolCallInfo

type ToolCallInfo struct {
	Name  string
	Input string
}

ToolCallInfo holds details about a tool invocation by the agent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL