[BUG] API Error: Cannot read properties of undefined (reading 'map') when AI responds without tool calls

Resolved 💬 2 comments Opened Oct 23, 2025 by Moondear Closed Oct 23, 2025

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?

## 🐛 Bug Description

When the AI assistant responds with text indicating it will perform an action (e.g., "Let me create this for you:") but
doesn't immediately invoke a tool, the backend throws an API error:

``
API Error: Cannot read properties of undefined (reading 'map')
``

## 📋 Environment

  • Claude Code Version: [Latest as of 2025-01-23]
  • Operating System: Windows 11
  • Node.js: v22.2.0
  • Python: 3.12.3
  • Project: Qwen-Agent Pediatric QA System

What Should Happen?

The backend should handle AI responses gracefully even when they don't contain tool calls. It should either:

  1. Parse the text-only response without errors
  2. Return an empty array [] when no tool calls are found (instead of undefined)
  3. Display a proper error message to the user if tool calls were expected but missing

Expected behavior: The conversation continues normally, and the AI's text response is displayed without throwing a
JavaScript error.

Error Messages/Logs

API Error: Cannot read properties of undefined (reading 'map')

  Context:
  - User asked: "确认了没有文档编写员。让我查看一下项目经理配置中提到的标准流程,看看文档编写员的定位:"
  - AI used Grep tool to search for "文档编写员"
  - AI responded: "非常好!我发现项目经理和测试工程师的配置中都提到了文档编写员,但这个 Agent 还没有被创建。让我为你创建这个
  Subagent:"
  - Response ended without

Steps to Reproduce

### Reproduction Steps

  1. Setup: Create a project with .claude/agents/ directory containing at least one agent configuration file that

references a non-existent agent.

  1. Create test files:

```bash
mkdir -p .claude/agents

  1. Create a file .claude/agents/project-manager.md with content that references a missing agent:

# Project Manager Agent

## Standard Workflow

  1. [Knowledge Organizer] Collect resources
  2. [Backend Designer] Design logic
  3. [Documentation Writer] Update docs # ← References non-existent agent
  4. Start Claude Code in this project directory
  5. Send this message to Claude:

Check if we have a "Documentation Writer" agent configured in .claude/agents/

  1. Claude searches using Grep tool:

pattern: "Documentation Writer"
path: ".claude/agents"

  1. Claude responds with text like:

"I found that project-manager mentions Documentation Writer,
but the file doesn't exist. Let me create it for you:"

  1. Critical: The AI response **ends without any `

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.0.25 (Claude Code)

Claude Code Version

2.0.25 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

### Reproduction Steps

  1. Setup: Create a project with .claude/agents/ directory containing at least one agent configuration file that

references a non-existent agent.

  1. Create test files:

```bash
mkdir -p .claude/agents

  1. Create a file .claude/agents/project-manager.md with content that references a missing agent:

# Project Manager Agent

## Standard Workflow

  1. [Knowledge Organizer] Collect resources
  2. [Backend Designer] Design logic
  3. [Documentation Writer] Update docs # ← References non-existent agent
  4. Start Claude Code in this project directory
  5. Send this message to Claude:

Check if we have a "Documentation Writer" agent configured in .claude/agents/

  1. Claude searches using Grep tool:

pattern: "Documentation Writer"
path: ".claude/agents"

  1. Claude responds with text like:

"I found that project-manager mentions Documentation Writer,
but the file doesn't exist. Let me create it for you:"

  1. Critical: The AI response **ends without any `

View original on GitHub ↗

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