cli

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cli provides CLI discovery, version validation, and command building for the Claude Code CLI binary.

This package provides three main capabilities:

CLI Discovery

The Discoverer interface locates and validates the Claude CLI binary:

discoverer := cli.NewDiscoverer(&cli.Config{
    CliPath: "",           // Optional explicit path
    Logger:  slog.Default(),
})
cliPath, err := discoverer.Discover(ctx)

Discovery searches in the following order:

  1. Explicit path in Config.CliPath (if provided)
  2. System PATH
  3. Common installation directories (/usr/local/bin, /usr/bin, ~/.local/bin)

Version Validation

During discovery, the CLI version is validated against MinimumVersion (2.0.0). A warning is logged if the version is below minimum. Version checking can be skipped via Config.SkipVersionCheck or the CLAUDE_AGENT_SDK_SKIP_VERSION_CHECK environment variable.

Command Building

The package provides functions to build CLI command arguments and environment:

args := cli.BuildArgs("prompt", options, isStreaming)
env := cli.BuildEnvironment(options)

Index

Constants

View Source
const (
	// MinimumVersion is the minimum required Claude CLI version.
	MinimumVersion = "2.0.0"

	// VersionCheckTimeout is the timeout for the CLI version check command.
	VersionCheckTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

func BuildArgs

func BuildArgs(
	prompt string,
	options *config.Options,
	isStreaming bool,
) []string

BuildArgs constructs the CLI command arguments.

When isStreaming is true, uses --input-format stream-json and omits the prompt from command line arguments (prompt comes via stdin instead).

func BuildEnvironment

func BuildEnvironment(options *config.Options) []string

BuildEnvironment constructs the environment variables for the CLI process.

Types

type Command

type Command struct {
	// Args are the command line arguments.
	Args []string

	// Env are the environment variables.
	Env []string
}

Command represents the CLI command to execute.

type Config

type Config struct {
	// CliPath is an explicit CLI path that skips PATH search.
	// If empty, discovery will search PATH and common locations.
	CliPath string

	// SkipVersionCheck skips version validation during discovery.
	// Can also be controlled via CLAUDE_AGENT_SDK_SKIP_VERSION_CHECK env var.
	SkipVersionCheck bool

	// Logger is an optional logger for discovery operations.
	// If nil, a default no-op logger is used.
	Logger *slog.Logger
}

Config holds configuration for CLI discovery.

type Discoverer

type Discoverer interface {
	// Discover locates the Claude CLI binary and validates its version.
	// Returns the absolute path to the CLI binary or an error.
	Discover(ctx context.Context) (string, error)
}

Discoverer locates and validates the Claude CLI binary.

func NewDiscoverer

func NewDiscoverer(cfg *Config) Discoverer

NewDiscoverer creates a new CLI discoverer with the given configuration.

Jump to

Keyboard shortcuts

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