Skip to content
Leashr
Tested

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

shell
node .leashr/bin/mission.js start checkout-refactor --dir .
output
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.

shell
node skills/lsh-cost/scripts/collector.js --dir .

Report

shell
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 prints n/a and 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_usd of claude -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-cap and lsh-audit for the same scope equals this report (tested).

What is measured

NameContent
claude_code.api_requestOne event per request: cost_usd, tokens, model, effort, agent, session, leashr.mission. Primary source.
claude_code.cost.usage, claude_code.token.usageMetrics, 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

FunctionStatusProof
Missions and session bindingTestedskills/lsh-mission/test, skills/lsh-audit/test/mission-attribution.test.js
Collector and reportTested, Claude Code 2.1.310skills/lsh-cost/test/cost.test.js
Cost for Codex, Cursor, AntigravityNot supportedno parser