claudeusage

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package claudeusage counts a Claude Code Architect session's own token usage from its transcript. The SessionStart hook records each session's transcript path; orch run complete reads the transcripts of the sessions that ran the run's verbs. The transcript format is internal to Claude Code, so only the versions in verifiedVersions are read; anything else is reported unavailable rather than guessed. Nothing from a transcript but timestamps and token counters ever leaves this package.

Index

Constants

View Source
const (
	ReasonNoSession         = "no-session-recorded"
	ReasonSessionNotUUID    = "session-id-not-uuid"
	ReasonPathUnrecorded    = "transcript-path-unrecorded"
	ReasonTranscriptMissing = "transcript-missing"
	ReasonUnreadable        = "transcript-unreadable"
	ReasonUnparseable       = "transcript-unparseable"
	ReasonUnverifiedVersion = "unverified-claude-code-version"
)

The unavailable reasons a Capture can carry.

View Source
const SessionsDir = ".orchestrator/metrics/claude-sessions"

SessionsDir is where the SessionStart hook records sessions, inside the git-ignored metrics directory. One file per session, named by its UUID.

Variables

This section is empty.

Functions

func RecordSession

func RecordSession(root, sessionID, transcriptPath string, now time.Time) error

RecordSession records sessionID's transcript path under root, replacing an earlier record of the same session atomically, so a concurrent reader sees the old or the new record whole. Sessions never share a file, so sessions starting together cannot overwrite each other. It takes no lock. shortcut: records are never pruned (one small file per session); add pruning if the directory's size ever matters.

func ValidSession

func ValidSession(id string) bool

ValidSession reports whether id is a UUID. Only such an id may name, find or read a file.

Types

type Capture

type Capture struct {
	Session  string
	Counters Counters
	Reason   string
}

Capture is one session's result: Counters when Reason is empty, otherwise nothing but the reason.

func Architect

func Architect(root string, sessions []string, start, end time.Time) []Capture

Architect counts, for each session in sessions, the usage of its own main-conversation assistant messages timestamped within [start, end]. Each message id is counted once across all of the sessions; sessions are taken in sorted order, so a message present in two transcripts counts for the first. A session whose usage cannot be established carries a reason instead and claims no message ids. No sessions at all yields one ReasonNoSession capture.

type Counters

type Counters struct {
	Input, Output, CacheRead, CacheCreation int64
}

Counters are a session's four counted token totals.

Jump to

Keyboard shortcuts

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