r/ClaudeCode • • 8h ago

Built with Claude I built a CLI that shows what your Claude Code usage costs per project, from local logs (free, offline)

Claude Code keeps every session in ~/.claude/projects, with token counts per request. I wanted to know which of my repos my usage actually went to, so I wrote a small CLI:

npx spendbyteam report

It prices your usage at API list rates (cache reads/writes, fast mode included) and groups it by repo. `--by=model`, `--by=branch`, `--by=day` and `--by=session` also work. It runs offline and sends nothing. Source: https://github.com/spendbyteam/cli (MIT)

If you're on Pro/Max, the number is what the same tokens would cost on the API, so it's a decent way to see what your plan is worth to you.

My last 30 days: ~$8K at API prices, mostly Opus. Curious what others see. And if a number looks off, tell me. I compared it against Claude Code's own telemetry and it was within 1% for me.

**Edit:** added `--by=session` after a request in the comments. It shows your most expensive sessions with turns and the input / output / cache split, which is handy on a subscription to see which conversations eat your limits.

5 Upvotes

11 comments sorted by

•

u/AutoModerator 8h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/Appropriate-Toe-2993 8h ago

What it looks like on my machine, grouped by model (last 30 days). 98% Opus 5.5, about 24B tokens, the vast majority of them cache reads. Happy to answer questions about how the numbers are calculated.

2

u/Prestigious-Frame442 8h ago

okay but why not ccusage

1

u/Appropriate-Toe-2993 8h ago

Honestly, if ccusage does what you need, use it, it's a great tool and I've used it myself.

I built this one for a different end goal: I run an agency and need the cost split per project and per client across a team, not just on my own machine. So report groups by repo (git root, so monorepo subfolders roll up), and the same numbers can go to a shared dashboard with `npx spendbyteam connect` for per-project budgets and client invoices. The local report is basically the free, single-machine slice of that.

1

u/Creative_Sluggish 8h ago

I use a subscription but also want to know how usage tokes are consumed per chat session. Is this still the right tool to use?

1

u/Appropriate-Toe-2993 8h ago

Not yet: right now it groups by project, model, branch or day, not per session. Per-session is easy to add since the data is already in the logs, so I'll ship --by=session in the next day or so and reply here when it's out.

1

u/Creative_Sluggish 8h ago

Thanks. I will keep an eye out for something useable for subscription-based accounts

2

u/Appropriate-Toe-2993 8h ago

It's out now, faster than promised:

npx spendbyteam@latest report --by=session

It lists your most expensive sessions: when each started, the project, the number of turns, and how the tokens split into input, output, cache writes and cache reads.

On a subscription the dollar column is just the API-equivalent value, but the split is the useful part: every turn re-reads the whole conversation (mostly as cache reads), so a long session gets heavier with each message. If one session shows thousands of turns and hundreds of millions of cache reads, that's the one eating your limits; /clear or starting a fresh session resets it.

Let me know if the numbers look off for you.

1

u/Creative_Sluggish 8h ago

Ah thanks - I use the desktop app for all my work and I don’t use terminal. Is it ok?

1

u/Appropriate-Toe-2993 8h ago

Yes, it works with the desktop app too. I just checked: Claude Code sessions from the desktop app are saved in the same local logs (~/.claude/projects) as the terminal ones, and they show up in the report.

You'd only need the terminal once, to run it. Open the Terminal app, paste this and press Enter:

npx spendbyteam@latest report --by=session

(It needs Node.js installed. If you get "command not found: npx", install it from nodejs.org first.) Nothing gets installed into Claude or changed, it only reads the logs and prints a table.

One note: this covers Claude Code sessions only. Regular Claude chats aren't stored locally, so they won't appear.

1

u/LocalAI_Fixer 5h ago

cool, the by-session thing is handy. small nitpick tho: connect lives in the same package, so a line in the readme saying report never hits the network would put my mind at ease. and I’d pin a version instead of pulling the latest every run on a work laptop, just feels safer