claudecli

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package claudecli implements provider.Provider by shelling out to the Claude Code CLI (`claude --print`). This uses the user's Max plan authentication from ~/.claude instead of requiring separate API credits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client invokes the claude CLI binary for chat completions.

func New

func New(model string, opts ...Options) *Client

New creates a claude-cli provider with the default timeout. If model is empty, the CLI uses its default.

func NewWithTimeout added in v0.1.8

func NewWithTimeout(model string, timeout time.Duration, opts ...Options) *Client

NewWithTimeout creates a claude-cli provider with a custom timeout. Use this when the provider config specifies timeout_seconds.

func (*Client) Chat

Chat builds a prompt from the request messages, invokes `claude --print`, and returns the CLI output as the assistant response.

Output is read incrementally via pipes instead of CombinedOutput so that the onActivity callback fires as bytes arrive and hung processes are detected early (no output for staleOutputTimeout → cancel).

IMPORTANT: The prompt MUST be sent via stdin, not as a CLI argument. Passing the prompt as an argument causes the CLI to hang indefinitely. --dangerously-skip-permissions is required for headless/non-interactive use. --allowedTools pre-approves tools so the CLI never prompts in headless context. ANTHROPIC_API_KEY must be unset so the CLI uses OAuth (~/.claude) not API credits.

func (*Client) Healthy

func (c *Client) Healthy(ctx context.Context) bool

Healthy returns true if the claude binary is found and responds to --version.

func (*Client) Name

func (c *Client) Name() string

Name returns the provider identifier.

func (*Client) SetOnActivity added in v0.1.13

func (c *Client) SetOnActivity(fn func())

SetOnActivity registers a callback invoked whenever the CLI process produces output bytes. The runner uses this to reset the dispatcher heartbeat timer, proving the session is actively producing tokens.

type Options added in v0.1.16

type Options struct {
	AllowedTools string      // comma-separated tool list (e.g. "Bash,Read,Edit,Write,Glob,Grep")
	MaxTurns     int         // max agentic turns per session; 0 means no limit
	BaseURL      string      // override ANTHROPIC_BASE_URL (e.g. Ollama endpoint)
	Logger       *zap.Logger // structured logger; nil uses nop logger
}

Options configures optional Client parameters.

Jump to

Keyboard shortcuts

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