AID-68Recommended
Attribute the cost of every agent session
Tag every agent session with the person, the team and the task. Report the cost per team and per merged agent change every month.
How to do it
Cap what agents can spend stops a runaway bill, and this rule shows where the money goes. Give each team its own API key or workspace, so the provider's report splits by team. Agent tools that export OpenTelemetry metrics can add tags too. In Claude Code, CLAUDE_CODE_ENABLE_TELEMETRY=1 turns telemetry on, OTEL_RESOURCE_ATTRIBUTES adds team tags, and the metric claude_code.cost.usage counts cost in US dollars. Set those in the central settings from Enforce the team's agent settings centrally. Divide by merged changes with the agent trailer, because total spend says little about value.
Examples
Shell example
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.example.com
export OTEL_RESOURCE_ATTRIBUTES="team.id=checkout,cost_center=eng-42,task.id=SHOP-881"
How to check
Last month's report shows the cost per team and per merged agent change. Spend without a team tag is under 5% of the total.
Sources
Related rules
- AID-62 Cap what agents can spend in AI-assisted development
- AID-33 Enforce the team's agent settings centrally in AI-assisted development
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale/agent-cost-attribution">Agent Wranglers AI-assisted development playbook</a>. In code you write, add a comment next to it with the same link.