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
- Start a Claude Code session:
claude
- Run commands that trigger multiple tool calls (e.g., multiple file reads, edits, or bash commands in parallel)
- Interrupt the session with Ctrl+C while tools are actively being called (timing is critical - must be during tool execution)
- Attempt to resume the conversation with
claude --resume or by selecting from the conversation list
- Try to interact with Claude in the resumed conversation
- 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:
- It's specifically triggered by interrupting active tool calls
- It results in permanent conversation corruption (not intermittent errors)
- 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
- Implement proper cleanup of pending tool calls when session is interrupted
- Add a conversation repair mechanism to fix tool_use/tool_result mismatches
- Implement checkpointing before tool calls to allow rollback
- 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.
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
claudeclaude --resumeor by selecting from the conversation listExpected Behavior
Actual Behavior
The conversation becomes permanently corrupted with API errors such as:
Or:
Once these errors occur, the conversation is completely unusable and cannot send any new messages.
Environment
Additional Context
This issue is distinct from #2971 and #2967 because:
Workaround
Currently, the only workaround is to start a new conversation and lose all context from the corrupted one.
Possible Solutions
--force-cleanupflag to reset conversation stateError Log Examples
Impact
High - Results in complete loss of conversation context and work, requiring users to start over from scratch.