Skip to content

feat: Cost by Branch table + CSV export#45

Open
jakduch wants to merge 5 commits into
josepe98:mainfrom
jakduch:feat/cost-by-branch
Open

feat: Cost by Branch table + CSV export#45
jakduch wants to merge 5 commits into
josepe98:mainfrom
jakduch:feat/cost-by-branch

Conversation

@jakduch
Copy link
Copy Markdown
Collaborator

@jakduch jakduch commented May 23, 2026

What does this add and why do you believe it belongs in this dashboard?

Adds a Cost by Branch table (with CSV export) that aggregates sessions by the (project, branch) tuple, surfacing per-git-branch token and cost totals alongside cache-read and cache-creation columns. Unlike the existing Project & Branch card, this view is wired to a dedicated sortable card and a dedicated CSV export named branches.csv, and exposes the cache mix so you can see which branches are hitting the prompt cache versus paying full input cost.

Why it belongs in a personal Claude Code usage dashboard: Claude Code work happens on feature branches, and answering "which branch did I burn the most credits on this week?" is exactly the kind of retrospective a solo developer wants when reviewing their own spend. Per-branch aggregation reveals which feature branches consumed most spend — long-running refactors, exploratory spikes, or a runaway loop on one branch — in a way that project-level totals hide. The CSV export lets you drop the breakdown into a spreadsheet for monthly review or to attach to a client invoice when a branch maps to billable work.

Checklist

Code correctness

  • All calcCost() calls pass 6 arguments: (model, inp, out, cache_read, cache_creation, cache_1h)
  • JavaScript template literals use bare backticks (`), not escaped ones (\`)
  • No JS variables referenced before they are defined
  • No new third-party dependencies introduced

Tests

  • python3 -m unittest discover -s tests -v — all passing
  • python3 -m unittest tests.test_browser -v — all passing
  • New behaviour is covered by at least one test

Scope

  • This is a single concern — one feature or fix per PR
  • Only touches existing files (dashboard.py, scanner.py, cli.py, pricing.py, cowork.py, tests/) — or I've explained below why a new file is needed

Notes: adds one new test module tests/test_cost_by_branch.py covering the helper and the HTML/JS wiring — same pattern as the other per-feature test files already in tests/.

jakduch added 2 commits May 23, 2026 20:45
Adds a new "Cost by Branch" dashboard card that aggregates filtered
sessions by (project, branch) tuple, surfacing cache_read and
cache_creation alongside the existing token + cost columns.

- Python _cost_by_branch(sessions) helper (mirrors the JS version) so
  the aggregation is testable server-side.
- JS _costByBranch() helper, sortable table (all 9 columns), and CSV
  export wired through the existing downloadCSV helper.
- Empty / NULL / whitespace branch values are normalised to
  "(default)" both in HTML and CSV.
- 6 unit tests covering the helper edge cases (empty input, branch
  bucketing, cache-column aggregation, cost-desc sort) plus a
  structural test that the card and JS wiring are present.
@josepe98 josepe98 closed this May 25, 2026
@josepe98 josepe98 reopened this May 25, 2026
@josepe98 josepe98 closed this May 25, 2026
@josepe98 josepe98 reopened this May 25, 2026
@josepe98 josepe98 closed this May 25, 2026
@josepe98 josepe98 reopened this May 25, 2026
@josepe98 josepe98 closed this May 25, 2026
@josepe98 josepe98 reopened this May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants