MCPcopy Create free account
hub / github.com/betta-tech/byo-coding-agent / cmdTokens

Function cmdTokens

commands.go:61–81  ·  view source on GitHub ↗
(_ string)

Source from the content-addressed store, hash-verified

59}
60
61func cmdTokens(_ string) {
62 stats, ok := rootAgent.Provider.(tokenReporter)
63 if !ok {
64 fmt.Println(ui.Dimmed("this provider doesn't report token usage"))
65 return
66 }
67 u := stats.TotalUsage()
68 cost := stats.EstimatedCostUSD()
69 fmt.Println(ui.Dimmed("session usage:"))
70 fmt.Printf(" input %s\n", ui.Cyan(formatThousands(u.InputTokens)))
71 fmt.Printf(" output %s\n", ui.Cyan(formatThousands(u.OutputTokens)))
72 if u.CacheCreationTokens > 0 || u.CacheReadTokens > 0 {
73 fmt.Printf(" cache write %s\n", ui.Cyan(formatThousands(u.CacheCreationTokens)))
74 fmt.Printf(" cache read %s\n", ui.Cyan(formatThousands(u.CacheReadTokens)))
75 }
76 if cost >= 0 {
77 fmt.Printf(" est. cost %s\n", ui.Cyan(fmt.Sprintf("$%.4f", cost)))
78 } else {
79 fmt.Printf(" est. cost %s\n", ui.Dimmed("(unknown model — no rate)"))
80 }
81}
82
83// formatThousands inserts thousands separators into a non-negative int.
84func formatThousands(n int) string {

Callers

nothing calls this directly

Calls 5

DimmedFunction · 0.92
CyanFunction · 0.92
formatThousandsFunction · 0.70
TotalUsageMethod · 0.65
EstimatedCostUSDMethod · 0.65

Tested by

no test coverage detected