cctrack 0.4.0__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.
- cctrack-0.5.0/CLAUDE.md +50 -0
- {cctrack-0.4.0 → cctrack-0.5.0}/PKG-INFO +16 -12
- {cctrack-0.4.0 → cctrack-0.5.0}/README.md +15 -11
- {cctrack-0.4.0 → cctrack-0.5.0}/pyproject.toml +1 -1
- {cctrack-0.4.0 → cctrack-0.5.0}/src/cctrack/__init__.py +462 -168
- {cctrack-0.4.0 → cctrack-0.5.0}/tests/test_cctrack.py +23 -5
- {cctrack-0.4.0 → cctrack-0.5.0}/tests/test_hook_reporting.py +421 -10
- cctrack-0.4.0/CLAUDE.md +0 -48
- {cctrack-0.4.0 → cctrack-0.5.0}/.github/workflows/ci.yml +0 -0
- {cctrack-0.4.0 → cctrack-0.5.0}/.github/workflows/publish.yml +0 -0
- {cctrack-0.4.0 → cctrack-0.5.0}/.gitignore +0 -0
- {cctrack-0.4.0 → cctrack-0.5.0}/LICENSE +0 -0
- {cctrack-0.4.0 → cctrack-0.5.0}/src/cctrack/__main__.py +0 -0
- {cctrack-0.4.0 → cctrack-0.5.0}/tests/test_hook.py +0 -0
cctrack-0.5.0/CLAUDE.md
ADDED
|
@@ -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.
|
|
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
|
|
@@ -86,27 +86,31 @@ Daily breakdown:
|
|
|
86
86
|
|
|
87
87
|
## Remote aggregation
|
|
88
88
|
|
|
89
|
-
With `--remote`, cctrack SSHs to each host
|
|
89
|
+
With `--remote`, cctrack SSHs to each host and streams back both the JSONL logs and the host's statusline hook data (`~/.claude/cctrack/`) for local parsing, so authoritative hook costs from every machine are summed per day. Requires SSH key auth.
|
|
90
90
|
|
|
91
91
|
```bash
|
|
92
92
|
# Aggregate this machine + DGX server + laptop
|
|
93
93
|
cctrack --remote dgx macbook-air
|
|
94
|
+
|
|
95
|
+
# For accurate aggregate costs, install the hook on each host too
|
|
96
|
+
cctrack --install-hook --remote dgx macbook-air
|
|
94
97
|
```
|
|
95
98
|
|
|
96
99
|
## Rate card
|
|
97
100
|
|
|
98
|
-
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.
|
|
99
102
|
|
|
100
|
-
| Model | Input | Output | Cache Read | Cache Write |
|
|
101
|
-
|
|
102
|
-
|
|
|
103
|
-
| Opus 4 / 4.
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
| Haiku
|
|
107
|
-
| Haiku 3 | $0.
|
|
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 |
|
|
108
112
|
|
|
109
|
-
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.
|
|
110
114
|
|
|
111
115
|
## Origins
|
|
112
116
|
|
|
@@ -61,27 +61,31 @@ Daily breakdown:
|
|
|
61
61
|
|
|
62
62
|
## Remote aggregation
|
|
63
63
|
|
|
64
|
-
With `--remote`, cctrack SSHs to each host
|
|
64
|
+
With `--remote`, cctrack SSHs to each host and streams back both the JSONL logs and the host's statusline hook data (`~/.claude/cctrack/`) for local parsing, so authoritative hook costs from every machine are summed per day. Requires SSH key auth.
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
67
|
# Aggregate this machine + DGX server + laptop
|
|
68
68
|
cctrack --remote dgx macbook-air
|
|
69
|
+
|
|
70
|
+
# For accurate aggregate costs, install the hook on each host too
|
|
71
|
+
cctrack --install-hook --remote dgx macbook-air
|
|
69
72
|
```
|
|
70
73
|
|
|
71
74
|
## Rate card
|
|
72
75
|
|
|
73
|
-
Prices per million tokens, from [Anthropic's pricing page](https://www.anthropic.com/pricing):
|
|
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.
|
|
74
77
|
|
|
75
|
-
| Model | Input | Output | Cache Read | Cache Write |
|
|
76
|
-
|
|
77
|
-
|
|
|
78
|
-
| Opus 4 / 4.
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
| Haiku
|
|
82
|
-
| Haiku 3 | $0.
|
|
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 |
|
|
83
87
|
|
|
84
|
-
Unknown models fall back to Sonnet rates.
|
|
88
|
+
Unknown models fall back to Sonnet rates and are flagged with `?` in the report's Model column.
|
|
85
89
|
|
|
86
90
|
## Origins
|
|
87
91
|
|