Skip to content

[BUG] Agent/Explore subagent crashes with "Cannot read properties of undefined (reading 'input_tokens')" #34899

@a1506578383

Description

@a1506578383

Bug Description

When using the Agent tool (with subagent_type: Explore or general-purpose), the call consistently fails with:

Error: Cannot read properties of undefined (reading 'input_tokens')

All basic tools (Glob, Grep, Read, Bash, Edit, Write) work fine. Only the Agent/subagent invocations are affected.

Steps to Reproduce

  1. Start a Claude Code CLI session (v2.1.76)
  2. Trigger any task that invokes the Agent tool, e.g.:
    • subagent_type: Explore — for codebase exploration
    • subagent_type: general-purpose — for multi-step research
  3. The agent call fails immediately with the error above
  4. Retrying produces the same error every time

Expected Behavior

The subagent should launch, perform its task, and return results.

Actual Behavior

The subagent call fails instantly with:

Error: Cannot read properties of undefined (reading 'input_tokens')

No partial results are returned. The error appears to originate from response parsing logic where the API response object's usage or usage.input_tokens field is undefined.

Environment

  • Claude Code version: 2.1.76 (latest on npm as of 2025-03-16)
  • OS: Windows 11 Home China (10.0.26200)
  • Node.js: v22.22.1
  • Shell: Git Bash (MINGW64)
  • Model: claude-opus-4-6

Workaround

Avoid using Agent/Explore subagents entirely. Use Glob, Grep, and Read tools directly for codebase searches. This works but loses the parallelism and autonomy benefits of subagents.

Additional Context

  • The error is 100% reproducible — every Agent call fails, not intermittent.
  • Network connectivity is fine (all other API calls succeed).
  • This may be related to how subagent API responses are parsed — possibly a missing null check on response.usage before accessing input_tokens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agentsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:windowsIssue specifically occurs on Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions