cctrack 0.5.0__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,9 +31,11 @@ uv build
31
31
 
32
32
  This is a single-module CLI tool. All logic lives in `src/cctrack/__init__.py`:
33
33
 
34
- 1. **Rate card** (`RATES`, `get_rates`, `calculate_cost`, `is_known_model`) - Model-to-price mapping using prefix matching. Order matters: longer/more-specific prefixes must come first (the legacy `claude-opus-4` 15/75 entry must stay below every `claude-opus-4-x`). Unknown models fall back to Sonnet rates and are flagged with `?` in the report.
34
+ 1. **Rate card** (`RATES`, `get_rates`, `calculate_cost`, `is_known_model`) - Model-to-price mapping using prefix matching. Order matters: longer/more-specific prefixes must come first (the legacy `claude-opus-4` 15/75 entry must stay below every `claude-opus-4-x`). Unknown models fall back to Sonnet rates and are flagged with `?` in the report. `get_rates`/`calculate_cost` take the usage date so time-limited `intro` pricing (e.g. Sonnet 5 through 2026-08-31) applies to past usage correctly.
35
+ 1a. **Energy model** (`ENERGY_WH_PER_MTOK`, `estimate_energy_wh`) - Opt-in (`--energy`) order-of-magnitude estimate keyed off each rate entry's `tier`. Deliberately NOT a function of price: both cache-write TTLs use one figure because a 1h write costs more money but the same compute.
35
36
  2. **File discovery** (`default_dirs`, `discover_files`) - Walks `~/.claude/projects/` and `~/.sandy/sandboxes/` for `.jsonl` files.
36
37
  3. **Remote aggregation** (`fetch_remote_jsonl`, `parse_remote_events`, `fetch_remote_hook_data`, `parse_remote_hook_data`) - SSHs to hosts, cats all JSONL logs plus statusline hook data (statusline files, monthly summaries, session baselines) with file separators, parses locally.
38
+ 3a. **Hook parsing** (`parse_hook_rows`, `compute_hook_deltas`, `_cost_increment`) - The hook is authoritative for **cost only**. Its `input_tokens`/`output_tokens`/`cache_*` fields are context-window SNAPSHOTS (`input_tokens` ≈ `cache_read + cache_write`; `output_tokens` is just the last message's), not cumulative — never use them for token counts. `cost_usd` is a per-session running total, but it RESTARTS on resume/compaction and a render can report 0, so deltas walk every row chronologically and treat a meaningful drop as a restart.
37
39
  4. **JSONL parsing** (`parse_lines`, `parse_events`, `dedup_events`) - Extracts `assistant` events with token usage. Deduplicates by `requestId` across all of a host's files (last event wins) — resumed sessions (`--resume`/`--continue`) repeat events with the same `requestId` in new files. Events without `requestId` are never deduped.
38
40
  5. **Aggregation** (`aggregate`) - Buckets events into daily and monthly summaries with token counts and costs.
39
41
  6. **Output** (`print_report`) - Prints current month-to-date summary with projections, daily breakdown, and previous month summaries. Cost is composed **per source** (one source per machine): hook cost where a source has statusline coverage, accuracy-factor-adjusted JSONL cost otherwise, summed per date. The accuracy factor is measured per source over dates strictly after that source's hook install day.
@@ -44,7 +46,9 @@ Entry point: `cctrack:main` (registered in `pyproject.toml` as a console script)
44
46
 
45
47
  - Zero external dependencies - stdlib only (json, argparse, subprocess, etc.)
46
48
  - Deduplication is global per host by `requestId` (last wins) - resumed sessions replay history into new files and must not double count. Cross-host `requestId` collisions can't occur (distinct API calls).
47
- - Hook data is authoritative for cost where present; JSONL-derived cost is an estimate. Never let one machine's hook coverage suppress another machine's JSONL cost - compose per source.
49
+ - Hook data is authoritative for **cost only**; every token count comes from the JSONL logs. Never mix the two in one figure - the hook's token fields are snapshots and would double count against JSONL cache columns.
50
+ - Never let one machine's hook coverage suppress another machine's JSONL cost - compose per source.
51
+ - Cumulative counters from the hook are not monotonic. Any code differencing `cost_usd` must handle restarts (resume/compaction) and zero-valued renders, or whole days silently vanish.
48
52
  - `session-baselines.json` carries each session's rolled-up cumulative across the 90-day retention boundary so straddling sessions aren't re-counted from zero.
49
53
  - Build system is Hatch (`hatchling`)
50
54
  - Requires Python 3.10+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cctrack
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Claude Code cost tracker — scans JSONL logs and reports token usage + estimated cost
5
5
  Project-URL: Homepage, https://github.com/rappdw/cctrack
6
6
  Project-URL: Repository, https://github.com/rappdw/cctrack
@@ -98,19 +98,39 @@ cctrack --install-hook --remote dgx macbook-air
98
98
 
99
99
  ## Rate card
100
100
 
101
- Prices per million tokens, from [Anthropic's pricing page](https://www.anthropic.com/pricing). Cache writes are priced per TTL: 5-minute at 1.25× input, 1-hour at 2× input.
101
+ Prices per million tokens, from [Anthropic's pricing page](https://platform.claude.com/docs/en/about-claude/pricing). Cache writes are priced per TTL: 5-minute at 1.25× input, 1-hour at 2× input.
102
102
 
103
103
  | Model | Input | Output | Cache Read | Cache Write 5m | Cache Write 1h |
104
104
  |---|---|---|---|---|---|
105
105
  | Fable 5 / Mythos 5 | $10.00 | $50.00 | $1.00 | $12.50 | $20.00 |
106
- | Opus 4.8 / 4.7 / 4.6 / 4.5 | $5.00 | $25.00 | $0.50 | $6.25 | $10.00 |
106
+ | Opus 5 / 4.8 / 4.7 / 4.6 / 4.5 | $5.00 | $25.00 | $0.50 | $6.25 | $10.00 |
107
107
  | Opus 4 / 4.1 | $15.00 | $75.00 | $1.50 | $18.75 | $30.00 |
108
- | Sonnet 5 / 4.x / 3.7 | $3.00 | $15.00 | $0.30 | $3.75 | $6.00 |
108
+ | Sonnet 5 (through 2026-08-31) | $2.00 | $10.00 | $0.20 | $2.50 | $4.00 |
109
+ | Sonnet 5 (from 2026-09-01) / 4.x / 3.7 | $3.00 | $15.00 | $0.30 | $3.75 | $6.00 |
109
110
  | Haiku 4.x | $1.00 | $5.00 | $0.10 | $1.25 | $2.00 |
110
111
  | Haiku 3.5 | $0.80 | $4.00 | $0.08 | $1.00 | $1.60 |
111
112
  | Haiku 3 | $0.25 | $1.25 | $0.03 | $0.30 | $0.50 |
112
113
 
113
- Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column.
114
+ Usage is priced with the rates in effect on the day it happened, so time-limited introductory pricing is applied correctly to past usage.
115
+
116
+ Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column — a prompt to update the rate card rather than a silent guess.
117
+
118
+ ## Energy estimate
119
+
120
+ `cctrack --energy` adds an estimated inference energy column (Wh/kWh):
121
+
122
+ ```bash
123
+ cctrack --energy
124
+ ```
125
+
126
+ This is a **rough estimate, not a measurement** — Anthropic does not publish per-token energy figures or model sizes. It is modelled from logged tokens using the published full-stack per-prompt figures the major labs have disclosed (Google: 0.24 Wh median Gemini text prompt; OpenAI: ~0.34 Wh average ChatGPT query — both include accelerator, host, cooling and idle capacity), apportioned across token classes by relative compute cost and scaled by model tier:
127
+
128
+ - **output tokens dominate** — decode is sequential and memory-bandwidth bound
129
+ - **input and cache writes** are prefill: parallel, far cheaper per token
130
+ - **cache reads** skip prefill entirely (~0.1× input)
131
+ - both cache-write TTLs use the same figure — a 1-hour write costs more money but the same compute
132
+
133
+ Treat results as ±1 order of magnitude. It covers datacenter inference only: not model training, and not your own machine. Scale the whole model with `CCTRACK_ENERGY_SCALE=1.5` if you have better numbers for your workload.
114
134
 
115
135
  ## Origins
116
136
 
@@ -73,19 +73,39 @@ cctrack --install-hook --remote dgx macbook-air
73
73
 
74
74
  ## Rate card
75
75
 
76
- Prices per million tokens, from [Anthropic's pricing page](https://www.anthropic.com/pricing). Cache writes are priced per TTL: 5-minute at 1.25× input, 1-hour at 2× input.
76
+ Prices per million tokens, from [Anthropic's pricing page](https://platform.claude.com/docs/en/about-claude/pricing). Cache writes are priced per TTL: 5-minute at 1.25× input, 1-hour at 2× input.
77
77
 
78
78
  | Model | Input | Output | Cache Read | Cache Write 5m | Cache Write 1h |
79
79
  |---|---|---|---|---|---|
80
80
  | Fable 5 / Mythos 5 | $10.00 | $50.00 | $1.00 | $12.50 | $20.00 |
81
- | Opus 4.8 / 4.7 / 4.6 / 4.5 | $5.00 | $25.00 | $0.50 | $6.25 | $10.00 |
81
+ | Opus 5 / 4.8 / 4.7 / 4.6 / 4.5 | $5.00 | $25.00 | $0.50 | $6.25 | $10.00 |
82
82
  | Opus 4 / 4.1 | $15.00 | $75.00 | $1.50 | $18.75 | $30.00 |
83
- | Sonnet 5 / 4.x / 3.7 | $3.00 | $15.00 | $0.30 | $3.75 | $6.00 |
83
+ | Sonnet 5 (through 2026-08-31) | $2.00 | $10.00 | $0.20 | $2.50 | $4.00 |
84
+ | Sonnet 5 (from 2026-09-01) / 4.x / 3.7 | $3.00 | $15.00 | $0.30 | $3.75 | $6.00 |
84
85
  | Haiku 4.x | $1.00 | $5.00 | $0.10 | $1.25 | $2.00 |
85
86
  | Haiku 3.5 | $0.80 | $4.00 | $0.08 | $1.00 | $1.60 |
86
87
  | Haiku 3 | $0.25 | $1.25 | $0.03 | $0.30 | $0.50 |
87
88
 
88
- Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column.
89
+ Usage is priced with the rates in effect on the day it happened, so time-limited introductory pricing is applied correctly to past usage.
90
+
91
+ Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column — a prompt to update the rate card rather than a silent guess.
92
+
93
+ ## Energy estimate
94
+
95
+ `cctrack --energy` adds an estimated inference energy column (Wh/kWh):
96
+
97
+ ```bash
98
+ cctrack --energy
99
+ ```
100
+
101
+ This is a **rough estimate, not a measurement** — Anthropic does not publish per-token energy figures or model sizes. It is modelled from logged tokens using the published full-stack per-prompt figures the major labs have disclosed (Google: 0.24 Wh median Gemini text prompt; OpenAI: ~0.34 Wh average ChatGPT query — both include accelerator, host, cooling and idle capacity), apportioned across token classes by relative compute cost and scaled by model tier:
102
+
103
+ - **output tokens dominate** — decode is sequential and memory-bandwidth bound
104
+ - **input and cache writes** are prefill: parallel, far cheaper per token
105
+ - **cache reads** skip prefill entirely (~0.1× input)
106
+ - both cache-write TTLs use the same figure — a 1-hour write costs more money but the same compute
107
+
108
+ Treat results as ±1 order of magnitude. It covers datacenter inference only: not model training, and not your own machine. Scale the whole model with `CCTRACK_ENERGY_SCALE=1.5` if you have better numbers for your workload.
89
109
 
90
110
  ## Origins
91
111
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cctrack"
7
- version = "0.5.0"
7
+ version = "0.6.0"
8
8
  description = "Claude Code cost tracker — scans JSONL logs and reports token usage + estimated cost"
9
9
  readme = "README.md"
10
10
  license = "MIT"