economics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package economics provides Claude Code spending vs savings analysis.

Combines ccusage (tokens spent) with tokman tracking (tokens saved) to provide dual-metric economic impact reporting with weighted cost-per-token calculations.

Index

Constants

View Source
const (
	WeightOutput      = 5.0  // Output = 5x input
	WeightCacheCreate = 1.25 // Cache write = 1.25x input
	WeightCacheRead   = 0.1  // Cache read = 0.1x input
)

API pricing ratios (verified Feb 2026, consistent across Claude models <=200K context) Source: https://docs.anthropic.com/en/docs/about-claude/models

Variables

This section is empty.

Functions

func Run

func Run(opts RunOptions) error

Run executes the economics analysis and displays results

Types

type DayStats

type DayStats struct {
	Date        string
	Commands    int
	SavedTokens int
	SavingsPct  float64
}

DayStats represents daily tracking stats (simplified from tracking package)

type MonthStats

type MonthStats struct {
	Month       string
	Commands    int
	SavedTokens int
	SavingsPct  float64
}

MonthStats represents monthly tracking stats

type PeriodEconomics

type PeriodEconomics struct {
	Label string

	// ccusage metrics (Option for graceful degradation)
	CCCost         *float64
	CCTotalTokens  *uint64
	CCActiveTokens *uint64 // input + output only (excluding cache)

	// Per-type token breakdown
	CCInputTokens       *uint64
	CCOutputTokens      *uint64
	CCCacheCreateTokens *uint64
	CCCacheReadTokens   *uint64

	// tokman metrics
	TMCommands    *int
	TMSavedTokens *int
	TMSavingsPct  *float64

	// Primary metric (weighted input CPT)
	WeightedInputCPT *float64 // Derived input CPT using API ratios
	SavingsWeighted  *float64 // saved * weighted_input_cpt (PRIMARY)

	// Legacy metrics (verbose mode only)
	BlendedCPT     *float64 // cost / total_tokens (diluted by cache)
	ActiveCPT      *float64 // cost / active_tokens (OVERESTIMATES)
	SavingsBlended *float64 // saved * blended_cpt (UNDERESTIMATES)
	SavingsActive  *float64 // saved * active_cpt (OVERESTIMATES)
}

PeriodEconomics represents economics data for a single time period

type RunOptions

type RunOptions struct {
	Daily   bool
	Weekly  bool
	Monthly bool
	All     bool
	Format  string // "text", "json", "csv"
	Verbose bool
}

RunOptions configures the economics report

type Totals

type Totals struct {
	CCCost           float64
	CCTotalTokens    uint64
	CCActiveTokens   uint64
	CCInputTokens    uint64
	CCOutputTokens   uint64
	CCCacheCreate    uint64
	CCCacheRead      uint64
	TMCommands       int
	TMSavedTokens    int
	TMAvgSavingsPct  float64
	WeightedInputCPT *float64
	SavingsWeighted  *float64
	BlendedCPT       *float64
	ActiveCPT        *float64
	SavingsBlended   *float64
	SavingsActive    *float64
}

Totals represents aggregated economics across all periods

type WeekStats

type WeekStats struct {
	WeekStart   string
	Commands    int
	SavedTokens int
	SavingsPct  float64
}

WeekStats represents weekly tracking stats

Jump to

Keyboard shortcuts

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