`advisor_tool_result` orphaned after auto-compaction causes API 400 on next request
Resolved 💬 3 comments Opened May 6, 2026 by pixxiestudiob Closed May 9, 2026
Bug
After auto-compaction occurs in a long session, any subsequent API call fails with:
API Error: 400 messages.N.content.0: unexpected `tool_use_id` found in
`advisor_tool_result` blocks: srvtoolu_01XRrgJHsNNK4ysNDdtpcU6k.
Each `advisor_tool_result` block must have a corresponding
`server_tool_use` block before it.
Steps to reproduce
- Start a long session that calls
advisor()one or more times. - Continue working until auto-compaction triggers (context approaching limit).
- Issue any follow-up command after compaction.
Expected behavior
Compaction preserves tool_use / tool_result pairs atomically, or strips both together. The session remains usable after compaction.
Actual behavior
Compaction drops the server_tool_use block for the advisor() call but retains the advisor_tool_result block. The orphaned result block causes the Anthropic API to reject every subsequent request with a 400, making the session unrecoverable.
Environment
- Claude Code CLI
- Platform: WSL2 (Linux 6.6.87.2-microsoft-standard-WSL2)
- Orphaned tool_use_id:
srvtoolu_01XRrgJHsNNK4ysNDdtpcU6k
Workaround
Start a fresh session. The broken session cannot be resumed.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗