Outcome-Attributed Coding Agent Spend Tracking¶
Map coding-agent trace spend many-to-many to pull requests as a diagnostic lens, paired with task stratification, quality checks, and billing reconciliation.
Outcome-attributed coding-agent spend tracking links session traces many-to-many to GitHub pull requests or GitLab merge requests while labeling non-PR sessions by work type (LangChain Blog, 2026-11-18). Use it as an operational diagnostic across multi-agent fleets, subject to four conditions: stratify comparisons by task type, pair spend with review and defect checks, reconcile trace estimates against contracted or seat billing, and forbid using it as an individual productivity target.
Why raw token totals fail¶
High-level usage analytics and token totals do not show what spend produced (LangChain Blog, 2026-11-18). Across eight frontier LLMs using OpenHands on SWE-bench Verified, input tokens dominated overall cost even with caching enabled. In the Claude Sonnet 4.5 phase analysis, accumulated context made cache reads cost more in aggregate than output tokens despite their lower per-token price (Bai et al., arXiv:2604.22750v3). Across the eight models, runs on the same task varied by up to 30× in total tokens. More tokens did not reliably improve accuracy, which often peaked at intermediate cost and leveled off or fell at higher costs (Bai et al., arXiv:2604.22750v3).
Claude Code sends the conversation history with every request, including requests carrying batches of tool results. With prompt caching, it reads that history at the cached rate, so even a one-line question in an all-day session draws usage for the whole conversation (Claude Code Docs). Raw totals mix shipped work, abandoned attempts, and runaway context loops into one figure.
The attribution model¶
LangSmith for Coding Agents attributes trace spend to GitHub pull requests or GitLab merge requests in a many-to-many mapping (LangChain Blog, 2026-11-18). One thread can open several pull requests, and one pull request can take several threads to finish.
graph TD
T[Agent threads] --> M{Linked to PR/MR?}
M -->|Yes, many-to-many| S[PR state: open, closed, merged]
M -->|No| U[Unattributed spend]
U --> W[Work-type label: review, investigation]
S --> D[Thread drill-down]
W --> D
The model partitions spend along three cuts (LangChain Blog, 2026-11-18):
- PR lifecycle state: attributed spend splits into open, closed, and merged pull requests so unresolved or closed work stays visible beside merged code.
- Unattributed spend by work type: sessions that never open a pull request, such as code review and problem investigation, are tracked separately and labeled by work type so useful non-PR work stays visible.
- Multi-agent rollup: traces from Claude Code, OpenAI Codex, Cursor, GitHub Copilot in VS Code, and custom harnesses such as Deep Agents roll up into one dashboard instead of separate vendor consoles.
Operational levers from thread drill-down¶
Every dashboard metric links back to its underlying threads (LangChain Blog, 2026-11-18). Use those threads in four workflows:
- Long-thread coaching: cost-by-thread-length views isolate long sessions where full-context re-sending concentrates spend, reinforcing Anthropic's guidance to clear context with
/clearbetween unrelated tasks (LangChain Blog, 2026-11-18; Claude Code Docs). - Model and subagent checks: compare cost per merged PR before and after changing models. When moving subagents to a smaller tier, use the breakdown by model to check spend and track whether work still merges (LangChain Blog, 2026-11-18).
- Skill audits: trace skill calls alongside thread length and merge outcomes to investigate whether instructions lead to extra turns (LangChain Blog, 2026-11-18). In RQ1, Hu et al. analyzed 1,200 trajectories from four agent configurations on 300 SWE-bench Verified tasks. Across configurations, subsumed retrieval, similar script generation, and test re-execution together affected 79.00–98.00% of tasks and accounted for 6.86–22.75% of task monetary cost. The separate RQ2–RQ3 mitigation evaluation used over 10,000 trajectories on held-out SWE-bench Verified and Pro tasks. In that evaluation, developer-designed high-level skills reduced cost by up to 41.73% (Hu et al., arXiv:2609.30725v3).
- Shared engineering and finance reporting: showing cost per merged PR next to unattributed spend gives finance a unit-cost figure while letting engineering open the underlying threads when spend moves (LangChain Blog, 2026-11-18).
Why it works¶
Outcome-attributed tracking closes the feedback loop between context accumulation and repository artifacts. Because human-rated task difficulty only weakly aligns with actual token costs on SWE-bench Verified (Bai et al., arXiv:2604.22750v3), teams cannot tell from spend spikes alone whether delivery volume grew or an agent entered redundant loops. Joining session traces many-to-many with PR lifecycle states and work-type labels partitions aggregate spend into inspectable buckets linked directly to transcripts (LangChain Blog, 2026-11-18). Teams can then test habit, skill, or model changes against merge outcomes instead of raw token volume.
When this backfires¶
Outcome-attributed spend breaks down when treated as a standalone ROI score or a performance target:
- Performance targeting: using cost per merged PR as an individual or team target penalizes non-PR work such as code review and investigation, which LangChain explicitly notes can be sound unattributed spend (LangChain Blog, 2026-11-18), and treats merge rate as code quality despite construct-validity limits (Pinna et al., arXiv:2602.08915v2).
- Unstratified before-and-after comparisons: across 7,156 PRs from five coding agents in the AIDev dataset, acceptance rates spanned a 29pp gap across task types (84.0% for chore versus 55.4% for perf). Within the same study, Claude Code's task mix shifted +18.4pp toward
featand −23.0pp away fromdocsbetween early and late periods, though the authors caution that Claude Code results rest on only 139 PRs (Pinna et al., arXiv:2602.08915v2). Unstratified before-and-after PR averages can confound model changes with workload shifts. - Ignoring review and defect costs: PR acceptance does not equal code quality because merged PRs may contain bugs (Pinna et al., arXiv:2602.08915v2). In a Monte Carlo simulation across 432 scenarios, escaped bugs were the dominant cost driver, an average of 61% of agent spend went to bug-finding roles, and developer costs exceeded agent costs in 65% of optimal teams with a median agent-to-developer cost ratio of 0.32 (Herbold, arXiv:2610.20394v1). In Hu et al.'s SWE-bench Verified and Pro evaluation, CodeGraph, a structure-aware retrieval tool, added retrieval overhead in some Mini-SWE-Agent settings and shifted work away from cheaper subagents in Claude Code. The largest end-to-end cost increase was 28.14%, for Mini-SWE-Agent with MiniMax-M3 on held-out Verified tasks (Hu et al., arXiv:2609.30725v3).
- Unreconciled billing rates: Claude Code defaults to list price for local and OpenTelemetry cost estimates. Administrators can use
modelPricingin v2.1.242 or later to report contracted rates without changing billing. Usage inside a Teams or Enterprise seat allowance is not metered in dollars (Claude Code Docs). - Heavy non-PR workflows: investigation and code review can create useful work without a linked PR (LangChain Blog, 2026-11-18). Use shared work-type labels so PR-centered views do not hide that work.
Where developer salaries and escaped-bug remediation dominate total cost (Herbold, arXiv:2610.20394v1), coarse org or workspace budget caps via a centralized LLM gateway paired with periodic trace audits avoid per-PR instrumentation overhead.
Example¶
LangSmith for Coding Agents connects traces to pull requests in three steps: install the tracing plugin for each coding agent, connect GitHub, and open the coding agent overview page (LangChain Blog, 2026-11-18). In Claude Code, install the plugin inside a session:
/plugin marketplace add langchain-ai/langsmith-claude-code-plugins
/plugin install langsmith-tracing@langsmith-claude-code-plugins
/reload-plugins
Engineering then inspects the cost-by-thread-length and PR-state views to locate uncleared sessions or expensive closed PRs, and opens the linked threads to see whether context clearing, a skill rewrite, or a model change explains the spend (LangChain Blog, 2026-11-18).
Key Takeaways¶
- Keep cost per merged PR strictly as a thread-drill-down diagnostic rather than an individual target or a proxy for code quality.
- Report unattributed spend labeled by work type beside PR-attributed spend so code review and investigation stay visible to finance.
- Stratify before-and-after model or skill rollouts by task type so workload shifts do not masquerade as model gains or regressions.
- Reconcile trace-estimated dollar figures against contracted API rates and flat-rate seat allowances before using them in financial reporting.
Related¶
- Total Cost Accounting per Accepted Software Factory Change — full-cost accounting ledger including failed attempts and human repair
- Agent Spend Is Set by Velocity, Not by Agent Payoff — why project velocity sets spend while agent capability decides payoff
- Reading a Vendor-Computed AI Coding ROI Dashboard — how to read cohort-level vendor ROI panels without trusting modeled throughput
- Cost-Aware Tracing for Skill Distillation — per-step USD cost and counterfactual redundancy flags for pruning skills
- Centralized LLM Gateway for Per-Dimension Agent Budgets — enforcing spend caps by organization, workspace, user, and API key