[BUG] Cost tracking understates actual spend — sideQuery/classifier tokens and background subagent costs excluded from /cost

Resolved 💬 2 comments Opened Apr 5, 2026 by Kamlesh364 Closed May 27, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The /cost command understates actual Anthropic API spend across four scenarios:

  1. sideQuery/classifier tokens not tracked — Auto-mode permission checks, memory scanning, session

search, and the permission explainer all use sideQuery(), a separate API call path that deliberately
skips addToTotalSessionCost(). Every auto-mode tool approval makes a real billable API call that
never appears in /cost.

  1. Background subagent costs not rolled up — Subagents spawned with run_in_background=true run in

a separate process with isolated cost state. Their token usage never reaches the parent session's cost
tracker.

  1. Session cost history silently discarded on ID mismatchrestoreCostStateForSession() silently

returns undefined when lastSessionId doesn't match, with no warning. Concurrent sessions or any ID
mismatch causes prior cost history to be lost without notice.

  1. Unknown model pricing falls back silently — Custom models set via ANTHROPIC_MODEL fall back to

the default model's pricing rate. The hasUnknownModelCost flag is set but the displayed dollar
figure is still wrong rather than shown as unknown.

What Should Happen?

  • sideQuery calls should be tracked separately (e.g. "internal overhead") or clearly documented with an

estimated overhead note shown in /cost

  • Background subagent costs should be aggregated back to the parent session on completion
  • Session ID mismatch on restore should display a warning that prior cost history could not be

recovered

  • Unknown model cost should display as "unknown" rather than a misleading wrong number

Error Messages/Logs

Steps to Reproduce

For issue #1 (classifier tokens):

  1. Run claude with --auto flag
  2. Give it a task that triggers many tool calls
  3. Compare /cost output against your Anthropic usage dashboard — actual spend will be higher

For issue #2 (background subagents):

  1. Use the Agent tool with run_in_background=true
  2. Let the subagent complete
  3. Check /cost in parent session — subagent token usage is absent

For issue #3 (session ID mismatch):

  1. Open two Claude Code sessions in the same project directory concurrently
  2. Let both accumulate costs
  3. Close one and resume — prior cost data from the overwritten session is silently gone

For issue #4 (unknown model):

  1. Set ANTHROPIC_MODEL=any-unknown-model-name
  2. Run a query and check /cost
  3. Cost shown uses default model rates with no indication of which rate was applied

Claude Model

None

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.1.92

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Root cause references (from source):

  • src/utils/permissions/permissions.ts:766 — explicit comment: "sideQuery does NOT call addToTotalSessionCost"
  • src/utils/sideQuery.ts — no addToTotalSessionCost call anywhere in the file
  • src/cost-tracker.ts:93 — silent undefined return on session ID mismatch
  • src/utils/modelCost.ts:158 — unknown model falls back to default model pricing

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗