cc-logbook 0.0.0-stage → 0.1.0
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.
- package/LICENSE +47 -0
- package/README.md +130 -2
- package/bin/cc-logbook.js +636 -0
- package/package.json +33 -4
- package/site/index.html +566 -0
- package/src/aggregate.js +140 -0
- package/src/aliases.js +30 -0
- package/src/auth.js +115 -0
- package/src/config.js +46 -0
- package/src/cron.js +53 -0
- package/src/git.js +66 -0
- package/src/parse.js +101 -0
- package/src/pricing.js +92 -0
- package/src/serve.js +82 -0
- package/src/sources.js +112 -0
- package/src/store.js +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cc-logbook contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
Portions of src/parse.js and src/pricing.js are
|
|
26
|
+
adapted from cc-spend (https://github.com/TODO/cc-spend), used under the
|
|
27
|
+
MIT License:
|
|
28
|
+
|
|
29
|
+
Copyright (c) TODO cc-spend authors
|
|
30
|
+
|
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
32
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
33
|
+
in the Software without restriction, including without limitation the rights
|
|
34
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
35
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
36
|
+
furnished to do so, subject to the following conditions:
|
|
37
|
+
|
|
38
|
+
The above copyright notice and this permission notice shall be included in all
|
|
39
|
+
copies or substantial portions of the Software.
|
|
40
|
+
|
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
42
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
44
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
45
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
46
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
47
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,131 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cc-logbook
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**A dashboard of your Claude Code token usage: local with zero setup, or synced across every machine you use.**
|
|
4
|
+
|
|
5
|
+
**[Live demo →](https://the-silent-geek.github.io/Claude-code-usage/)** (fake data: 3 machines, 5 projects, 60 days)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx cc-logbook
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
It reads `~/.claude/projects` and opens a dashboard at `http://localhost:4545` with tokens and API-equivalent cost per day, model and project. No account, no network calls, nothing written to disk. Press **Refresh** on the page after more Claude Code work.
|
|
16
|
+
|
|
17
|
+
Just want numbers in the terminal? `npx cc-logbook preview`.
|
|
18
|
+
|
|
19
|
+
On a remote machine, VS Code Remote-SSH forwards the port automatically. Otherwise run `ssh -L 4545:localhost:4545 <host>` and open the URL locally.
|
|
20
|
+
|
|
21
|
+
Needs Node ≥ 18. No dependencies.
|
|
22
|
+
|
|
23
|
+
## Track several machines
|
|
24
|
+
|
|
25
|
+
If you use Claude Code on a laptop, a workstation and some short-lived GPU VMs, sync mode puts them all on one hosted dashboard and keeps each VM's history after it's deleted.
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
npx cc-logbook init
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
On the first machine, `init` does the following:
|
|
32
|
+
|
|
33
|
+
1. **Logs you in to GitHub** if needed, using the GitHub CLI (`gh`). You get a short code, open github.com/login/device on any device (your phone works), and type it in. This works on headless VMs too.
|
|
34
|
+
2. **Creates a private repo** (`cc-logbook-data`) in your account to hold the usage rows, and asks which timezone to count days in.
|
|
35
|
+
3. **Turns on hosting**: GitHub Pages if your plan allows it for private repos, otherwise it prints Cloudflare Pages steps (free).
|
|
36
|
+
4. **Schedules an hourly push** with cron and runs the first one.
|
|
37
|
+
|
|
38
|
+
On every other machine, run `npx cc-logbook init`, choose **existing** and paste the repo URL.
|
|
39
|
+
|
|
40
|
+
For a scheduled job that survives the npx cache being cleared, `init` offers to `npm i -g cc-logbook`.
|
|
41
|
+
|
|
42
|
+
> **About access:** logging in with `gh` gives this machine access to all your GitHub repos. On a shared machine, use the deploy-key option `init` prints instead. It only grants write access to the one data repo.
|
|
43
|
+
|
|
44
|
+
## Commands
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
cc-logbook local dashboard on localhost (default)
|
|
48
|
+
cc-logbook preview totals for today / 7 days / 30 days in the terminal
|
|
49
|
+
cc-logbook init set up sync mode on this machine
|
|
50
|
+
cc-logbook push export + commit + push (what cron runs)
|
|
51
|
+
cc-logbook build aggregate a data repo into site/ (what the data repo's Action runs)
|
|
52
|
+
cc-logbook uninstall remove the cron entry and config (keeps the data repo)
|
|
53
|
+
|
|
54
|
+
--dir [label=]path Claude config dir (repeatable; default ~/.claude, ~/.claude-*, $CLAUDE_CONFIG_DIR)
|
|
55
|
+
--machine <name> machine label (default $CC_LOGBOOK_MACHINE, then config, then hostname)
|
|
56
|
+
--include <prefix> only read projects whose alias starts with prefix (repeatable)
|
|
57
|
+
--days <n> only read the last n days
|
|
58
|
+
--port <n> local mode port (default 4545; tries the next 10 if busy)
|
|
59
|
+
--no-open don't open a browser
|
|
60
|
+
--dry-run push: do everything except write, commit or push
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## How it works
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
LOCAL MODE (default)
|
|
67
|
+
~/.claude/projects ──parse──▶ rows ──aggregate──▶ data.json ──▶ http://127.0.0.1:4545
|
|
68
|
+
|
|
69
|
+
SYNC MODE (optional)
|
|
70
|
+
machine A ─┐ ┌──────── data repo (yours, private) ─────────┐
|
|
71
|
+
machine B ─┼─ cc-logbook push ──git──▶│ data/<machine>/<YYYY-MM>.jsonl │
|
|
72
|
+
machine C ─┘ (cron, hourly) │ cc-logbook.config.json │
|
|
73
|
+
│ .github/workflows/build.yml │
|
|
74
|
+
│ └─ npx cc-logbook build ─▶ site/ ─▶ Pages │
|
|
75
|
+
└─────────────────────────────────────────────┘
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Claude Code keeps a transcript of every session in `~/.claude/projects`. cc-logbook pulls one row per API response out of those transcripts: timestamp, model, project, session and token counts. Both modes share the same parser, aggregation, pricing and dashboard page.
|
|
79
|
+
|
|
80
|
+
**Dedup.** Claude Code writes one response as several transcript lines and copies earlier lines into resumed sessions. Rows are keyed by request id + message id, and repeated keys keep the max of each token count. Rows are deduped again across machines, so a `~/.claude` copied onto a VM isn't counted twice.
|
|
81
|
+
|
|
82
|
+
**Append-only.** In sync mode, `push` never deletes rows. If a VM's logs disappear, everything it already pushed stays. Running it with nothing new produces byte-identical files, so there are no empty commits.
|
|
83
|
+
|
|
84
|
+
## Privacy
|
|
85
|
+
|
|
86
|
+
| Read and exported | Never exported |
|
|
87
|
+
|---|---|
|
|
88
|
+
| Token counts, model id, timestamp | Prompt text, responses, tool inputs |
|
|
89
|
+
| Project alias (`ai-automated`) | File paths, working directories |
|
|
90
|
+
| Session UUID, account label (`default`, `work`) | Home directory, username |
|
|
91
|
+
| Machine label you chose | |
|
|
92
|
+
|
|
93
|
+
Project aliases come from the folder name Claude Code uses for each project. Projects under your home dir become the path relative to it (`/home/you/ai-automated` → `ai-automated`). Anything outside home becomes `other-<hash>`. You can rename aliases in `cc-logbook.config.json` (data repo) or `~/.config/cc-logbook/config.json` (local) without re-exporting. Use `--include` to read only some projects.
|
|
94
|
+
|
|
95
|
+
Local mode binds to `127.0.0.1` only and never writes to disk.
|
|
96
|
+
|
|
97
|
+
## Cost is an estimate
|
|
98
|
+
|
|
99
|
+
The dashboard shows **API-equivalent cost**: what the same tokens would cost at Anthropic API list prices. That includes 5-minute vs 1-hour cache writes and Haiku 5.5's long-prompt tier. It is **not your bill**: Pro, Max and Team plans are billed differently. Unknown models are listed as unpriced, never guessed.
|
|
100
|
+
|
|
101
|
+
## Hosting (sync mode)
|
|
102
|
+
|
|
103
|
+
| Option | Private repo | Cost | Notes |
|
|
104
|
+
|---|---|---|---|
|
|
105
|
+
| GitHub Pages | Needs a paid plan | — | The site is **publicly reachable** even if the repo is private |
|
|
106
|
+
| Cloudflare Pages | ✓ | Free | Build `npx cc-logbook build`, output `site`; add Cloudflare Access to limit who can view |
|
|
107
|
+
| Locally | ✓ | Free | `npx cc-logbook build` in your clone, then serve `site/` |
|
|
108
|
+
|
|
109
|
+
## Scheduling on macOS and Windows
|
|
110
|
+
|
|
111
|
+
`init` installs cron on Linux and macOS. On macOS it also prints a launchd plist if you prefer that. On Windows it prints the `schtasks` command to run. Task Scheduler setup isn't automated.
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
npm test # node:test, no dependencies
|
|
117
|
+
node bin/cc-logbook.js --dir ./sample-logs
|
|
118
|
+
node demo/generate.mjs /tmp/demo && node bin/cc-logbook.js build --root /tmp/demo
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`template/` is the source for the [cc-logbook-data-template](https://github.com/the-silent-geek/cc-logbook-data-template) repo that `init` creates data repos from.
|
|
122
|
+
|
|
123
|
+
Release: `npm pack`, then from another folder `npx ./cc-logbook-<version>.tgz` and `npx ./cc-logbook-<version>.tgz preview`. Then `npm publish`.
|
|
124
|
+
|
|
125
|
+
## Credits
|
|
126
|
+
|
|
127
|
+
Transcript parsing and the pricing table structure are adapted from [cc-spend](https://github.com/TODO/cc-spend) (MIT). Its copyright notice is kept in [LICENSE](LICENSE).
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|