Documentation
¶
Index ¶
Constants ¶
const LabelMaxLen = 200
LabelMaxLen is the max length of the label string after sanitization.
const TailReadBytes int64 = 64 * 1024
TailReadBytes is the upper bound on how many bytes we read from the end of a JSONL file.
Variables ¶
var ErrSessionEmpty = errors.New("session has no usable content")
ErrSessionEmpty is returned by ParseSessionTail / FindByID when the file exists but has no user message or no extractable label.
var ErrSessionFileMissing = errors.New("session file missing")
ErrSessionFileMissing is returned by FindByID when no JSONL file matches the session id. Callers distinguish this from a file that exists but contains no usable content (see ErrSessionEmpty).
Functions ¶
func CollectJSONLPaths ¶ added in v0.1.1
CollectJSONLPaths walks the projects directory and returns every session JSONL path, excluding agent-*.jsonl. Returned nil when projects dir doesn't exist.
func ExtractText ¶ added in v0.1.4
func ExtractText(raw json.RawMessage, sep string) string
ExtractText returns the concatenated text of a message Content payload. Content may be a bare JSON string or an array of typed blocks; only "text" blocks contribute, joined by sep.
func IterContent ¶ added in v0.1.1
IterContent reads a session JSONL transcript and invokes fn with the extractable text of each user/assistant message. fn can return false to stop early. Non-JSON and non-message lines are skipped silently. Lines longer than 4 MiB are skipped.
func ProjectsDir ¶
ProjectsDir returns the directory where Claude Code stores transcripts. If CLAUDE_CONFIG_DIR is set, it uses $CLAUDE_CONFIG_DIR/projects; otherwise it falls back to ~/.claude/projects.
Types ¶
type Session ¶
type Session struct {
ID string
ProjectDir string
JSONLPath string
CWD string
CWDBasename string
Label string
LastTime time.Time
LastEpoch int64
CWDExists bool
// CWDUnknown is true when the JSONL had no cwd field and the
// directory-name fallback could not be reconciled with the filesystem.
// Callers (resume) refuse to act on these sessions.
CWDUnknown bool
}
Session is a parsed view of one Claude Code session transcript.
func FindByID ¶
FindByID scans every project directory looking for a session whose filename matches the given UUID. Returns ErrSessionFileMissing when no JSONL exists for the id, and ErrSessionEmpty when the file is present but has no usable content.
func ParseSessionTail ¶
ParseSessionTail reads the tail of one JSONL transcript and returns a Session. Returns ErrSessionEmpty when the file exists but has no user message or no extractable label. Returns ErrSessionFileMissing when the file is absent.
func Scan ¶
Scan walks every project directory under ~/.claude/projects and parses each session JSONL in parallel. Sessions returned are sorted by last activity (newest first).
func ScanFiltered ¶
ScanFiltered behaves like Scan but only parses files whose path is in the allow-set. Empty allow returns nothing.