[BUG] Interrupting session during tool calls permanently corrupts conversation with tool_use/tool_result API errors

Resolved 💬 8 comments Opened Jul 4, 2025 by bachittle Closed Sep 18, 2025

Description

When a Claude Code session is interrupted (escape or Ctrl+C) while tools are actively being called, it causes API synchronization errors that make the conversation permanently unusable. The conversation cannot be resumed or recovered, effectively losing all context and requiring a new conversation to be started.

Steps to Reproduce

  1. Start a Claude Code session: claude
  2. Run commands that trigger multiple tool calls (e.g., multiple file reads, edits, or bash commands in parallel)
  3. Interrupt the session with Ctrl+C while tools are actively being called (timing is critical - must be during tool execution)
  4. Attempt to resume the conversation with claude --resume or by selecting from the conversation list
  5. Try to interact with Claude in the resumed conversation
  6. Observe API errors that prevent any further interaction

Expected Behavior

  • Conversations should gracefully handle interruptions during tool calls
  • If a tool call is interrupted, the conversation should be able to recover or rollback to a working state
  • At minimum, there should be a way to repair or clean corrupted conversation state

Actual Behavior

The conversation becomes permanently corrupted with API errors such as:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.29: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_013ckU2JwQXpVxFdvi3xKT6T. Each `tool_use` block must have a corresponding `tool_result` block in the next message."}}

Or:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.6.content.0: unexpected `tool_use_id` found in `tool_result` blocks: toolu_012UKNLZsKcnA6fXh1k8qWop. Each `tool_result` block must have a corresponding `tool_use` block in the previous message."}}

Once these errors occur, the conversation is completely unusable and cannot send any new messages.

Environment

  • Claude Code Version: 1.0.43
  • Operating System: Debian GNU/Linux 12 (bookworm) x86_64
  • Shell: bash 5.2.15

Additional Context

This issue is distinct from #2971 and #2967 because:

  1. It's specifically triggered by interrupting active tool calls
  2. It results in permanent conversation corruption (not intermittent errors)
  3. There's no recovery mechanism - the conversation is lost

Workaround

Currently, the only workaround is to start a new conversation and lose all context from the corrupted one.

Possible Solutions

  1. Implement proper cleanup of pending tool calls when session is interrupted
  2. Add a conversation repair mechanism to fix tool_use/tool_result mismatches
  3. Implement checkpointing before tool calls to allow rollback
  4. Provide a --force-cleanup flag to reset conversation state

Error Log Examples

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.9: `tool_use` ids were found without `tool_result` blocks immediately after: toolu_0159A3WFTNviEbqP5udwQEjV, toolu_01V6BgQw5nXvM93fDkouSxqe. Each `tool_use` block must have a corresponding `tool_result` block in the next message."}}

Impact

High - Results in complete loss of conversation context and work, requiring users to start over from scratch.

View original on GitHub ↗

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