claude

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package claude drives the claude CLI as a subprocess and parses its stream-json output into a plain text reply.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFinalMessage

func ParseFinalMessage(jsonlOutput string) (string, error)

Types

type LoginStatusReport

type LoginStatusReport struct {
	Command     string
	LoggedIn    bool
	AuthMethod  string
	APIProvider string
	Output      string
}

LoginStatusReport holds the result of a Claude CLI login status check.

func CheckLogin

func CheckLogin(command string, timeout time.Duration) (LoginStatusReport, error)

CheckLogin runs "claude auth status" and returns the login state. If timeout is zero or negative, a 15-second default is used.

type Runner

type Runner struct {
	Command      string
	Timeout      time.Duration
	Env          map[string]string
	WorkspaceDir string
}

Runner executes the claude CLI for a single request.

func (Runner) Run

func (r Runner) Run(ctx context.Context, userText string) (string, error)

Run is a convenience wrapper that runs without thread resumption or progress callbacks.

func (Runner) RunWithThreadAndProgress

func (r Runner) RunWithThreadAndProgress(
	ctx context.Context,
	threadID string,
	userText string,
	model string,
	env map[string]string,
	onProgress func(step string),
	onRawEvent func(kind, line, detail string),
) (string, string, int64, int64, int64, error)

RunWithThreadAndProgress runs the claude CLI and returns the final assistant reply and the session ID to use for subsequent calls.

  • threadID: resume an existing session when non-empty.
  • userText: the fully assembled prompt (no further template rendering is done).
  • model: overrides the CLI default when non-empty.
  • env: merged over the process environment.
  • onProgress: called with each intermediate assistant message; may be nil.
  • onRawEvent: optional callback for raw stdout events (kind, line, detail); nil disables raw event delivery.

Jump to

Keyboard shortcuts

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