session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatAge

func FormatAge(t time.Time) string

FormatAge returns a human-readable relative time string.

func FormatTokenCount

func FormatTokenCount(n int64) string

FormatTokenCount formats a token count in human-readable form (e.g. 1.2K, 3.5M).

func HasActiveSession

func HasActiveSession(worktreePath string) bool

HasActiveSession checks if a worktree has any Claude session files. This is a lightweight check - it doesn't verify if the session is running.

func IsProcessRunning

func IsProcessRunning(sessionID string) bool

IsProcessRunning checks if a Claude process is running for the given session ID by looking for a process whose command line contains the session ID.

func SessionFilePath

func SessionFilePath(worktreePath, sessionID string) string

SessionFilePath returns the full filesystem path for a session .jsonl file.

func ShortenModel

func ShortenModel(model string) string

ShortenModel shortens a Claude model identifier. "claude-opus-4-6" -> "opus-4-6", "claude-sonnet-4-5-20250929" -> "sonnet-4-5"

Types

type Session

type Session struct {
	ID       string `json:"id"`
	Modified int64  `json:"modified_epoch"`
	ModHuman string `json:"modified"`
	Size     int64  `json:"size"`
	SizeStr  string `json:"size_str"`
}

Session represents a Claude Code session file.

func FindSessions

func FindSessions(worktreePath string) ([]Session, error)

FindSessions finds Claude sessions for a worktree path by scanning ~/.claude/projects/<encoded-path>/*.jsonl files.

type SessionDetail

type SessionDetail struct {
	Session
	Model      string     `json:"model"`
	Tokens     TokenUsage `json:"tokens"`
	Running    bool       `json:"running"`
	LastActive time.Time  `json:"last_active"`
	AgeStr     string     `json:"age_str"`
}

SessionDetail extends Session with parsed token usage and process status.

type TokenUsage

type TokenUsage struct {
	InputTokens              int64 `json:"input_tokens"`
	OutputTokens             int64 `json:"output_tokens"`
	CacheCreationInputTokens int64 `json:"cache_creation_input_tokens"`
	CacheReadInputTokens     int64 `json:"cache_read_input_tokens"`
}

TokenUsage holds aggregated token counts from a session.

func ParseSessionDetailFull

func ParseSessionDetailFull(path string) (model string, tokens TokenUsage, err error)

ParseSessionDetailFull reads the entire session file and sums up all token usage. Slower but accurate for total counts.

func ParseSessionDetailTail

func ParseSessionDetailTail(path string) (model string, tokens TokenUsage, err error)

ParseSessionDetailTail reads the last tailSize bytes of a session file and extracts the model and most recent token usage. This is fast but may not capture all token usage from long sessions.

Jump to

Keyboard shortcuts

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