Session resume crashes with TypeError on H.addedBlocks.length after reboot (mcp_instructions_delta handler)
Summary
After an unclean shutdown (reboot / power loss) while Claude Code CLI sessions are active, those sessions can no longer be continued. Any input returns:
undefined is not an object (evaluating 'H.addedBlocks.length')
The session becomes permanently unusable — every subsequent message reproduces the error, which also gets persisted into the transcript as isApiErrorMessage entries.
Environment
- Claude Code CLI 2.1.143 (also observed on 2.1.141 / 2.1.142)
- macOS (Darwin 25.3.0), arm64
- Many MCP servers configured
Root cause
In the bundled CLI, the mcp_instructions_delta event handler reads addedBlocks with no null-guard:
case "mcp_instructions_delta": {
let q = [];
if (H.addedBlocks.length > 0)
q.push(`# MCP Server Instructions\n\n...${H.addedBlocks.join("\n\n")}`);
if (H.removedNames.length > 0) q.push(/* ... */);
When the delta object arrives without an addedBlocks field, .length throws TypeError. The sibling code path that constructs these deltas always returns {addedNames, addedBlocks, removedNames}, so addedBlocks is normally defined — but on the resume path it can be undefined.
Reproduction
- Start a CLI session with MCP servers configured.
- While the session is mid-turn (e.g. just after a tool call), kill the machine uncleanly (reboot / power loss).
- Relaunch Claude Code, resume that session.
- Send any message ->
undefined is not an object (evaluating 'H.addedBlocks.length').
Trigger chain: reboot -> all MCP servers disconnect -> on resume the CLI replays queued operations and MCP servers reconnect -> a mcp_instructions_delta event is produced/replayed without addedBlocks -> the unguarded .length access throws.
Impact
Not rare. On one machine, 746 session transcripts contain this error, clustered around 3 reboot events (444 / 291 / 9 sessions) — each reboot bricks every active MCP-enabled session at once. Transcripts stay valid JSON; only the in-app resume path crashes, so context is recoverable manually but sessions can never be resumed in-app.
Suggested fix
Guard the access in the mcp_instructions_delta handler:
if ((H.addedBlocks?.length ?? 0) > 0) /* ... */;
if ((H.removedNames?.length ?? 0) > 0) /* ... */;
or ensure the delta object always carries addedBlocks / removedNames (defaulting to []) on the resume / replay path.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗