claude-code - 💡(How to fix) Fix CCD CycleHealth crashes with "undefined is not an object (evaluating '$.input_tokens')" on API errors [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#60520Fetched 2026-05-20 03:56:28
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

When an API call fails mid-conversation (network hiccup, rate limit, etc.), the CCD CycleHealth component tries to read $.input_tokens from the error response. Error responses don't carry usage stats, so $ is undefined and the read throws — surfacing as "Turn failed / Try sending your message again."

Error Message

When an API call fails mid-conversation (network hiccup, rate limit, etc.), the CCD CycleHealth component tries to read $.input_tokens from the error response. Error responses don't carry usage stats, so $ is undefined and the read throws — surfacing as "Turn failed / Try sending your message again." 2026-05-19 07:42:07 [warn] [CCD CycleHealth] local_324985da-... api_error (success): undefined is not an object (evaluating '$.input_tokens') 2026-05-18 11:32:38 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens') 2026-05-19 07:16:48 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens') 2026-05-19 07:18:36 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens') 2026-05-19 07:25:25 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens') 2026-05-19 07:42:07 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens') The CycleHealth error handler reads $.input_tokens (or destructures { input_tokens } from a usage/response object) without guarding against the case where the API returns an error response rather than a successful streaming response. Error responses don't include a usage block. The error handler should guard against undefined usage data: Retrying the failed turn succeeds in most cases. The bug only fires when an underlying API error occurs; it's a secondary crash on top of the real failure.

Root Cause

Root cause (likely)

Fix Action

Workaround

Retrying the failed turn succeeds in most cases. The bug only fires when an underlying API error occurs; it's a secondary crash on top of the real failure.

Code Example

2026-05-19 07:42:07 [info] [CCD CycleHealth] unhealthy cycle for local_324985da-... (19s, hadFirstResponse=true, reason=api_error)
2026-05-19 07:42:07 [warn] [CCD CycleHealth] local_324985da-... api_error (success): undefined is not an object (evaluating '$.input_tokens')

---

2026-05-18 11:32:38 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:16:48 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:18:36 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:25:25 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:42:07 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')

---

// e.g.:
const inputTokens = $?.input_tokens ?? 0;
RAW_BUFFERClick to expand / collapse

Summary

When an API call fails mid-conversation (network hiccup, rate limit, etc.), the CCD CycleHealth component tries to read $.input_tokens from the error response. Error responses don't carry usage stats, so $ is undefined and the read throws — surfacing as "Turn failed / Try sending your message again."

Environment

  • App version: 1.7196.3 (Windows desktop)
  • OS: Windows 11 Enterprise 10.0.26200
  • Platform: win32 x64
  • Node: 24.15.0

Log evidence

From %APPDATA%\Claude\logs\main.log:

2026-05-19 07:42:07 [info] [CCD CycleHealth] unhealthy cycle for local_324985da-... (19s, hadFirstResponse=true, reason=api_error)
2026-05-19 07:42:07 [warn] [CCD CycleHealth] local_324985da-... api_error (success): undefined is not an object (evaluating '$.input_tokens')

Multiple occurrences across sessions, both on 1.7196.0 and 1.7196.3:

2026-05-18 11:32:38 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:16:48 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:18:36 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:25:25 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')
2026-05-19 07:42:07 [warn] [CCD CycleHealth] ... api_error (success): undefined is not an object (evaluating '$.input_tokens')

Root cause (likely)

The CycleHealth error handler reads $.input_tokens (or destructures { input_tokens } from a usage/response object) without guarding against the case where the API returns an error response rather than a successful streaming response. Error responses don't include a usage block.

Expected behavior

The error handler should guard against undefined usage data:

// e.g.:
const inputTokens = $?.input_tokens ?? 0;

Or check response type before accessing usage fields.

Workaround

Retrying the failed turn succeeds in most cases. The bug only fires when an underlying API error occurs; it's a secondary crash on top of the real failure.

Sentry

Already being reported automatically via Sentry — event IDs visible in local logs (e.g. 0f187b836806476b9c930aad9647485a).

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The error handler should guard against undefined usage data:

// e.g.:
const inputTokens = $?.input_tokens ?? 0;

Or check response type before accessing usage fields.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix CCD CycleHealth crashes with "undefined is not an object (evaluating '$.input_tokens')" on API errors [1 participants]