feat: token usage tracking with JSONL tailer and Supabase storage#16
Merged
Conversation
Adds end-to-end token usage tracking: a JSONL file tailer reads the gateway's anthropic-payload.jsonl, accumulates per-session token/cost data, and flushes to Postgres. CC sidecar session events enrich rows with duration, exit code, and files changed. Usage API on the admin mux exposes summary, per-agent, per-model, and cost-efficiency endpoints for Dispatch routing decisions. New packages: internal/store, internal/tailer, internal/usage Modified: config (DatabaseURL, UsageConfig), process/subscriber (EnrichSession), cmd/orchestrator/main.go (wiring) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
anthropic-payload.jsonl, accumulates per-session token/cost data, and flushes to Postgres (Supabase) every 30sswarm.cc.session.completedevents enrich rows with duration, exit code, and files changed viaEnrichSessionupsert:9090) exposes/api/usage/summary,/api/usage/agent/{id},/api/usage/model/{id}, and/api/usage/cost-efficiency/{id}for Dispatch routingINSERT ON CONFLICTupserts that don't overwrite each other's fields — order-independent row convergenceNew packages
internal/storeUsageStoreinterface,PostgresStore(pgxpool),EnsureSchemamigrationinternal/tailerinternal/usageModified files
internal/config/config.go—DatabaseURL,UsageConfig(enabled, jsonl_path, flush/poll intervals),WARREN_DATABASE_URLenv overrideinternal/process/subscriber.go—usageStorefield,enrichSession()called from completed/failed handlerscmd/orchestrator/main.go— wires store → schema → tailer → usage handlers → subscriberTest plan
go build ./...— cleango vet ./...— cleancurl localhost:9090/api/usage/summary?range=30dcompleted_at/duration_ms/exit_codepopulated🤖 Generated with Claude Code