[Bug] API Error 400: tool_use.name exceeds 200 chars during extended sessions with MCP + agents
Bug Description
During extended Claude Code sessions that use MCP servers, skills, and background agents (Task tool), the session becomes completely unrecoverable with repeated API 400 errors:
API Error: 400
{"type":"error","error":{"type":"invalid_request_error","message":"messages.1.content.3.tool_use.name: String should have at most 200 characters"},"request_id":"req_011CXqpzg8a2KML9MmyPtmvr"}
Once triggered, every subsequent message (even simple text) fails with the same error. The session is bricked — no recovery possible except /clear or restarting.
Environment
- Version: 2.1.32
- Platform: macOS (darwin, Apple Silicon)
- Terminal: Ghostty
MCP Servers Installed
nx-mcpplaywrightmcp-gsheetsclaude-in-chrome
Steps to Reproduce
- Start a Claude Code session with MCP servers active
- Use skills (via Skill tool) that expand to large prompts
- Spawn background agents with Task tool (3+ agents)
- Continue working for ~30+ messages with mixed tool usage
- Error appears on
messages.N.content.M.tool_use.name - ALL subsequent messages fail — session is bricked
Key Observations
- Error references
messages.1.content.X.tool_use.name— this is in the compacted conversation history, not the latest message - This suggests context compaction may be corrupting or extending tool names beyond 200 chars
- One commenter on #7370 confirmed it happened "right after compacting a conversation"
- The error blocks ALL messages including plain text, because the corrupted tool name is in conversation history
Expected Behavior
- Tool names should be validated/truncated before API calls
- Context compaction should preserve valid tool names
- If a tool name in history is too long, it should be sanitized rather than bricking the session
- At minimum, provide a recovery mechanism (auto-rewind past the corrupted message)
Previous Reports (auto-closed, unfixed)
- #7370 — [BUG] API Error 400: Tool name exceeds 200 character limit causing complete session failure
- #15695 — [Bug] API Error 400: MCP tool_use.name exceeds 200 character limit, blocking all messages
- #2673 — Validation Error: Tool Use Name Exceeds 200 Character Limit
All three were auto-closed without resolution. The bug persists in v2.1.32.
Suggested Fix
The compaction/summarization logic should validate that tool names in the compressed history don't exceed 200 characters. If they do, truncate or replace with a placeholder before sending to the API. Additionally, when a 400 error references a historical message, Claude Code should attempt to auto-heal by rewinding past the corrupted message rather than failing on every subsequent turn.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗