Skip to content

feat: token usage tracking with JSONL tailer and Supabase storage#16

Merged
DarlingtonDeveloper merged 3 commits into
mainfrom
feat/token-usage-tracking
Feb 16, 2026
Merged

feat: token usage tracking with JSONL tailer and Supabase storage#16
DarlingtonDeveloper merged 3 commits into
mainfrom
feat/token-usage-tracking

Conversation

@DarlingtonDeveloper

Copy link
Copy Markdown
Collaborator

Summary

  • Adds JSONL file tailer that reads anthropic-payload.jsonl, accumulates per-session token/cost data, and flushes to Postgres (Supabase) every 30s
  • CC sidecar swarm.cc.session.completed events enrich rows with duration, exit code, and files changed via EnrichSession upsert
  • Usage API on admin mux (:9090) exposes /api/usage/summary, /api/usage/agent/{id}, /api/usage/model/{id}, and /api/usage/cost-efficiency/{id} for Dispatch routing
  • Both tailer and sidecar use INSERT ON CONFLICT upserts that don't overwrite each other's fields — order-independent row convergence

New packages

Package Purpose
internal/store UsageStore interface, PostgresStore (pgxpool), EnsureSchema migration
internal/tailer JSONL tailer with offset persistence, in-memory accumulators, periodic flush
internal/usage HTTP API handlers mounted on admin mux behind existing auth

Modified files

  • internal/config/config.goDatabaseURL, UsageConfig (enabled, jsonl_path, flush/poll intervals), WARREN_DATABASE_URL env override
  • internal/process/subscriber.gousageStore field, enrichSession() called from completed/failed handlers
  • cmd/orchestrator/main.go — wires store → schema → tailer → usage handlers → subscriber

Test plan

  • go build ./... — clean
  • go vet ./... — clean
  • All existing tests pass (39 tests across admin, config, process, etc.)
  • New unit tests: store types (4), tailer (8 including offset persistence, truncation detection, flush), usage handlers (9 including method validation, range parsing), config usage (3 including env override)
  • Integration: run with Supabase, verify sessions appear via curl localhost:9090/api/usage/summary?range=30d
  • Verify enrichment: trigger CC session completion, check completed_at/duration_ms/exit_code populated

🤖 Generated with Claude Code

DarlingtonDeveloper and others added 3 commits February 16, 2026 00:58
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>
@DarlingtonDeveloper DarlingtonDeveloper merged commit 77441e3 into main Feb 16, 2026
2 checks passed
@DarlingtonDeveloper DarlingtonDeveloper deleted the feat/token-usage-tracking branch February 16, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant