feat: Cost by Branch table + CSV export#45
Open
jakduch wants to merge 5 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 namedbranches.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
calcCost()calls pass 6 arguments:(model, inp, out, cache_read, cache_creation, cache_1h)`), not escaped ones (\`)Tests
python3 -m unittest discover -s tests -v— all passingpython3 -m unittest tests.test_browser -v— all passingScope
dashboard.py,scanner.py,cli.py,pricing.py,cowork.py,tests/) — or I've explained below why a new file is neededNotes: adds one new test module
tests/test_cost_by_branch.pycovering the helper and the HTML/JS wiring — same pattern as the other per-feature test files already intests/.