usage

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(sessions []*SessionData, projectRoot string) *types.UsageInsights

Aggregate combines parsed session data into UsageInsights

func AnalyzeUsage

func AnalyzeUsage(ctx context.Context, projectPath string, opts Options) (*types.UsageInsights, error)

AnalyzeUsage discovers and parses Claude Code session logs for a project, returning aggregated usage insights.

func ClaudeProjectsDir

func ClaudeProjectsDir() string

ClaudeProjectsDir returns the base directory for Claude Code project logs

func DiscoverProjectDir

func DiscoverProjectDir(absPath string) string

DiscoverProjectDir finds the Claude Code project directory for a given project path. Returns the full path to the directory under ~/.claude/projects/, or empty string if not found.

func DiscoverSessions

func DiscoverSessions(projectDir string, since time.Time) ([]string, error)

DiscoverSessions lists JSONL session files in a Claude project directory. If since is non-zero, only files modified after that time are returned.

func DiscoverSubagents

func DiscoverSubagents(projectDir, sessionID string) ([]string, error)

DiscoverSubagents lists subagent JSONL files for a given session. Session directories are named by UUID and contain a subagents/ subdirectory.

func EncodeProjectPath

func EncodeProjectPath(absPath string) string

EncodeProjectPath converts an absolute project path to Claude's encoded directory name. Claude Code encodes paths by replacing "/" and "." with "-": /Users/foo.bar/project → -Users-foo-bar-project

Types

type Options

type Options struct {
	Since            time.Time
	IncludeSubagents bool
	MaxWorkers       int // 0 = NumCPU
}

Options controls usage analysis behavior

type ParseOptions

type ParseOptions struct {
	Since time.Time // Skip entries before this time
}

ParseOptions controls parsing behavior

type SessionData

type SessionData struct {
	ID         string
	ToolEvents []ToolEvent
	TokenStats []TokenRecord
	TurnCount  int
	StartTime  time.Time
	EndTime    time.Time
}

SessionData holds parsed data from a single JSONL session file

func ParseSession

func ParseSession(ctx context.Context, path string, opts ParseOptions) (*SessionData, error)

ParseSession parses a single JSONL session file and extracts usage data. It streams the file line-by-line to handle large files efficiently.

type TokenRecord

type TokenRecord struct {
	Model               string
	InputTokens         int64
	OutputTokens        int64
	CacheCreationTokens int64
	CacheReadTokens     int64
}

TokenRecord holds token counts from a single assistant message

type ToolEvent

type ToolEvent struct {
	Name     string // Read, Edit, Bash, Write, Glob, Grep, Task, etc.
	FilePath string // extracted from input.file_path (empty for non-file tools)
	Model    string
}

ToolEvent represents a single tool invocation extracted from assistant content

Jump to

Keyboard shortcuts

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