Documentation
¶
Overview ¶
Package usage locates and parses Claude session JSONL files to extract usage events for manifest items.
Index ¶
- func EncodeRepoPath(repoPath string) string
- func LatestSessionFile(repoPath string) (string, error)
- func LocateSessionFiles(repoPath string, lookbackDays int) ([]string, error)
- func MatchSingleSession(manifest *types.Manifest, sessionFile string) (*types.LastSessionReport, error)
- func MatchUsage(manifest *types.Manifest, sessionFiles []string) (map[string]*types.UsageSummary, []string, error)
- func ParseSessionFile(path string) ([]types.UsageEvent, []string, []string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeRepoPath ¶
EncodeRepoPath converts an absolute repository path into the encoded form that Claude uses when naming project directories.
The encoding replaces every "/" separator with "-" and strips the leading "-" that would otherwise result from the leading "/" in an absolute path.
Example:
/Users/foo/project → Users-foo-project
func LatestSessionFile ¶
LatestSessionFile returns the absolute path of the single newest JSONL session file for repoPath, based on file modification time. It searches the same locations as LocateSessionFiles but applies no date cutoff. Returns ("", nil) when no files are found.
func LocateSessionFiles ¶
LocateSessionFiles returns the absolute paths of all *.jsonl session files belonging to repoPath that were modified within the past lookbackDays days.
Claude stores session files under:
~/.claude/projects/<encoded-repo-path>/*.jsonl
Subagent sessions may reside one level deeper:
~/.claude/projects/<encoded-repo-path>/*/*.jsonl
func MatchSingleSession ¶
func MatchSingleSession(manifest *types.Manifest, sessionFile string) (*types.LastSessionReport, error)
MatchSingleSession parses sessionFile and reports, for each item in manifest, whether it was active in that session.
For Skill/MCP/Hook/Command items a match requires at least one UsageEvent with the same ConfigType and Name. For CLAUDE.md items the same directory-containment logic used by MatchUsage applies: the item is active when any cwd or touched directory in the session is at or beneath the directory that contains the CLAUDE.md file.
Returns (nil, nil) when sessionFile is empty.
func MatchUsage ¶
func MatchUsage( manifest *types.Manifest, sessionFiles []string, ) (map[string]*types.UsageSummary, []string, error)
MatchUsage parses every file listed in sessionFiles, then correlates the extracted usage events with the items declared in manifest.
It returns:
- a map keyed by "Type:Name" → *UsageSummary for every manifest item that was observed at least once (items with no usage are absent from the map),
- the deduplicated list of all cwd values seen across every session file,
- any fatal error encountered (individual parse failures are logged and skipped rather than surfaced here).
CLAUDE.md matching uses directory containment: a CLAUDE.md item is considered "used" in any session whose cwd is equal to, or a subdirectory of, the directory that contains the CLAUDE.md file. Synthetic UsageEvents are generated for these implicit activations.
func ParseSessionFile ¶
ParseSessionFile reads the JSONL file at path and returns all usage events found within it, a deduplicated list of cwd values, and a deduplicated list of directories touched by file-oriented tools (Read, Edit, Write, Glob, Grep).
Lines that cannot be parsed are skipped with a warning; the function never returns a hard error due to individual malformed lines.
Types ¶
This section is empty.