Bug: Task tool fails with "tools: Tool names must be unique" error

Resolved 💬 15 comments Opened Oct 31, 2025 by keith-oak Closed Oct 31, 2025

Environment

  • Claude Code Version: Latest (as of 2025-10-31)
  • OS: macOS 25.0.0 (Darwin)
  • Node: 22+
  • Project Type: Next.js 16 application with MCP servers

Description

The Task tool consistently fails to launch subprocess agents with a 400 API error: "tools: Tool names must be unique". This occurs for all subagent types, including general-purpose, and happens during agent initialization before any execution begins.

Steps to Reproduce

  1. Invoke Task tool with subagent_type="general-purpose"
  2. Provide any valid prompt (e.g., "Create test files for API routes")
  3. Observe API Error 400 response

Actual Behavior

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "tools: Tool names must be unique."
  }
}

Error appears immediately during agent initialization, before any task execution.

Expected Behavior

Task agent should initialize successfully and execute the provided prompt autonomously.

Test Cases Attempted

  • ❌ 4 parallel agents (single message, multiple Task invocations) - all failed
  • ❌ 1 sequential agent - failed
  • ❌ Agent with explicit model: "sonnet" parameter - failed
  • ❌ Different subagent types - all failed

Request IDs

  • req_011CUezFfa6UVuTcb13YUK1f
  • req_011CUezFeoxPTtpm1Ui1wbj7
  • req_011CUezFeapTWu9numGWTFmM
  • req_011CUezFemyUWAUnTVHhmoGG
  • req_011CUezHAwDVuXkegeUVzKmC

Investigation Results

  • ✅ Verified no duplicate tools in parent environment (49 unique tools)
  • ✅ Error is consistent across all invocation patterns
  • ✅ Not specific to parallel execution (single agent also fails)
  • ✅ Not model-specific (tried default and sonnet)
  • ✅ Occurs at API validation level (400 error from Anthropic)

Root Cause Hypothesis

The Task tool's implementation likely has a bug where it double-adds tools when creating subprocess agents:

  1. Inherits all parent tools from the main session
  2. Re-adds them from the agent type definition
  3. Results in duplicate tool names passed to the Anthropic API
  4. API validation rejects the request

Impact

  • Severity: Medium
  • Workaround Available: Yes (direct implementation without agents)
  • Blocked Feature: Parallel autonomous agent execution for large-scale tasks
  • User Impact: Reduced efficiency - tasks that could be parallelized across 4+ agents must be done sequentially

Active MCP Servers

  • GitHub MCP (26 tools: create_issue, create_pull_request, etc.)
  • Microsoft Learn MCP (3 tools: docs_search, code_sample_search, docs_fetch)
  • IDE MCP (2 tools: getDiagnostics, executeCode)

Use Case That Failed

Attempted to launch 4 parallel agents to create test coverage for 94 API routes:

  • Agent 1: Entitlements routes (4 routes)
  • Agent 2: Patient cycle management (21 routes)
  • Agent 3: Clinic admin routes (33 routes)
  • Agent 4: Mobile app & AI routes (33 routes)

All agents failed immediately with the duplicate tools error.

Suggested Fix

Add validation in the Task tool implementation to:

  1. Deduplicate tools before passing to Anthropic API
  2. Provide clear error messages if duplicates are detected
  3. Consider tool namespacing for subagents to prevent conflicts

View original on GitHub ↗

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