Answer: Read cost data from every result message, whether its subtype is success or an error subtype, and account from total_cost_usd or modelUsage rather than usage. After a session crash, recover totals from the result of the turn before the crash, or fall back to summing the usage on the assistant messages. Status: Confirmed Entry: tool/claude-code/troubleshooting/costs-on-failures-and-crashes Revision: 2 Digest: sha256:37611fbe446e7a4c (changes whenever the content changes) Timeline: Created: 2026-11-15T12:15:52Z Last changed: 2026-11-17T12:20:23Z (crash recovery step 2: — → Sum the `usage` on the assistant messages instead, counting each API response once) Last verified: 2026-11-20T12:16:26Z Next check: 2026-11-21T12:16:26Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of failed conversation tracking | Read cost data from every result message, whether its `subtype` is `success` or one of the error subtypes. | [1] | 2026-11-20 preferred cost source | account from `total_cost_usd` or `modelUsage` rather than `usage` | [1] | 2026-11-20 crash result subtype | error_during_execution | [1] | 2026-11-20 crash recovery step 1 | Use the result of the turn before the crash. | [1] | 2026-11-20 crash recovery step 2 | Sum the `usage` on the assistant messages instead, counting each API response once | [1] | 2026-11-20 fallback limitation | Subagent usage isn't recoverable this way, and neither are output tokens or USD cost | [1] | 2026-11-20 budget error behavior | `usage` leaves out the response that crossed the budget, while `total_cost_usd` and `modelUsage` include it | [1] | 2026-11-20 Sources: [1] Anthropic. "Track cost and usage". https://code.claude.com/docs/en/agent-sdk/cost-tracking.md Role: primary. Accessed: 2026-11-20T12:16:26Z Quote: "Read cost data from every result message, whether its `subtype` is `success` or one of the error subtypes." (Supports: failed conversation tracking) Quote: "Where you have the choice, account from `total_cost_usd` or `modelUsage` rather than `usage`." (Supports: preferred cost source) Quote: "it emits a final `error_during_execution` result and exits" (Supports: crash result subtype) Quote: "Use the result of the turn before the crash." (Supports: crash recovery step 1) Quote: "Sum the `usage` on the assistant messages instead, counting each API response once" (Supports: crash recovery step 2) Quote: "Subagent usage isn't recoverable this way, and neither are output tokens or USD cost" (Supports: fallback limitation) Quote: "`usage` leaves out the response that crossed the budget, while `total_cost_usd` and `modelUsage` include it" (Supports: budget error behavior) Published: 2026-11-20T02:52:51Z Snapshot SHA-256: 33162fd50e80cef6285d81742eaf4629de96a5a4354ab5f2e147dfb8a83af0d7 (captured 2026-11-17T12:20:22Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-17T12:20:23Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:16:26Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:16:26Z Last attempt: 2026-11-20T12:16:26Z Notes and limitations: Extracted automatically from a single official source (section "Handle errors, caching, and output token counts"). Related: https://latestn.com/tool/claude-code/troubleshooting/cross-session-messaging-availability What Claude Code versions and platforms are required for cross-session messaging? https://latestn.com/tool/claude-code/troubleshooting/deep-link-opens-home-directory Why does my Claude Code deep link open in my home directory instead of the repo? https://latestn.com/tool/claude-code/troubleshooting/disable-uninstall-security-plugin How do I disable or uninstall the security-guidance plugin in Claude Code? https://latestn.com/tool/claude-code/troubleshooting/check-loaded-context How do I check which CLAUDE.md, settings, hooks, or MCP servers actually loaded in Claude Code? https://latestn.com/tool/claude-code/troubleshooting/configure-tmux How do I configure Claude Code to work properly inside tmux? https://latestn.com/tool/claude-code/troubleshooting/confirm-hipaa-configuration How do I confirm the HIPAA configuration is applied on a developer's computer? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-17T12:20:23Z | changed | crash recovery step 2: — → Sum the `usage` on the assistant messages instead, counting each API response once | [1] 2026-11-17T12:20:23Z | changed | crash recovery step 1: — → Use the result of the turn before the crash. | [1] 2026-11-17T12:20:23Z | changed | fallback limitation: This gives you the main loop's input and cache tokens. → Subagent usage isn't recoverable this way, and neither are output tokens or USD cost | [1] 2026-11-17T12:20:23Z | changed | recovery step 2: Sum the `usage` on the assistant messages instead, counting each API response once → — | [1] 2026-11-17T12:20:23Z | changed | recovery step 1: Use the result of the turn before the crash. → — | [1] 2026-11-15T12:15:52Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/troubleshooting/costs-on-failures-and-crashes/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/troubleshooting/costs-on-failures-and-crashes POST: https://latestn.com/dispute/tool/claude-code/troubleshooting/costs-on-failures-and-crashes with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/troubleshooting/costs-on-failures-and-crashes?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I track costs on failed conversations or recover totals after a session crash in the Claude Agent SDK? Revision 2, last verified 2026-11-20T12:16:26Z. https://latestn.com/tool/claude-code/troubleshooting/costs-on-failures-and-crashes (accessed 2026-11-21T10:06:24Z). @misc{LatestN_tool_claude_code_troubleshooting_costs_on_failures_and_crashes_r2, title = {How do I track costs on failed conversations or recover totals after a session crash in the Claude Agent SDK?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/troubleshooting/costs-on-failures-and-crashes}}, note = {Revision 2; digest sha256:37611fbe446e7a4c; last verified 2026-11-20T12:16:26Z; accessed 2026-11-21T10:06:24Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/troubleshooting/costs-on-failures-and-crashes