[BUG] /compact fails with 400 when session history contains "advisor" server_tool_use blocks
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?
Running /compact fails with a 400 API error when the session history containsserver_tool_use blocks from the advisor tool.
What Should Happen?
Compaction should strip server_tool_use blocks from the history before sending it to
the compaction API — the same way #26188 fixed the PDF crash by stripping document blocks.
The fix belongs on the Claude Code side, not the user side, since these blocks are written
automatically and there's no way to avoid them.
More importantly: /compact is the only escape hatch when the context limit is hit.
If it throws a 400 and dies, the session is dead. There's no recovery path other than/clear and losing everything. That's the real problem here.
Error Messages/Logs
Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.19.content.2.server_tool_use.name: Input should be
'web_search', 'web_fetch', 'code_execution', 'bash_code_execution', 'text_editor_code_execution', 'tool_search_tool_regex',
'tool_search_tool_bm25'"},"request_id":""}
Steps to Reproduce
- Add a rule to the system prompt instructing Claude to call
advisorbefore substantive work - Start a session and let Claude invoke
advisorat least once (e.g. before a code change) - Run
/compactor wait for auto-compact to trigger - 400 error occurs
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.84
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗