[BUG] Error: Error during compaction: Error: API Error: 400
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?
I currently have about 176487 tokens used up
I want to compact manually, but when I attempt to do so, I am facing a 400 issue
❯ /compact "keep the api handy, also keep the information that the figr spaces already has the sharing funcitonality implemented in the
frontend side"
⎿ Error: Error during compaction: Error: API Error: 400
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.0: unexpected tool_use_id found in tool_result
blocks: toolu_016ahFC3cNKqGN57sx7pMW1D. Each tool_result block must have a corresponding tool_use block in the previous
message."},"request_id":"req_011CXzFwfgPWcRGSNTDCdxBK"}
❯ /compact
⎿ Error: Error during compaction: Error: API Error: 400
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.0: unexpected tool_use_id found in tool_result
blocks: toolu_016ahFC3cNKqGN57sx7pMW1D. Each tool_result block must have a corresponding tool_use block in the previous
message."},"request_id":"req_011CXzFxJQk6zrTRRbj43iWt"}
these are the prompts
What Should Happen?
Claude should be able to compact without issues in the API
Error Messages/Logs
❯ /compact "keep the api handy, also keep the information that the figr spaces already has the sharing funcitonality implemented in the
frontend side"
⎿ Error: Error during compaction: Error: API Error: 400
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.0: unexpected tool_use_id found in tool_result
blocks: toolu_016ahFC3cNKqGN57sx7pMW1D. Each tool_result block must have a corresponding tool_use block in the previous
message."},"request_id":"req_011CXzFwfgPWcRGSNTDCdxBK"}
❯ /compact
⎿ Error: Error during compaction: Error: API Error: 400
{"type":"error","error":{"type":"invalid_request_error","message":"messages.0.content.0: unexpected tool_use_id found in tool_result
blocks: toolu_016ahFC3cNKqGN57sx7pMW1D. Each tool_result block must have a corresponding tool_use block in the previous
message."},"request_id":"req_011CXzFxJQk6zrTRRbj43iWt"}
Steps to Reproduce
Complete any implementation, use up your context window and try attempting
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.37
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗