Cost and missions
Claude Code exports its cost estimate through OpenTelemetry. Leashr collects it locally and groups it by mission, model and agent.
Name a mission
node .leashr/bin/mission.js start checkout-refactor --dir .Mission checkout-refactor started.
To attribute OpenTelemetry cost to this mission, start the agent from a shell where:
export OTEL_RESOURCE_ATTRIBUTES="leashr.mission=checkout-refactor"
On Claude Code, "start --claude-local-settings" sets it for every session in this project instead.A mission is a slug ([a-z0-9][a-z0-9._-]{0,63}). Other commands: show, end, env --shell bash|powershell|cmd. A session is bound to one mission for good by the SessionStart hook, so /clear and --resume do not split its cost between two missions. Switching mission from inside a session only affects new sessions.
Never put OTEL_RESOURCE_ATTRIBUTES in the shared .claude/settings.json: it would override every teammate's mission. In the interactive TUI the attribute was not exported in one test (cause not established), so attribution there rests on the session binding.
Collect
Start the collector and keep it running while the agent works. It listens on 127.0.0.1:4318 and accepts OTLP/HTTP JSON only (protobuf is refused with 415). Telemetry must be enabled in your user settings or shell: see Installation.
node skills/lsh-cost/scripts/collector.js --dir .Report
node skills/lsh-cost/scripts/report.js --dir . --mission checkout-refactor- Tables by mission, model, agent and agent name, with requests, tokens and
cost_usd_est. Without a signal it printsn/aand exits 1; it never fills a gap with a price table. - Checks: each table sums to its total, and
--expect <usd>compares with an outside figure (total_cost_usdofclaude -p --output-format json, or the statusline). Exit 3 if a check fails. - Requests are deduplicated by session and request id. The cost reported by
lsh-capandlsh-auditfor the same scope equals this report (tested).
What is measured
| Name | Content |
|---|---|
claude_code.api_request | One event per request: cost_usd, tokens, model, effort, agent, session, leashr.mission. Primary source. |
claude_code.cost.usage, claude_code.token.usage | Metrics, used as a cross-check of the total. |
| Transcript JSONL (fallback) | Tokens only, no cost, internal format that changes between versions. |
In the real sessions of the benchmark, including sessions with a subagent, the lsh-cost total equalled the total cost reported by Claude Code, to within 1e-17 (bench/data/cost-compare.json, summarized in bench/RESULTS.md).
Costs are estimates in USD at API list prices, not an invoice. On a subscription there is no per-token bill.
Limits
- Only Claude Code is collected. Codex and Cursor export tokens or other event names that the collector does not parse: their sessions show no cost. See Limits by agent.
- Requests sent while the collector is stopped are lost for Leashr.
- Nested subagents and a mission changed in the middle of a session are not tested.
- Console exporters print nothing with
--output-format json. Use OTLP.
Status
| Function | Status | Proof |
|---|---|---|
| Missions and session binding | Tested | skills/lsh-mission/test, skills/lsh-audit/test/mission-attribution.test.js |
| Collector and report | Tested, Claude Code 2.1.310 | skills/lsh-cost/test/cost.test.js |
| Cost for Codex, Cursor, Antigravity | Not supported | no parser |