Repository navigation
Write usage to a ledger other programs can read - #7
Merged
Merged
Conversation
Cost and tokens were counted in memory and nowhere else: e.cost was added up per response and shown in the sidebar, then lost when the app exited. Nothing outside a running teveus could report what a session cost, so a monitor, a script or a spreadsheet had nothing to read. Each billed response now appends one JSON line to ~/.config/teveus/usage.jsonl with the model, the project, the four token counts and the provider's own cost when it reports one. It is append-only so a reader can follow it live, and it lands in the config directory, so TEVEUS_CONFIG moves it along with everything else. History compaction is recorded too. It is a billed request like any other and was previously counted in e.cost but invisible everywhere else. Write errors are swallowed on purpose: the ledger is for reporting, and a read-only config directory must not fail a conversation.
stawan15
force-pushed
the
feat/usage-ledger
branch
from
November 1, 2026 05:27
bc7f4f0 to
2246033
Compare
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.
Cost and tokens were counted in memory and nowhere else:
e.costwas added up per response and shown in the sidebar, then lost when the app exited. Nothing outside a running teveus could report what a session cost, so a menu bar monitor, a script or a spreadsheet had nothing to read.Each billed response now appends one JSON line to
~/.config/teveus/usage.jsonl:{"time":"2026-11-01T05:04:17.798825Z","id":"20261101050417.798825000-api-abc","session":"api-abc","provider":"anthropic","model":"claude-sonnet-5","project":"app","cwd":"/Users/me/app","input":12,"output":340,"cacheRead":29570,"cacheWrite":9140,"cost":0.0342,"subagent":false}TEVEUS_CONFIGmoves it with everything else.e.costbut invisible everywhere else.UsageRecordininternal/agent/usage.gois a contract now that another program reads it, sousage_test.gopins the field names and the shape rather than only the arithmetic.Why this shape
Field names are lowerCamelCase to match what JSON consumers expect, and
modelkeeps teveus'sprovider/model-idform whileprovideris split out beside it. A consumer that needs a bare model id can take the last path segment; one that wants the router can readprovider.Verification
go build ./...,go vet,gofmtclean; fullgo test ./...passes.The reader side is the claude-monitor menu bar app, which shipped this in Claude-Usage-Monitor v0.1.2. It shows nothing for older teveus, which writes no ledger.