[BUG] `/compact` fails with API 400 when session history contains unrecognized `server_tool_use` name

Resolved 💬 4 comments Opened Mar 26, 2026 by jensbrak Closed Apr 26, 2026

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?

Description

When the context limit is reached and /compact is attempted, compaction fails with an API 400 error. The only remaining option is /clear, which permanently destroys all session context, including history from previously paused and resumed sessions.

This may be related to how server_tool_use blocks in session history are handled during compaction.

Occurrences

  • First occurrence: session spanning multiple days and resumed sessions
  • Second occurrence: fresh session, only a few hours old, started after /clear was used as a workaround for the first occurrence

Both produced identical errors. Session age and history length do not appear to be a prerequisite for the bug.

What Should Happen?

/compact should summarize the session history and allow work to continue with a reduced context footprint.

At minimum, compaction should fail gracefully with a clear actionable fallback, even if session history contains unsupported or stale server_tool_use blocks.

Error Messages/Logs

Error: Error during compaction: Error: API Error: 400
    {"type":"error","error":{"type":"invalid_request_error",
    "message":"messages.15.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'"}}

Steps to Reproduce

I do not yet have a minimal deterministic repro, but the failure occurred in sessions with these characteristics:

  1. active agentic session with tool usage
  2. context limit reached
  3. /compact invoked
  4. compaction fails immediately with the error above

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.84 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

Possible Related Issue

This may be related to #39374.

That issue appears to mention /compact and server_tool_use blocks from the advisor tool. My case may overlap, but I cannot confirm that advisor is involved in my session history. I am filing this separately because the shared overlap I can actually support is:

  • /compact
  • session history
  • likely server_tool_use involvement

If maintainers determine this is the same underlying issue, I am happy for this to be closed as a duplicate.

Why maybe related to 'server_tool_use':

From the error and surrounding context, I suspect the session history contains server_tool_use blocks that Claude Code is not handling correctly during compaction.

But...:

  • I cannot confirm that the advisor tool is involved
  • I only know that #39374 mentions /compact and server_tool_use blocks from advisor, which sounds possibly related

<img width="1090" height="431" alt="Image" src="https://github.com/user-attachments/assets/f98782f4-3be8-46ee-ab80-7307a7b3f344" />

View original on GitHub ↗

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