---
title: "Attribute the cost of every agent session · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale/agent-cost-attribution
id: AID-68
level: Recommended
updated: 2026-10-22
tokens: 881
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Attribute the cost of every agent session

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Running agents at scale](https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: AID-68
- Level: Recommended
- Chapter: [Running agents at scale](https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale.md)
- Rule: Tag every agent session with the person, the team and the task. Report the cost per team and per merged agent change every month.
- 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.
- How: [Cap what agents can spend](https://agentwranglers.se/playbook/ai-assisted-development/safety-and-permissions/agent-spend-limits.md) 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](https://agentwranglers.se/playbook/ai-assisted-development/safety-and-permissions/managed-agent-settings.md). Divide by merged changes with the agent trailer, because total spend says little about value.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```bash
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"
```

## Sources

- [Claude Code, monitoring](https://code.claude.com/docs/en/monitoring-usage)
- [OpenTelemetry resource semantic conventions](https://opentelemetry.io/docs/specs/semconv/resource/)

## Related rules

- AID-62 [Cap what agents can spend](https://agentwranglers.se/playbook/ai-assisted-development/safety-and-permissions/agent-spend-limits.md) in AI-assisted development
- AID-33 [Enforce the team's agent settings centrally](https://agentwranglers.se/playbook/ai-assisted-development/safety-and-permissions/managed-agent-settings.md) in AI-assisted development

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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.

- Previous: [Split work between agents by files and merge through one lead](https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale/multi-agent-split.md)
- Next: [Roll agents out to a team in steps](https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale/agent-rollout.md)
- [Running agents at scale](https://agentwranglers.se/playbook/ai-assisted-development/running-agents-at-scale.md)
