Skip to content

Attribution: project + user tags and per-project budgets (burn vs budget) #5941

Description

@vivekchand

Priority: P0 for team use — "what did this project spend on tokens, against its budget?"

Problem

  • "By team" usage (routes/usage.py:3713) groups by a per-runtime team_mapping and falls back to the runtime name (local_store.py:12306). It isn't per project or per user.
  • Per-user/org fields exist only for OTLP (local_store.py:1887).
  • There is a single global budget (routes/alerts.py:818).

Proposal (v1)

  • A project tag on every session, resolved in order: CLAWMETRY_PROJECT env → git remote → cwd root. User = OS user (or OTLP user.email).
  • Budgets per project: an amount and period, with alerts at 50/80/100% and a daily burn chart.
  • CSV export per project and per user (extend /api/usage/export, routes/usage.py:3112).

Done when

  • Two repos on one machine show as two projects with separate spend
  • A budget alert fires in a test at 80%
  • Works for Claude Code, Codex and Copilot sessions

Enterprise planning refinement, 13 September 2026

The specific requirements below refine the original scope and supersede conflicting implementation assumptions. Existing findings and discussion remain available.

Identity and budget refinement

Inspect the shipped principal/owner model and open PR #5204 before changing metadata. That PR extends derived principal inheritance; do not create a competing user/team identity schema or restamp history on every label edit.

Separate organization boundary, human/service principal, project/client engagement and execution/session. OS usernames and OTel email tags are hints, not authoritative tenant membership. Environment/git/cwd-derived project suggestions need source/confidence and a visible unassigned fallback; avoid publishing raw local paths or emails in shared metrics.

  • Authorized mapping supports historical periods and corrections with provenance. Two repos sharing a remote/path naming convention do not silently collapse into one client project.
  • Each budget declares period/timezone/currency and financial basis. Alerts are distinct from routed enforcement; observing spend cannot retroactively prevent a charge.
  • Exports and downstream reports include assigned/unassigned/unpriced amounts and completeness; runtime/gateway overlap follows LiteLLM integration: proxy callback / OTel ingestion + spend-log import #5940 rather than double counting.
  • Test two projects, two users on one host, a service principal, a forged tenant/project claim, a membership change, late events and a period boundary.
  • Cross-team report aggregation/authorization is implemented in the cloud membership/report surfaces; the OSS endpoint continues to persist/query DuckDB facts and gated contracts.

Related #5936/#5937/#5940 and VDI #5942. Run-level token/line totals must not be presented as an individual productivity score.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions