Documentation
¶
Overview ¶
Package tokentracker scans local machine files left behind by LLM CLIs and desktop apps (Claude Code, Codex, ChatGPT, Gemini, ...) and reports how many tokens they've used, broken down by provider and by token type.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Provider Provider
Model string
Time time.Time
Usage TokenUsage
Source string // path to the file this entry was read from
}
Entry is a single usage record read from a provider's local log/history file.
type IncrementalScanner ¶ added in v0.2.0
IncrementalScanner is implemented by Scanners that can skip re-reading files unchanged since a previous scan, given a persistent per-file cache. A Watcher uses this when a registered Scanner implements it, falling back to plain Scan otherwise — which is exactly what a Scanner with nothing to cache (a stub, or one with no local files yet) wants anyway.
type Report ¶
type Report struct {
Entries []Entry
ByProvider map[Provider]TokenUsage
ByTokenType TokenUsage
}
Report aggregates token usage across all detected providers.
func Scan ¶
Scan walks every registered provider's local usage files and returns the combined report, covering every entry ever recorded (not just one day). A provider failing to scan does not stop the others; their errors are joined and returned alongside whatever entries were recovered. Use Report.Day or Report.Filter to narrow the result down to a specific date.
func (Report) ByDay ¶
ByDay buckets every entry into a Report per calendar day, keyed by "2006-01-02" using loc for day boundaries. Pass time.Local to bucket by your machine's local days, or time.UTC to match raw timestamps.
func (Report) Day ¶
Day returns a Report scoped to entries whose timestamp falls on the same calendar day as t, using t's own location to decide day boundaries. Pass time.Now() for "today", or a time.Time constructed for the target date (e.g. time.Date(2026, 7, 15, 0, 0, 0, 0, time.Local)).
type TokenType ¶
type TokenType string
TokenType identifies a category of tokens within a single LLM exchange.
type TokenUsage ¶
TokenUsage holds token counts keyed by TokenType.
func (TokenUsage) Add ¶
func (u TokenUsage) Add(other TokenUsage) TokenUsage
Add returns a new TokenUsage with u and other's counts summed per type. Either receiver may be nil.
func (TokenUsage) Total ¶
func (u TokenUsage) Total() int64
Total returns the sum of all token counts in u.
type Watcher ¶ added in v0.2.0
type Watcher struct {
// contains filtered or unexported fields
}
Watcher wraps the registered Scanners with a persistent, in-memory, per-file cache so repeated Rescan calls over the life of a long-running process — a game or dashboard polling for fresh usage, unlike Scan's documented call-once-and-slice-the-result use — only pay the cost of re-reading files that actually changed since the last call.
A Watcher must be reused across calls (via NewWatcher, once) rather than recreated each time, or there's nothing for it to cache against. Its cache lives only in memory: nothing is persisted to disk, so the first Rescan after a process starts pays the same full-scan cost Scan always does.
func NewWatcher ¶ added in v0.2.0
func NewWatcher() *Watcher
NewWatcher creates a Watcher with an empty cache for each registered provider.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
tokentracker
command
Command tokentracker prints a table of local LLM token usage, for manually exercising the tokentracker package.
|
Command tokentracker prints a table of local LLM token usage, for manually exercising the tokentracker package. |