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 ¶
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) Parse ¶
func (s *ClaudeSource) Parse(ctx context.Context, h source.SessionHandle, c source.Cursor) (source.SourceUpdate, source.Cursor, error)
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
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 ¶
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 ¶
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 ¶
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.