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 ¶
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.
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 ¶
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 ¶
ValidSession reports whether id is a UUID. Only such an id may name, find or read a file.
Types ¶
type Capture ¶
Capture is one session's result: Counters when Reason is empty, otherwise nothing but the reason.
func Architect ¶
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.