Context compaction corrupts tool_use blocks — parameters merged into name field causing 400 API error

Resolved 💬 8 comments Opened Feb 14, 2026 by apurvdeodhar Closed Mar 24, 2026

Bug Description

Context compaction (autocompact) corrupts tool_use content blocks in the conversation history by merging tool parameters into the name field. This produces tool names exceeding the 200-character API limit, causing an unrecoverable 400 error loop.

Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.2.content.3.tool_use.name: String should have at most 200 characters"}}

Steps to Reproduce

  1. Start a Claude Code session with several plugins/MCP servers enabled
  2. Use the Task tool (subagent) and Read tool in a conversation
  3. Continue the conversation long enough for autocompact to trigger
  4. After compaction, the session enters an unrecoverable 400 error loop
  5. please continue or any new message triggers the same error

Root Cause (from debug logs)

After autocompact runs, tool_use blocks are serialized incorrectly. The tool parameters are concatenated into the name field instead of staying in the input field:

Expected:

{
  "type": "tool_use",
  "name": "Task",
  "input": {
    "prompt": "Check the status of ...",
    "subagent_type": "Bash",
    "description": "Check status"
  }
}

Actual (corrupted after compaction):

name: "Task\" prompt=\"Check the status of ... subagent_type=\"Bash\" description=\"Check status"

Debug log evidence:

[ERROR] Error: Error: Tool Task" prompt="<long prompt text>... subagent_type="Bash" description="<description>" not found
[ERROR] Error: Error: Tool Read" file_path="<path>" not found
[ERROR] API error (attempt 1/11): 400 ... messages.2.content.3.tool_use.name: String should have at most 200 characters

The not found suffix confirms Claude Code itself can't resolve these corrupted tool names before sending to the API.

Impact

  • Unrecoverable: Once corrupted messages enter the history, every subsequent API call fails
  • Data loss: The entire conversation context is lost — /clear is the only workaround
  • Silent corruption: No warning before the error loop begins; user discovers only after compaction runs

Environment

  • Claude Code version: 2.1.42
  • OS: macOS (Darwin 25.3.0)
  • Model: claude-opus-4-6
  • Plugins: 14 enabled (github, superpowers, playwright, sentry, context7, firecrawl, etc.)
  • MCP servers: 5 (github, playwright, sentry, aws-api, sequential-thinking)
  • autocompact threshold: ~167k tokens (from debug log: autocompact: tokens=59264 threshold=167000 effectiveWindow=180000)

Workaround

Run /clear to reset the conversation. There is no way to recover the corrupted session.

View original on GitHub ↗

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