cctrack 0.4.1__tar.gz → 0.5.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.
@@ -0,0 +1,50 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ cctrack-py is a zero-dependency Python CLI that scans Claude Code JSONL log files and reports token usage and estimated cost. It's a Python port of the Go-based [cctrack dashboard](https://github.com/ksred/cctrack), stripped down to a single command that parses logs and prints a cost report.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ # Install in development mode
13
+ uv pip install -e .
14
+
15
+ # Run the tool
16
+ python -m cctrack
17
+ # or after install:
18
+ cctrack
19
+
20
+ # Run all tests
21
+ python -m pytest tests/
22
+
23
+ # Run a single test
24
+ python -m pytest tests/test_cctrack.py::test_name
25
+
26
+ # Build distribution
27
+ uv build
28
+ ```
29
+
30
+ ## Architecture
31
+
32
+ This is a single-module CLI tool. All logic lives in `src/cctrack/__init__.py`:
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.
35
+ 2. **File discovery** (`default_dirs`, `discover_files`) - Walks `~/.claude/projects/` and `~/.sandy/sandboxes/` for `.jsonl` files.
36
+ 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.
37
+ 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
+ 5. **Aggregation** (`aggregate`) - Buckets events into daily and monthly summaries with token counts and costs.
39
+ 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.
40
+
41
+ Entry point: `cctrack:main` (registered in `pyproject.toml` as a console script).
42
+
43
+ ## Key Design Decisions
44
+
45
+ - Zero external dependencies - stdlib only (json, argparse, subprocess, etc.)
46
+ - 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.
48
+ - `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
+ - Build system is Hatch (`hatchling`)
50
+ - Requires Python 3.10+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cctrack
3
- Version: 0.4.1
3
+ Version: 0.5.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,18 +98,19 @@ 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):
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.
102
102
 
103
- | Model | Input | Output | Cache Read | Cache Write |
104
- |---|---|---|---|---|
105
- | Opus 4.7 / 4.6 / 4.5 | $5.00 | $25.00 | $0.50 | $6.25 |
106
- | Opus 4 / 4.1 | $15.00 | $75.00 | $1.50 | $18.75 |
107
- | Sonnet 4.x / 3.7 | $3.00 | $15.00 | $0.30 | $3.75 |
108
- | Haiku 4.x | $1.00 | $5.00 | $0.10 | $1.25 |
109
- | Haiku 3.5 | $0.80 | $4.00 | $0.08 | $1.00 |
110
- | Haiku 3 | $0.25 | $1.25 | $0.03 | $0.30 |
103
+ | Model | Input | Output | Cache Read | Cache Write 5m | Cache Write 1h |
104
+ |---|---|---|---|---|---|
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 |
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 |
109
+ | Haiku 4.x | $1.00 | $5.00 | $0.10 | $1.25 | $2.00 |
110
+ | Haiku 3.5 | $0.80 | $4.00 | $0.08 | $1.00 | $1.60 |
111
+ | Haiku 3 | $0.25 | $1.25 | $0.03 | $0.30 | $0.50 |
111
112
 
112
- Unknown models fall back to Sonnet rates.
113
+ Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column.
113
114
 
114
115
  ## Origins
115
116
 
@@ -73,18 +73,19 @@ 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):
77
-
78
- | Model | Input | Output | Cache Read | Cache Write |
79
- |---|---|---|---|---|
80
- | Opus 4.7 / 4.6 / 4.5 | $5.00 | $25.00 | $0.50 | $6.25 |
81
- | Opus 4 / 4.1 | $15.00 | $75.00 | $1.50 | $18.75 |
82
- | Sonnet 4.x / 3.7 | $3.00 | $15.00 | $0.30 | $3.75 |
83
- | Haiku 4.x | $1.00 | $5.00 | $0.10 | $1.25 |
84
- | Haiku 3.5 | $0.80 | $4.00 | $0.08 | $1.00 |
85
- | Haiku 3 | $0.25 | $1.25 | $0.03 | $0.30 |
86
-
87
- Unknown models fall back to Sonnet rates.
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.
77
+
78
+ | Model | Input | Output | Cache Read | Cache Write 5m | Cache Write 1h |
79
+ |---|---|---|---|---|---|
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 |
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 |
84
+ | Haiku 4.x | $1.00 | $5.00 | $0.10 | $1.25 | $2.00 |
85
+ | Haiku 3.5 | $0.80 | $4.00 | $0.08 | $1.00 | $1.60 |
86
+ | Haiku 3 | $0.25 | $1.25 | $0.03 | $0.30 | $0.50 |
87
+
88
+ Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column.
88
89
 
89
90
  ## Origins
90
91
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cctrack"
7
- version = "0.4.1"
7
+ version = "0.5.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"