claudecode

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package claudecode implements the TermmuxDriverAdapter for Claude Code CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatSessionLogPath

func FormatSessionLogPath(configDir, cwd, sessionID string) string

FormatSessionLogPath returns the session log path for given parameters.

func MakeOtelConfig

func MakeOtelConfig(endpoint string) map[string]string

MakeOtelConfig creates an OTEL endpoint-aware config for the child process env.

func ParseSessionLog

func ParseSessionLog(reader io.Reader) ([]driver.ConversationEntry, error)

ParseSessionLog reads Claude Code's session.jsonl format and returns canonical conversation entries.

func WriteSessionLog

func WriteSessionLog(entries []driver.ConversationEntry, w io.Writer) error

WriteSessionLog writes canonical conversation entries back into Claude Code's session.jsonl format.

Types

type Driver

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

Driver implements TermmuxDriverAdapter for Claude Code CLI.

func New

func New() *Driver

New creates a new Claude Code driver.

func (*Driver) BuildCommandArgs

func (d *Driver) BuildCommandArgs(prependArgs, extraArgs []string) []string

BuildCommandArgs builds the CLI arguments for launching Claude Code.

func (*Driver) BuildCommandEnvVars

func (d *Driver) BuildCommandEnvVars(runtimeDir string) map[string]string

BuildCommandEnvVars returns environment variables to set for the child process.

func (*Driver) Command

func (d *Driver) Command() string

func (*Driver) DiscoveredSessionID

func (d *Driver) DiscoveredSessionID() string

DiscoveredSessionID returns the session ID discovered from OTEL events.

func (*Driver) Errors

func (d *Driver) Errors() []error

Errors returns any accumulated errors from the event handler.

func (*Driver) EventHandler

func (d *Driver) EventHandler() *EventHandler

EventHandler returns the underlying event handler for testing.

func (*Driver) HandleHookEvent

func (d *Driver) HandleHookEvent(eventName string, payload json.RawMessage) bool

HandleHookEvent processes a hook event from Claude Code.

func (*Driver) HandleInterrupt

func (d *Driver) HandleInterrupt() bool

HandleInterrupt handles an interrupt signal.

func (*Driver) Name

func (d *Driver) Name() string

func (*Driver) NativeSessionLogPath

func (d *Driver) NativeSessionLogPath(configDir, cwd, sessionID string) string

NativeSessionLogPath returns the path to Claude Code's native session.jsonl.

func (*Driver) OtelCallbacksForMonitor

func (d *Driver) OtelCallbacksForMonitor(mon *monitor.AgentMonitor) (onLogs, onMetrics, onTraces func(json.RawMessage))

OtelCallbacksForMonitor returns OTEL callbacks that route through the event handler and submit to the monitor.

func (*Driver) ParseSessionLog

func (d *Driver) ParseSessionLog(reader io.Reader) ([]driver.ConversationEntry, error)

ParseSessionLog reads Claude Code's session.jsonl format.

func (*Driver) PrepareForLaunch

func (d *Driver) PrepareForLaunch(dryRun bool) (driver.LaunchConfig, error)

PrepareForLaunch prepares the driver for launch, including config directory setup.

func (*Driver) SessionLogCallbackForMonitor

func (d *Driver) SessionLogCallbackForMonitor(mon *monitor.AgentMonitor) func([]byte)

SessionLogCallbackForMonitor returns a callback that processes session log lines and submits events to the monitor.

func (*Driver) SetConfigDir

func (d *Driver) SetConfigDir(dir string)

SetConfigDir sets the config directory for this driver instance. Called by the session manager before launch.

func (*Driver) Start

func (d *Driver) Start(ctx context.Context, events chan<- monitor.AgentEvent) error

Start begins event processing. The events channel receives normalized events.

func (*Driver) Stop

func (d *Driver) Stop()

Stop stops the driver.

func (*Driver) SupportsHooks

func (d *Driver) SupportsHooks() bool

func (*Driver) SupportsResume

func (d *Driver) SupportsResume() bool

func (*Driver) WriteSessionLog

func (d *Driver) WriteSessionLog(entries []driver.ConversationEntry, writer io.Writer) error

WriteSessionLog writes to Claude Code's session.jsonl format.

type EventHandler

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

EventHandler processes three event sources (OTEL, hooks, session log) and normalizes them into AgentEvents for Claude Code sessions.

func NewEventHandler

func NewEventHandler() *EventHandler

NewEventHandler creates a new Claude Code event handler.

func (*EventHandler) HandleHookEvent

func (eh *EventHandler) HandleHookEvent(eventName string, payload json.RawMessage) []monitor.AgentEvent

HandleHookEvent processes hook events from Claude Code. Returns normalized events for the hook type.

func (*EventHandler) HandleOtelLogs

func (eh *EventHandler) HandleOtelLogs(payload json.RawMessage) []monitor.AgentEvent

HandleOtelLogs processes OTEL log records from Claude Code. Claude Code emits logs for: api_request, api_error, tool_result.

func (*EventHandler) HandleOtelMetrics

func (eh *EventHandler) HandleOtelMetrics(_ json.RawMessage) []monitor.AgentEvent

HandleOtelMetrics processes OTEL metrics — currently a no-op for Claude Code.

func (*EventHandler) HandleOtelTraces

func (eh *EventHandler) HandleOtelTraces(_ json.RawMessage) []monitor.AgentEvent

HandleOtelTraces processes OTEL traces — currently a no-op for Claude Code.

func (*EventHandler) HandleSessionLogLine

func (eh *EventHandler) HandleSessionLogLine(line []byte) []monitor.AgentEvent

HandleSessionLogLine processes a JSONL line from Claude Code's session.jsonl. Extracts assistant message content for the AgentMessage event.

func (*EventHandler) SessionID

func (eh *EventHandler) SessionID() string

SessionID returns the discovered session ID, or empty if not yet known.

Jump to

Keyboard shortcuts

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