ccmeter

package
v0.0.0-...-ae4eaf2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 32 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main()

Main runs the ccmeter command line. It reads os.Args so the root main.go stays a thin entry point over this package.

Types

type Account

type Account struct {
	Cfg AccountConfig
	// contains filtered or unexported fields
}

Account holds the parsed usage of one config dir and scans it incrementally: each .jsonl file is read from where the last scan stopped.

func (*Account) Scan

func (a *Account) Scan(cutoff time.Time)

Scan reads new lines from the account's projects/ folder. Files last modified before cutoff are skipped, and so are entries older than cutoff, except that a tracked account counts those towards its all-time ledger.

type AccountConfig

type AccountConfig struct {
	Name string `json:"name"`
	Dir  string `json:"dir"`
	// Optional limits, in equivalent API cost (USD). When zero, the meter
	// falls back to your own 30-day peak for the 5-hour window.
	BlockLimitUSD  float64 `json:"block_limit_usd,omitempty"`
	WeeklyLimitUSD float64 `json:"weekly_limit_usd,omitempty"`
	// Archived keeps the account and its history but leaves it out of the
	// table, the dashboard and background plan-limit checks.
	Archived bool `json:"archived,omitempty"`
}

AccountConfig describes one Claude Code account, identified by its config dir.

type AccountDetail

type AccountDetail struct {
	Summary
	AllTime *AllTime     `json:"all_time,omitempty"`
	Setup   AccountSetup `json:"setup"`
	Range   RangeDetail  `json:"range"`
}

AccountDetail is everything the dashboard's account page shows: the same Summary as the overview, plus a breakdown of a chosen range of days.

type AccountInfo

type AccountInfo struct {
	Email             string     `json:"email,omitempty"`
	Name              string     `json:"name,omitempty"`
	Organization      string     `json:"organization,omitempty"`
	Plan              string     `json:"plan,omitempty"` // "Max 5x", "Pro"
	Role              string     `json:"role,omitempty"`
	ExtraUsage        bool       `json:"extra_usage"`
	AccountCreated    *time.Time `json:"account_created,omitempty"`
	SubscriptionSince *time.Time `json:"subscription_since,omitempty"`
	ProfileUpdated    *time.Time `json:"profile_updated,omitempty"`
}

AccountInfo is who an account is logged in as. It comes from the profile Claude Code saves in .claude.json, which holds no login tokens. Only the fields named here are ever read, so nothing else in that file can reach the dashboard.

type AccountSetup

type AccountSetup struct {
	Hooks         bool      `json:"hooks"`
	Plugin        bool      `json:"plugin"`
	StatusLine    bool      `json:"status_line"`
	SettingsError string    `json:"settings_error,omitempty"`
	LastAttempt   time.Time `json:"last_attempt,omitzero"`
	LastOK        time.Time `json:"last_ok,omitzero"`
	NextAllowed   time.Time `json:"next_allowed,omitzero"`
	LastError     string    `json:"last_error,omitempty"`
}

AccountSetup says how plan limits reach this account. It only reports yes or no from settings.json, never the settings themselves.

type AllTime

type AllTime struct {
	Totals
	Since string `json:"since"` // local date of the earliest response, 2006-01-02
}

AllTime is an account's usage over everything ccmeter has seen.

type Block

type Block struct {
	Active       bool      `json:"active"`
	Start        time.Time `json:"start"`
	End          time.Time `json:"end"`
	RemainingMin int       `json:"remaining_min"`
	Totals
	BurnUSDPerHour float64 `json:"burn_usd_per_hour"`
	ProjectedUSD   float64 `json:"projected_usd"`
	LimitUSD       float64 `json:"limit_usd"`
	LimitSource    string  `json:"limit_source"` // "config", "peak" or ""
	Pct            float64 `json:"pct"`
}

type BlockRow

type BlockRow struct {
	Start  time.Time `json:"start"`
	End    time.Time `json:"end"`
	Last   time.Time `json:"last"`
	Active bool      `json:"active"`
	Totals
}

type Config

type Config struct {
	Accounts []AccountConfig `json:"accounts"`
	// Pricing overrides, keyed by a substring of the model name, USD per million tokens.
	Pricing map[string]Price `json:"pricing,omitempty"`
}

Config is the whole ccmeter config file.

type DayPoint

type DayPoint struct {
	Date string `json:"date"`
	Totals
}

type Entry

type Entry struct {
	T     time.Time
	Model string
	In    int64 // input tokens
	Out   int64 // output tokens
	CW5   int64 // cache write, 5-minute TTL
	CW1h  int64 // cache write, 1-hour TTL
	CR    int64 // cache read

	Project string // the log folder under projects/, one per folder a session started in
	Session string // session id, or the log file's name in older logs
}

Entry is one billed assistant response.

func (Entry) Total

func (e Entry) Total() int64

type HourCell

type HourCell struct {
	Weekday int `json:"weekday"`
	Hour    int `json:"hour"`
	Totals
}

HourCell is usage in one hour of one weekday (0 is Sunday), in local time.

type LimitWindow

type LimitWindow struct {
	UsedPct  float64   `json:"used_pct"`
	ResetsAt time.Time `json:"resets_at"`
	// Reset is set when resets_at has passed since the last report, so the
	// saved percentage no longer applies.
	Reset bool `json:"reset,omitempty"`
}

LimitWindow is one plan window as last reported by Claude Code.

type ListedPrice

type ListedPrice struct {
	Name  string    `json:"name"`
	Price PriceView `json:"price"`
}

ListedPrice is one row of a price list.

type ModelLimit

type ModelLimit struct {
	Name string `json:"name"`
	LimitWindow
}

ModelLimit is a weekly limit of its own for one model, such as Fable on a Max plan. Only `claude /usage` reports these, and only on plans that have one.

type ModelRow

type ModelRow struct {
	Model string `json:"model"`
	Totals
	Priced bool `json:"priced"`
}

type Period

type Period struct {
	Totals
	LimitUSD float64 `json:"limit_usd,omitempty"`
	Pct      float64 `json:"pct,omitempty"`
}

type PlanLimits

type PlanLimits struct {
	Source    string       `json:"source"` // "statusline" or "usage-endpoint"
	UpdatedAt time.Time    `json:"updated_at"`
	AgeMin    int          `json:"age_min"`
	FiveHour  *LimitWindow `json:"five_hour,omitempty"`
	SevenDay  *LimitWindow `json:"seven_day,omitempty"`
	Models    []ModelLimit `json:"models,omitempty"`
}

PlanLimits is what the dashboard and table read.

type Price

type Price struct {
	Input        float64 `json:"input"`
	Output       float64 `json:"output"`
	CacheWrite   float64 `json:"cache_write,omitempty"`    // 5-minute cache write (default 1.25x input)
	CacheWrite1h float64 `json:"cache_write_1h,omitempty"` // 1-hour cache write (default 2x input)
	CacheRead    float64 `json:"cache_read,omitempty"`     // default 0.1x input
}

Price is USD per million tokens. Cache prices default to the standard multipliers of the input price when left at zero.

type PriceView

type PriceView struct {
	Input        float64 `json:"input"`
	Output       float64 `json:"output"`
	CacheWrite   float64 `json:"cache_write"`
	CacheWrite1h float64 `json:"cache_write_1h"`
	CacheRead    float64 `json:"cache_read"`
}

PriceView is a Price with its cache prices filled in, all of them always sent.

type Pricer

type Pricer struct {
	// contains filtered or unexported fields
}

Pricer resolves a model name to a price. User overrides win (longest matching substring), then the built-in rules.

type PricesReport

type PricesReport struct {
	CheckedOn  string        `json:"checked_on"`
	SourceURL  string        `json:"source_url"`
	ConfigPath string        `json:"config_path"`
	Used       []UsedPrice   `json:"used"`
	Overrides  []ListedPrice `json:"overrides"`
	Builtin    []ListedPrice `json:"builtin"`
}

PricesReport is what the dashboard's Prices page shows.

type ProjectRow

type ProjectRow struct {
	Path string `json:"path"`
	Totals
	Sessions   int       `json:"sessions"`
	LastActive time.Time `json:"last_active"`
}

type RangeDetail

type RangeDetail struct {
	Days int    `json:"days"`
	From string `json:"from"` // first day, 2006-01-02
	To   string `json:"to"`   // today
	Totals
	Daily        []DayPoint   `json:"daily"` // oldest first, every day present
	Models       []ModelRow   `json:"models"`
	Projects     []ProjectRow `json:"projects"`
	Sessions     []SessionRow `json:"sessions"` // most recent first
	SessionCount int          `json:"session_count"`
	Blocks       []BlockRow   `json:"blocks"` // 5-hour windows, most recent first
	Hours        []HourCell   `json:"hours"`  // only the hours with usage
}

RangeDetail covers the last Days calendar days, including today.

type Report

type Report struct {
	GeneratedAt time.Time `json:"generated_at"`
	Accounts    []Summary `json:"accounts"`
	// Archived accounts keep their data but stay out of the totals.
	Archived []Summary `json:"archived,omitempty"`
	Total    struct {
		Today Totals `json:"today"`
		Week  Totals `json:"week"`
		Month Totals `json:"month"`
	} `json:"total"`
}

type SessionRow

type SessionRow struct {
	ID      string `json:"id"`
	Project string `json:"project"`
	Totals
	Models []string  `json:"models"`
	Start  time.Time `json:"start"`
	Last   time.Time `json:"last"`
}

type Summary

type Summary struct {
	Name         string       `json:"name"`
	Dir          string       `json:"dir"`
	Archived     bool         `json:"archived,omitempty"`
	Found        bool         `json:"found"`
	Error        string       `json:"error,omitempty"`
	Files        int          `json:"files"`
	LastActivity *time.Time   `json:"last_activity,omitempty"`
	Block        Block        `json:"block"`
	Today        Period       `json:"today"`
	Week         Period       `json:"week"`  // rolling 7 days
	Month        Period       `json:"month"` // rolling 30 days
	Daily        []DayPoint   `json:"daily"` // last 30 days, oldest first
	Models       []ModelRow   `json:"models"`
	Unpriced     []string     `json:"unpriced,omitempty"`
	Account      *AccountInfo `json:"account,omitempty"`    // left out of the status line, which must stay quick
	Plan         *PlanLimits  `json:"plan,omitempty"`       // real plan limits
	PlanError    string       `json:"plan_error,omitempty"` // last fetch problem, if recent
}

type Totals

type Totals struct {
	Input      int64   `json:"input"`
	Output     int64   `json:"output"`
	CacheWrite int64   `json:"cache_write"`
	CacheRead  int64   `json:"cache_read"`
	Tokens     int64   `json:"tokens"`
	CostUSD    float64 `json:"cost_usd"`
	Messages   int     `json:"messages"`
}

type UsedPrice

type UsedPrice struct {
	Model    string     `json:"model"`
	Source   string     `json:"source"` // "override", "builtin", or "" when unpriced
	Match    string     `json:"match,omitempty"`
	Price    *PriceView `json:"price,omitempty"`
	Accounts []string   `json:"accounts"`
	Messages int        `json:"messages"`
	Tokens   int64      `json:"tokens"`
	CostUSD  float64    `json:"cost_usd"`
}

UsedPrice is a model found in the logs and the price ccmeter charges it at.

Jump to

Keyboard shortcuts

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