claude-code-cost 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.
@@ -0,0 +1,54 @@
1
+ ---
2
+ description: Bump version, tag, push, and create a GitHub release with auto-generated notes
3
+ argument-hint: "[version e.g. 1.13.0 or rc4]"
4
+ ---
5
+
6
+ # Release
7
+
8
+ Create a new release for this project.
9
+
10
+ ## Inputs
11
+
12
+ - `$ARGUMENTS` — target version or shorthand. Examples:
13
+ - `1.13.0` — full version
14
+ - `rc4` — shorthand for next RC (e.g. if current is `1.19.0-rc.3`, becomes `1.19.0-rc.4`)
15
+ - If not provided, ask the user.
16
+
17
+ ## Steps
18
+
19
+ 1. **Determine version**: Use `$ARGUMENTS` or ask user. Handle `rc<N>` shorthand by reading current version from `package.json` and replacing/appending the RC suffix. Validate it's different from the current version.
20
+
21
+ 2. **Detect prerelease**: If version contains `-rc.`, `-alpha.`, `-beta.`, treat as prerelease.
22
+
23
+ 3. **Check working tree**: Run `git status`. If there are uncommitted changes, warn the user and stop.
24
+
25
+ 4. **Bump version**:
26
+ ```
27
+ npm version <version> --no-git-tag-version
28
+ ```
29
+
30
+ 5. **Commit & push** (push to current branch, not hardcoded `main`):
31
+ ```
32
+ git add package.json package-lock.json
33
+ git commit -m "🔖 chore: Bump version to <version>"
34
+ git push origin HEAD
35
+ ```
36
+
37
+ 6. **Tag & push tag**:
38
+ ```
39
+ git tag v<version>
40
+ git push origin v<version>
41
+ ```
42
+
43
+ 7. **Generate release notes**: Collect commits since the previous tag using `git log --oneline <prev-tag>..HEAD`. Write a **user-facing summary** grouped by:
44
+ - Features (✨) — describe what was added, not raw commit messages
45
+ - Fixes (🐛)
46
+ - Other notable changes
47
+ Include a "Full Changelog" compare link at the bottom.
48
+
49
+ 8. **Create GitHub release** (add `--prerelease` flag for RC/alpha/beta):
50
+ ```
51
+ gh release create v<version> --title "v<version>" --notes "<notes>" [--prerelease]
52
+ ```
53
+
54
+ 9. **Report**: Show the release URL to the user.
@@ -0,0 +1,39 @@
1
+ name: Deploy to GitHub Pages
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ paths:
7
+ - 'docs/**'
8
+ - 'assets/**'
9
+ workflow_dispatch:
10
+
11
+ permissions:
12
+ contents: read
13
+ pages: write
14
+ id-token: write
15
+
16
+ concurrency:
17
+ group: pages
18
+ cancel-in-progress: false
19
+
20
+ jobs:
21
+ deploy:
22
+ environment:
23
+ name: github-pages
24
+ url: ${{ steps.deployment.outputs.page_url }}
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+
29
+ - name: Copy assets into docs for flat serving
30
+ run: cp -r assets docs/assets
31
+
32
+ - uses: actions/configure-pages@v5
33
+
34
+ - uses: actions/upload-pages-artifact@v3
35
+ with:
36
+ path: docs
37
+
38
+ - id: deployment
39
+ uses: actions/deploy-pages@v4
@@ -0,0 +1 @@
1
+ npx @biomejs/biome check --error-on-warnings public/app.js public/style.css
package/CLAUDE.md ADDED
@@ -0,0 +1,42 @@
1
+ # Claude Code Cost Dashboard
2
+
3
+ Cost visualization dashboard for Claude Code usage. Reads JSONL session files from `~/.claude/projects/` and displays costs with top-down drill-down: total → project → session → message.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ npm start # Start server on port 3458
9
+ npm run dev # Start with --open flag
10
+ node server.js --port 3000 --open # Custom port
11
+ ```
12
+
13
+ ## Architecture
14
+
15
+ - **server.js** — Express server with pricing module, JSONL parsing, data aggregation
16
+ - **public/app.js** — Vanilla JS SPA with Chart.js, no build step
17
+ - **public/style.css** — CSS variables, dark/light theme (matches cck + marketplace)
18
+
19
+ ## Data Flow
20
+
21
+ ```
22
+ ~/.claude/projects/**/*.jsonl → server.js (parse + aggregate) → REST API → app.js (render + Chart.js)
23
+ ```
24
+
25
+ ## Pricing
26
+
27
+ Dynamic pricing from LiteLLM (`model_prices_and_context_window.json`). Supports tiered pricing (200k threshold), cache token costs, fast mode multiplier. Offline fallback included.
28
+
29
+ ## Conventions
30
+
31
+ - Vanilla JS only, no frameworks, no build step
32
+ - `#region` markers in all JS/CSS files
33
+ - CSS variables for theming (shared with cck/marketplace)
34
+ - Hub integration via `/hub-config` + `window.__HUB__`
35
+
36
+ ## app.js Regions
37
+
38
+ STATE, UTILS, URL_STATE, FETCH, RENDER_OVERVIEW, RENDER_PROJECTS, RENDER_SESSIONS, RENDER_DETAIL, CHARTS, THEME, ROUTER, TOAST, HUB_INTEGRATION, INIT
39
+
40
+ ## style.css Regions
41
+
42
+ VARIABLES, RESET, SCROLLBAR, TOPBAR, LAYOUT, CARDS, CHARTS, TABLE, BREADCRUMB, DETAIL, LOADING, TOAST, LIGHT_THEME, RESPONSIVE
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Oleksii Nikiforov
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.
@@ -0,0 +1,83 @@
1
+ # Claude Code Cost Dashboard — Planning Context
2
+
3
+ ## What
4
+ Build `claude-code-cost` — a cost dashboard web app for Claude Code Hub. It visualizes Claude Code usage costs with a **top-down drill-down** approach: total costs → per-project → per-session.
5
+
6
+ ## Why
7
+ The ecosystem has 10+ CLI/TUI cost tools (ccusage, ccburn, ccost, tokscale) but **no polished embeddable web dashboard**. This fills that gap as a new tab in Claude Code Hub alongside kanban and marketplace.
8
+
9
+ ## How
10
+
11
+ ### Architecture (match sibling apps exactly)
12
+ Follow the same Express + vanilla JS + no-build-step pattern used by:
13
+ - `../cck/` — kanban app (Express + chokidar + SSE + vanilla JS)
14
+ - `../claude-code-marketplace/` — marketplace app (Express + vanilla JS)
15
+
16
+ Study these reference codebases (available via --add-dir):
17
+ - **Server pattern**: `server.js` with Express, CLI args (--port, --open), `/hub-config` endpoint, static serving
18
+ - **Frontend pattern**: `public/app.js` with #region markers, vanilla JS, HTML string rendering, no frameworks
19
+ - **Theme system**: CSS variables, dark/light toggle, IBM Plex Mono + Playfair Display fonts, orange accent (#e86f33)
20
+ - **Hub integration**: `/hub-config` endpoint, `window.__HUB__`, postMessage forwarding (Ctrl+Alt+Arrow, Alt+1-9)
21
+ - **Real-time updates**: chokidar file watchers + SSE broadcasting (from cck)
22
+
23
+ ### Pricing — CRITICAL
24
+ **DO NOT hardcode model prices.** Study `../ccusage-reference/` source code to understand how ccusage handles pricing dynamically. Use the same approach (whether it's a pricing module, API fetch, or configurable table). The dashboard must stay accurate as models/prices evolve.
25
+
26
+ ### Data Sources (all local filesystem, no external APIs)
27
+
28
+ 1. **~/.claude/projects/{path}/{session-id}.jsonl** — Raw conversation logs. Each assistant message has:
29
+ ```json
30
+ "usage": {
31
+ "input_tokens": 3,
32
+ "cache_creation_input_tokens": 15696,
33
+ "cache_read_input_tokens": 0,
34
+ "output_tokens": 143
35
+ }
36
+ ```
37
+ Plus `model`, `timestamp`, `sessionId`. This is the primary source for accurate cost calculation.
38
+
39
+ 2. **~/.claude/stats-cache.json** — Pre-computed daily aggregates:
40
+ - `dailyActivity[]`: date, messageCount, sessionCount, toolCallCount
41
+ - `dailyModelTokens[]`: date, tokensByModel (model name → total tokens)
42
+
43
+ 3. **~/.claude/usage-data/session-meta/{id}.json** — Per-session metadata:
44
+ - input_tokens, output_tokens, project_path, start_time, duration_minutes
45
+ - tool_counts, first_prompt, uses_mcp, uses_web_search, lines_added/removed
46
+
47
+ 4. **~/.claude/usage-data/facets/{id}.json** — Session quality/outcome metadata
48
+
49
+ ### UI — Top-Down Drill-Down
50
+ The dashboard should flow top-down:
51
+ 1. **Overview cards** — Total cost today/this week/this month, total sessions, total tokens
52
+ 2. **Daily cost trend** — Line/bar chart with 7-day moving average
53
+ 3. **Per-project breakdown** — Table/cards showing cost per project, sortable
54
+ 4. **Per-session details** — Click project to see sessions, click session for message-level cost
55
+ 5. **Supporting charts** — Token breakdown (input/output/cache stacked bar), model distribution (donut), cache efficiency ratio, activity heatmap
56
+
57
+ ### Tech Stack
58
+ - Express.js + chokidar + SSE (server)
59
+ - Vanilla JS with #region markers (frontend)
60
+ - Chart.js via CDN (charts)
61
+ - CSS variables for dark/light theme
62
+ - PWA-ready (manifest.json, sw.js, icons/)
63
+
64
+ ## When (Scope)
65
+ - Plan mode only — design the full implementation plan
66
+ - Core cost dashboard features first
67
+ - Hub integration included from the start
68
+ - No external API dependencies (all local data)
69
+
70
+ ## Target Structure
71
+ ```
72
+ claude-code-cost/
73
+ ├── server.js
74
+ ├── package.json
75
+ ├── CLAUDE.md
76
+ ├── public/
77
+ │ ├── index.html
78
+ │ ├── app.js
79
+ │ ├── style.css
80
+ │ ├── sw.js
81
+ │ ├── manifest.json
82
+ │ └── icons/
83
+ ```
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # Claude Code Cost
2
+
3
+ [![npm version](https://img.shields.io/npm/v/claude-code-cost)](https://www.npmjs.com/package/claude-code-cost)
4
+ [![license](https://img.shields.io/npm/l/claude-code-cost)](LICENSE)
5
+ [![npm downloads](https://img.shields.io/npm/dm/claude-code-cost)](https://www.npmjs.com/package/claude-code-cost)
6
+
7
+ > Know what Claude Code costs you — per day, per project, per session.
8
+
9
+ ## Getting Started
10
+
11
+ ```bash
12
+ npx claude-code-cost --open
13
+ ```
14
+
15
+ Open http://localhost:3458 (or use `--open` to auto-launch the browser).
16
+
17
+ That's it. No hooks, no config — the dashboard reads your existing Claude Code session files.
18
+
19
+ ### Overview
20
+
21
+ ![Overview — Dark](assets/overview-dark.png)
22
+ ![Overview — Light](assets/overview-light.png)
23
+
24
+ ### Projects
25
+
26
+ ![Projects — Dark](assets/projects-dark.png)
27
+ ![Projects — Light](assets/projects-light.png)
28
+
29
+ ### Session Detail
30
+
31
+ ![Session — Dark](assets/session-dark.png)
32
+ ![Session — Light](assets/sesssion-light.png)
33
+
34
+ ## Features
35
+
36
+ - **Top-down drill-down** — Total cost → per project → per session → per message
37
+ - **Dynamic pricing** — Fetches live model prices from [LiteLLM](https://github.com/BerriAI/litellm), supports tiered pricing (200K threshold), cache token costs, and fast mode multipliers
38
+ - **Daily cost chart** — Bar chart with cumulative line, configurable date range (1d / 3d / 7d / 30d / 90d / 1y)
39
+ - **Model distribution** — Donut chart showing cost breakdown by model
40
+ - **Cache efficiency** — Track how well prompt caching is working across your sessions
41
+ - **Project breakdown** — See which projects cost the most, sortable by cost, sessions, or activity
42
+ - **Session detail** — Message-level cost breakdown with cumulative cost and token stacked bar charts
43
+ - **Dark & light theme** — Matches the Claude Code Hub design system
44
+ - **Hub integration** — Works as a tab in Claude Code Hub alongside Kanban and Marketplace
45
+ - **Instant reload** — API responses cached in browser; Refresh button for fresh data
46
+
47
+ ## Configuration
48
+
49
+ ```bash
50
+ PORT=8080 npx claude-code-cost # Custom port
51
+ npx claude-code-cost --open # Auto-open browser
52
+ npx claude-code-cost --dir=~/.claude-work # Custom Claude config dir
53
+ ```
54
+
55
+ If port 3458 is in use, the server falls back to a random available port.
56
+
57
+ ### Global install
58
+
59
+ ```bash
60
+ npm install -g claude-code-cost
61
+ claude-code-cost --open
62
+ ```
63
+
64
+ ## How It Works
65
+
66
+ Claude Code writes conversation logs to `~/.claude/projects/` as JSONL files. Each assistant response includes token counts (`input_tokens`, `output_tokens`, `cache_creation_input_tokens`, `cache_read_input_tokens`) and model info.
67
+
68
+ The dashboard:
69
+ 1. **Reads** JSONL session files (streamed line-by-line for large files)
70
+ 2. **Fetches** live model pricing from LiteLLM (cached 6h, offline fallback included)
71
+ 3. **Calculates** cost per message using tiered pricing with 200K token threshold
72
+ 4. **Aggregates** by day, project, and session — all server-side
73
+ 5. **Renders** with Chart.js — no build step, vanilla JS
74
+
75
+ Nothing is modified — the dashboard is read-only.
76
+
77
+ ### Cost Calculation
78
+
79
+ Uses the same pricing logic as [ccusage](https://github.com/ryoppippi/ccusage):
80
+
81
+ - **Auto mode** — Uses pre-calculated `costUSD` from JSONL when available, otherwise calculates from tokens
82
+ - **Tiered pricing** — Tokens above 200K threshold charged at higher rate (Claude 1M context models)
83
+ - **Fast mode** — Applies provider-specific multiplier for fast/streaming responses
84
+ - **Deduplication** — Skips duplicate messages by `messageId + requestId` hash
85
+
86
+ ## FAQ
87
+
88
+ **Where does pricing data come from?**
89
+ Live from [LiteLLM's pricing dataset](https://github.com/BerriAI/litellm) (2000+ models). Cached for 6 hours. If the fetch fails, a bundled offline snapshot of Claude model prices is used.
90
+
91
+ **Does it work offline?**
92
+ Yes. The offline pricing fallback covers all current Claude models. PWA support included.
93
+
94
+ **Does it modify any files?**
95
+ No. Completely read-only — only reads JSONL files from `~/.claude/projects/`.
96
+
97
+ **Does it work with Claude Code Hub?**
98
+ Yes. Exposes `/hub-config` endpoint and forwards keyboard shortcuts (Ctrl+Alt+Arrow, Alt+1-9) to the hub parent frame.
99
+
100
+ ## License
101
+
102
+ MIT
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/biome.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
3
+ "formatter": {
4
+ "enabled": true,
5
+ "indentStyle": "space",
6
+ "indentWidth": 2,
7
+ "lineWidth": 120
8
+ },
9
+ "linter": {
10
+ "enabled": true,
11
+ "rules": {
12
+ "style": {
13
+ "noDescendingSpecificity": "off"
14
+ },
15
+ "suspicious": {
16
+ "useIterableCallbackReturn": "off"
17
+ }
18
+ }
19
+ },
20
+ "javascript": {
21
+ "formatter": {
22
+ "quoteStyle": "single"
23
+ }
24
+ },
25
+ "css": {
26
+ "formatter": {
27
+ "quoteStyle": "single"
28
+ }
29
+ },
30
+ "files": {
31
+ "includes": ["public/app.js", "public/style.css"]
32
+ }
33
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file