dev.toJune 5, 2026 AFFECTS EXAM
ModeloAPIPrecio

Claude Agent SDK Cost Tracking — what to do before June 15, 2026

How to measure what your Claude Agent SDK workload really costs before the June 15, 2026 credit change, with code, caveats, and a sizing decision.

---

title: Claude Agent SDK Cost Tracking — what to do before June 15, 2026

published: true

description: How to measure what your Claude Agent SDK workload really costs before the June 15, 2026 credit change, with code, caveats, and a sizing decision.

tags: ai, claude, anthropic, tutorial

canonical_url: https://moeed.app/posts/claude-agent-sdk-cost-tracking/

cover_image: https://moeed.app/posts/claude-agent-sdk-cost-tracking-hero.png

---

On June 15, 2026 Anthropic moves Claude Agent SDK calls, `claude -p`, GitHub Actions, and third-party agents off the subscription pool and onto a separate dollar-denominated credit ($20 Pro, $100 Max 5x, $200 Max 20x), billed at

standard API list prices. Interactive Claude Code in the terminal stays where it is. Everything programmatic moves.

So the question your manager is going to ask the next day stops being "are we within the subscription limit?" and starts being "what did this cost?"

The full guide is on my blog: [Claude Agent SDK Cost Tracking: A Practical Guide (2026)](https://moeed.app/posts/claude-agent-sdk-cost-tracking/). Here is the short version.

## What the SDK gives you

Every `query()` call ends with a `result` message carrying `total_cost_usd` and a `usage` object with token counts. There is also a per-model breakdown so you can see how much went to Opus versus Haiku in the same call. Same data in

TypeScript and Python, slightly different field names.

## The one warning

Anthropic is very direct in the [official docs](https://code.claude.com/docs/en/agent-sdk/cost-tracking): `total_cost_usd` is a client-side estimate from a price table bundled at build time. It can drift from the real bill when:

- pricing changes

- the installed SDK does not recognise a model

- billing rules apply that the client cannot model (the June 15 credit pool, enterprise discounts, surge pricing)

Use the SDK number for budgeting. Use the [Usage and Cost API](https://platform.claude.com/docs/en/build-with-claude/usage-cost-api) or the Console for invoicing.

## A minimum viable cost log

```python

from claude_agent_sdk import query, ResultMessage

import asyncio

async def main():

async for message in query(prompt="Summarise this project"):

if isinstance(message, ResultMessage):

print(f"Estimated cost: ${message.total_cost_usd or 0:.4f}")

asyncio.run(main())

```

Five lines is enough to start. Add a tag for user, model, and feature when you push it into production metrics.

## The duplicate-ID gotcha with parallel tools

When Claude uses multiple tools in parallel within one turn, the SDK emits several assistant messages that share the same `id` with identical usage. If you sum tokens across every assistant message, you triple- or quadruple-count.

Deduplicate by ID before you add:

```typescript

const seenIds = new Set<string>();

let totalInputTokens = 0;

for await (const message of query({ prompt: "..." }))

Read full article on dev.to