claude-code - 💡(How to fix) Fix [BUG] Session becomes unrecoverable after interrupted tool call - /clear and /compact also fail [3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49026Fetched 2026-04-17 08:52:55
View on GitHub
Comments
3
Participants
3
Timeline
9
Reactions
0
Author
Timeline (top)
labeled ×5commented ×3unlabeled ×1

After a long session (~130+ conversation turns), an interrupted tool call caused the session to enter an unrecoverable state. Every subsequent message fails with the same API error, and neither /compact nor /clear can fix it.

Error Message

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.130.content.1.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Ca71wobUadrt2SuxWcK77"}

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Ca72J9qCn9oWjkaFXBPY4"}

Error during compaction: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Ca73S7CXvvJkTnCxnYNL5"}

(Same error persists after /clear as well — session is completely unrecoverable)

Root Cause

Root Cause (suspected)

An empty text content block (with cache_control set) was written into session history when a tool call was interrupted. The app does not sanitize empty blocks before sending, and /clear appears to make an API call before clearing — so it also fails with the same broken history.

Fix Action

Workaround

Only workaround is opening a new session entirely.

Code Example

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.130.content.1.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Ca71wobUadrt2SuxWcK77"}

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Ca72J9qCn9oWjkaFXBPY4"}

Error during compaction: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Ca73S7CXvvJkTnCxnYNL5"}

(Same error persists after /clear as well — session is completely unrecoverable)
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

markdown## Environment

  • Platform: Claude Code Desktop App (Windows 11)
  • Model: Claude Opus 4.6 1M

Description

After a long session (~130+ conversation turns), an interrupted tool call caused the session to enter an unrecoverable state. Every subsequent message fails with the same API error, and neither /compact nor /clear can fix it.

Error Messages

First error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error", "message":"messages.130.content.1.text: cache_control cannot be set for empty text blocks"}}

All subsequent errors (including after /compact and /clear): API Error: 400 {"type":"error","error":{"type":"invalid_request_error", "message":"messages: text content blocks must be non-empty"}}

Steps to Reproduce

  1. Run a long session with many tool calls (~100+ turns)
  2. Have a tool call interrupted mid-execution (e.g. network issue or timeout)
  3. Try to send any message → API error
  4. Try /compact → same API error ("Error during compaction")
  5. Try /clear → same API error
  6. Session is now completely dead with no recovery path except + New session

Expected Behavior

  • /clear should reset session state without making an API call first, so it doesn't carry the broken history into the reset request.
  • /compact should sanitize empty text blocks before sending to API.

Root Cause (suspected)

An empty text content block (with cache_control set) was written into session history when a tool call was interrupted. The app does not sanitize empty blocks before sending, and /clear appears to make an API call before clearing — so it also fails with the same broken history.

Workaround

Only workaround is opening a new session entirely.

What Should Happen?

  1. When a tool call is interrupted, the session history should roll back or sanitize the incomplete turn — empty text blocks should never be persisted.
  2. /clear should reset local session state without making an API call first, so a broken session can always be cleared regardless of history state.
  3. /compact should filter out empty text content blocks before sending to the API, instead of failing with the same error.

Error Messages/Logs

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.130.content.1.text: cache_control cannot be set for empty text blocks"},"request_id":"req_011Ca71wobUadrt2SuxWcK77"}

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Ca72J9qCn9oWjkaFXBPY4"}

Error during compaction: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages: text content blocks must be non-empty"},"request_id":"req_011Ca73S7CXvvJkTnCxnYNL5"}

(Same error persists after /clear as well — session is completely unrecoverable)

Steps to Reproduce

  1. Start a long Claude Code session in the Desktop App (100+ conversation turns with tool calls)
  2. Have a tool call interrupted mid-execution (e.g. stop generation, network issue, or timeout)
  3. Try to send any message → API Error 400: "cache_control cannot be set for empty text blocks"
  4. Try /compact → "Error during compaction" with same API Error 400
  5. Try /clear → same API Error 400, session still broken
  6. No recovery possible except opening a new session via "+ New session"

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

Version 1.2773.0 (884b37)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Terminal.app (macOS)

Additional Information

This issue occurred in the Claude Code Desktop App (not CLI). The session had approximately 130+ conversation turns before the error appeared. The broken state persisted across /compact, /clear, and multiple retry attempts. The only recovery was opening a new session. Screenshots attached showing the error sequence.

extent analysis

TL;DR

Sanitizing empty text blocks before sending to the API and modifying /clear to reset local session state without an initial API call may resolve the issue.

Guidance

  • The root cause appears to be the persistence of empty text blocks in the session history after an interrupted tool call, which causes subsequent API errors.
  • To mitigate this, the application should filter out empty text content blocks before sending them to the API, as suggested in the "What Should Happen?" section.
  • Modifying the /clear command to reset the local session state without making an API call first could provide a recovery path for broken sessions.
  • Implementing a rollback or sanitization mechanism for incomplete turns when a tool call is interrupted could prevent the issue from occurring in the first place.

Example

No specific code example can be provided without more context on the application's codebase, but the general approach would involve checking for and removing empty text blocks before API calls, and altering the /clear command's behavior.

Notes

The provided information suggests that the issue is related to how the application handles interrupted tool calls and empty text blocks, but without access to the code or more detailed logs, it's challenging to provide a definitive fix. The suggested modifications are based on the expected behavior described in the issue report.

Recommendation

Apply a workaround by modifying the application to sanitize empty text blocks and alter the /clear command's behavior, as these changes address the suspected root cause and provide a potential recovery path for broken sessions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING