claude

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package claude provides the Claude Code source for agentwatch.

A ClaudeSource discovers sessions by walking a directory of Claude Code project files (typically ~/.claude/projects) and parsing JSONL session logs. Use New with WithRoot to configure the root directory; there are no default paths — consumers choose the location.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) (source.Source, error)

New returns a new ClaudeSource configured by opts.

func Register

func Register(r *source.Registry, opts ...Option) error

Register adds a ClaudeSource constructor to r under the name "claude".

Types

type ClaudeSource

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

ClaudeSource discovers and parses Claude Code JSONL session files. The zero value is usable but will not discover any sessions until configured with a non-empty root via WithRoot.

func (*ClaudeSource) Discover

func (s *ClaudeSource) Discover(ctx context.Context) ([]source.SessionHandle, error)

Discover walks the configured root and returns a SessionHandle for every *.jsonl file found. The session ID is derived from the filename (without the .jsonl extension). StartedAt is set from the file modification time. WorkingDir is populated by decoding the parent directory name (Claude Code encodes project paths by replacing "/" with "-").

When a discover window is set (WithDiscoverWindow), only files whose modification time is within that window are returned. The filter uses the real file mtime on every call (not a cached value) because Claude JSONL files are appended to during a session — their mtime changes without updating the parent directory's mtime.

func (*ClaudeSource) Name

func (s *ClaudeSource) Name() string

Name returns "claude".

func (*ClaudeSource) Parse

Parse reads new JSONL lines from the session file starting at cursor c and returns an incremental SourceUpdate. The cursor encodes a byte offset and the subagent parent map; an empty cursor starts from the beginning.

If a session-end marker for h.ID is found in the configured sessionEndDir, the returned SourceUpdate has Terminal=true and EndReason populated.

If no new data is available, Parse returns a zero SourceUpdate and the unchanged cursor.

type Option

type Option func(*ClaudeSource)

Option configures a ClaudeSource.

func WithDiscoverWindow added in v0.1.2

func WithDiscoverWindow(d time.Duration) Option

WithDiscoverWindow limits discovery to JSONL files whose modification time is within d of the current time. Zero disables age filtering but still uses the efficient directory-mtime-caching walker.

func WithMaxEndMarkerSize

func WithMaxEndMarkerSize(bytes int) Option

WithMaxEndMarkerSize sets the maximum byte size of an end-marker file to accept. Files larger than this are removed from disk without being parsed. Defaults to 4096 bytes.

func WithRoot

func WithRoot(path string) Option

WithRoot sets the root directory to scan for Claude Code session files. Discover walks this directory recursively, collecting all *.jsonl files. If root is empty, Discover returns no sessions.

func WithSessionEndDir

func WithSessionEndDir(path string) Option

WithSessionEndDir sets the directory where Claude Code deposits session-end hook marker files. When set, Parse checks this directory for a matching marker and signals Terminal=true on the SourceUpdate when one is found. The marker file is removed from disk once consumed.

Jump to

Keyboard shortcuts

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