Quick answer
Claude Code stores each project's sessions in a folder derived from the project path under `~/.claude/projects`. Sum the token fields per folder, then apply current rates to input, cache read, cache write, and output. On a subscription, treat the result as a shadow cost rather than a bill.
Attribute the sessions
- List the folders under
~/.claude/projects. - Match each folder to a repository path.
- Sum input, cache read, cache write, and output per folder.
- Exclude sessions that only read a file while working elsewhere.
- Group worktrees under the parent project.
Convert to cost
cost = input * in_rate
+ cache_read * read_rate
+ cache_write * write_rate
+ output * out_rateUse current rates for the model recorded in the log. A single project can contain several models, so apply rates per message rather than to the total.
Compare projects honestly
- Normalise by merged changes, not hours.
- Separate exploration from implementation.
- Track a full week before ranking.
- Note model changes, which can double a line without a behaviour change.
Attribute cost to repositories
Claude Code logs each session with its working directory, so per-project cost is available without guesswork. The error is dividing a monthly total across every repository you touched, which flatters the expensive one and penalises the cheap ones.
- Group sessions by working directory.
- Exclude sessions with no completed work from the numerator.
- Keep tooling and setup work in a separate bucket.
- Divide by completed tasks, not sessions.
UsageAtlas groups local sessions by project over 30 or 90 days. The general formula is in AI coding cost per project.
Questions, answered
Does Claude Code record the project path?
Yes, in the log folder name and in message metadata, which is what makes per-project attribution possible.
Is cost per project real on a subscription?
It is a shadow price. You pay a flat fee, but API rates show what the work would cost metered.
Should cache writes be included?
Yes, at the write rate. Excluding them understates the total.