Session resume sends invalid previous_message_id (UUID) when prior session ended with connection error

Status Open
Reported on v2.1.131
Maintainer reply None cached
Activity 0 comments · opened Sep 22, 2026

Bug description

When a session ends with a connectivity error (e.g. API Error: Unable to connect. Is the computer able to access the url?), the last message stored in the session JSONL has an internal UUID as its id (e.g. 39fc571e-f3d6-4b5d-a487-cde05d34cff5) instead of a proper Anthropic API message ID (prefixed with msg_). On the next session start, Claude Code uses that UUID as previous_message_id, which the API rejects with a 400 error.

Steps to reproduce

  1. Start a Claude Code session and perform some work.
  2. Lose connectivity mid-session — the last assistant message becomes an "API Error: Unable to connect" entry in the session JSONL.
  3. End the session and start a new one in the same project directory.
  4. Observe the error immediately at session start:
API Error: 400 diagnostics.previous_message_id: must be the `id` from a prior /v1/messages response (starts with `msg_`)

Expected behavior

Claude Code should either:

  • Skip previous_message_id when the stored ID does not start with msg_, or
  • Not use messages flagged "isApiErrorMessage": true as the basis for conversation continuation.

Actual behavior

The error is shown at session start. It is non-blocking (the conversation continues), but it appears on every subsequent UserPromptSubmit until the user manually runs /clear.

Root cause (from session JSONL inspection)

The problematic entry in the session .jsonl looks like:

{
  "type": "assistant",
  "message": {
    "id": "39fc571e-f3d6-4b5d-a487-cde05d34cff5",
    ...
    "content": [{ "type": "text", "text": "API Error: 400 ..." }]
  },
  "isApiErrorMessage": true,
  "apiErrorStatus": 400
}

The id is a UUID generated internally for the error message, not a valid msg_... ID from /v1/messages. Claude Code appears to pick up the last message id regardless of whether it is a real API response.

Suggested fix

Before setting previous_message_id, filter out entries where isApiErrorMessage === true or where the id does not match /^msg_/.

Environment

  • Claude Code version: 2.1.131
  • Platform: Windows 10 (win32)
  • Shell: PowerShell + bash (WSL)

View original on GitHub ↗